You can examine the Invocation stack of your job by using one of the
Retrieve job API's or the DSPJOB command.
The following program returns in the &CALLER parameter, the program that
invoked the program named in the &PGM parameter.
Example of use in your own program:
/* &MYNAME will contain the name of the program currently running */
CALL CALLER (&MYNAME '*')
/* &MYCALLER contains the name of the caller of the current program */
CALL CALLER (&MYCALLER &MYNAME)
PGM PARM(&CALLER &PGM)
DCL VAR(&CALLER) TYPE(*CHAR) LEN(10)
DCL VAR(&PGM) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGKEY) TYPE(*CHAR) LEN(4)
DCL VAR(&SENDER) TYPE(*CHAR) LEN(80)
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))
CHGVAR VAR(&CALLER) VALUE(' ')
SNDPGMMSG MSG('Who called me?') TOPGMQ(*PRV (&PGM)) +
KEYVAR(&MSGKEY)
RCVMSG PGMQ(*PRV (&PGM)) MSGTYPE(*INFO) +
MSGKEY(&MSGKEY) RMV(*YES) SENDER(&SENDER)
CHGVAR VAR(&CALLER) VALUE(%SST(&SENDER 56 10))
GOTO CMDLBL(ENDPGM)
ERROR: CHGVAR VAR(&CALLER) VALUE(' ')
ENDPGM: ENDPGM