Get Procedure Pointer

GetProcPtr

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:

Parameters

szProcedure
[input VChar(256) const]  Procedure name. Specify the name of the procedure exactly as it has been exported from the service program.
Procedure names are case-sensitive so 'MYPROC' is not the same as 'MyProc'.
 
szSrvPgm
[input Char(21) const]  The qualified service program name. The name may be specified using qualified name syntax or the legacy 10/10 format.
 

Legacy 10/10 qualified name syntax:

 *...v....1....v....2.
'RPGLIB    XTOOLS     '
 

Qualified name syntax:

 *...v....1....v....2.
'RPGLIB/XTOOLS        '
 
szObjType [optional DFT(X'0203') ]
[input Char(2) const]  A optional parameter that must be either X'0203' or X'0201'. If unspecified, X'0203' is used.
 

Return Value

The return value is a PROCPTR to the procedure or *NULL if the procedure could not be located.

Example

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.