Use the program boundary as a base

You can specify the program boundary as the base call stack entry by using the *PGMBDY special value.

The special value *PGMBDY is used by itself or with a program name to identify the PEP of a CL program. The entry for the PEP of the identified CL program then is the base entry. This option is useful when you want to send a message from within a CL procedure outside the boundary of the program which contains the procedure.

Refer to the first figure for an example of sending a message using the special value *PGMBDY. In this example, CLPROC4 is sending a message directly to to CLPGM1 which is the caller of the containing program CLPGM2. CLPROC4 can do this without knowing which program called CLPGM2 or knowing the location of the PEP compared to the procedure sending the message. In this example, *PGMBDY is used without an accompanying program name specified. This means that the program whose boundary is to be identified is the program which contains the procedure that is sending the message.

See the second figure for an example of sending a message using the special value *PGMBDY and a program name. The following programs and procedures are used in the second figure:

A message is sent from CLPROCA to the caller of CLPGM2 by using the special value *PGMBDY with program name CLPGM2.

In this example, if the TOPGMQ parameter is specified as TOPGMQ(*PRV _CL_PEP), the message is sent to the caller of CLPGM3 rather than the caller of CLPGM2. This occurs because the most recently called procedure by that name is the PEP for CLPGM3.

Figure 1. Example of using *PGMBDY as a simple name

Figure 2. Example of using *PGMBDY in a complex name

The special value *PGMBDY can also be used with an OPM program. If you specify an OPM program name with *PGMBDY, you have the same results as when only the OPM program name is used. For example, TOPGMQ(*SAME *PGMBDY *NONE opmname) sends the message to the same place as TOPGMQ(*SAME opmname).The exception to this is when a message is sent to an OPM program that called itself recursively. TOPGMQ(*SAME pgmname) sends the message to the latest recursion level. However, TOPGMQ(*SAME *PGMBDY *NONE pgmname) sends the message to the first recursion level. The figure below shows how PGM1 is called and proceeds to call itself recursively two more times. At the third recursion level PGM1 calls PGM2. PGM2 then sends a message back to PGM1. If the program is sent using only the name PGM1, the message goes to the third recursion level of PGM1. If the program is sent using the name PGM1 in conjunction with the special value *PGMBDY, the message goes to the first recursion level of PGM1.

Figure 3. Example of using *PGMBDY with an OPM name with recursion