If a CL procedure is to send a message to an OPM program or another ILE procedure, you must identify the call stack entry to which the message is sent.
The message is sent to the call message queue of the identified call stack entry.
The TOPGMQ parameter of the Send Program Message (SNDPGMMSG) command is used to identify the call stack entry to which a message is sent. Identification of a call stack entry consists of the following two parts:
This specification identifies a program or procedure within the call stack (this is element 2 of TOPGMQ).
The offset specification (element 1 of TOPGMQ) identifies if you send the message to the base (*SAME) or if you send the message to the caller of the base (*PRV).
The specification TOPGMQ(*PRVĀ *) identifies the base entry as being the one in which the procedure using the Send Program Message (SNDPGMMSG) command is running. The offset is specified as being one entry previous to that base. This specification identifies the caller of the procedure which is using the command.
To understand how to identify the base entry, element 2 of TOPGMQ, you also need to understand the call stack when an ILE program is running. Two programs are used to illustrate this. Program CLPGM1 is an OPM CL program and Program CLPGM2 is an ILE program. Since program CLPGM2 is ILE, it can consist of several procedures, such as: CLPROC1, CLPROC2, CLPROC3, and CLPROC4. At runtime the following calls take place: