Get Caller

GetCallerInfo

The GetCallerInfo  procedure retrieves the name of the calling program, or the calling procedure, or both.

calling-proc/pgm   GetCallerInfo(
  szOption         10A   Const OPTIONS(*NOPASS:*OMIT) 
)
 

Parameters

szOption [ optional ]
[input Char(10) const]  Specify the type of information you want to retrieve. Valid choices for this parameter include the following:
*PRV or *PREV Returns the calling program's program, module or procedure name. (This is the default.)
*PGM The program name is sent back at the return value.
*PROC The procedure name is sent back as the return value.
*MODULE The module name is sent back as the return value
*SAME or * Returns the current program, module, or procedure name instead of the callers.
szRtnPgm [ optional ]
[input Char(10) ]  Specify a field or data structure variable that will receive the program name of the caller.
szRtnProc [ optional ]
[input Char(256) ]  Specify a field or data structure variable that will receive the name of the calling procedure.
szRtnModule [ optional ]
[input Char(10) ]  Specify a field or data structure variable that will receive the name of the calling module.

 

Return Value

If the function succeeds, the return value is the procedure, program or module name, as specified on the szOption parameter. The return value may be ignored when using the szRtnPgm, szRtnProc, or szRtnModule parameters.

Example 1 - Find My Caller

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++++++++++
     D callingProc     S            256A   Varying
     D pgmName         S             10A   
 
.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++

     C                   eval      pgmName = GetCallerInfo()

     C                   eval      CallingProc = GetCallerInfo('*PROC')

In this example, the caller's program name is returned, and then the caller's procedure name is returned. Note the length of a procedure name may be up to 256 characters, hence the lengthy CALLINGPROC variable declaration.

 

Example 2 - Find My Program Name

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++++++++++
     D callingProc     S            256A   Varying
     D pgmName         S             10A   
 
.....CSRn01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++

     C                   eval      pgmName = GetCallerInfo('*SAME')

     C                   callp     GetCallerInfo('*':pgmName:CallingProc)

In this example, the *SAME and '*' option tell the GetCallerInfo procedure to return information about "this" procedure, rather than its caller. The first statement returns the name of the program, whereas the second statement returns the name of the program and the procedure name.