The GetProcPtr procedure retrieves a pointer to a procedure in a service program. These procedure pointer can be used to subsequently call the procedure.
The GetProcPtr procedure can be used to retrieve a procedure pointer and used to allow so call "late binding" to procedures and service programs.
pointer-to-procedure (PROCPTR) GetProcPtr( szProcedure 256A Const Varying szSrvPgm 21A Const szObjType 2A Const OPTIONS(*NOPASS:*OMIT) ) |
|
See also: |
Legacy 10/10 qualified name syntax:
*...v....1....v....2.
'RPGLIB XTOOLS '
Qualified name syntax:
*...v....1....v....2.
'RPGLIB/XTOOLS '
- X'0201' - For a *PGM object
- X'0203' - For a *SRVPGM object
The return value is a PROCPTR to the procedure or *NULL if the procedure could not be located.
The following example illustrates how to call a procedure in a service program that was not bound to the calling module during the compile phase.
.....DName+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++++++++++
D thePtr S * ProcPtr
D MyToUpper PR 65535A ExtProc(thePtr) Varying
D InString 65535A Const Varying
D szName S 20A Inz('Robert Cozzi')
.....CSRn01..............OpCode(ex)Extended-factor2+++++++++++++++++++++++++++
C eval thePtr = GetProcPtr('ToUpper' : 'XTOOLS/RPGLIB')
C eval szName to MyToUpper(szName)
When this routine is performed, the TOUPPER procedure in the RPG xTools is called dynamically.
The field named THEPTR (first line above) is a procedure pointer. The prototype for the MyToUpper procedure has the EXTPROC(thePtr) keyword specified. Since THEPTR is a procedure pointer, the procedure is assumed to be late-bound. It is up to the program to get the procedure's pointer at runtime.
Once the procedure pointer is returned by the GetProcPtr procedure, it is pointing to the ToUpper procedure in the RPGLIB service program. From that point on, when MyToUpper is called, it is really calling the TOUPPER procedure in the RPGLIB service program.
Note that procedure names are case-sensitive.