Transferring control

170 Views


Transferring control to improve performance

The Transfer Control (TFRCTL) command calls the program specified on the command, passes control to it, and removes the transferring program from the call stack.

Reducing the number of programs on the call stack can have a performance benefit.

When a Call (CALL) command is used, the program called returns control to the program containing the Call (CALL) command.

When a Transfer Control (TFRCTL) command is used, control returns to the first program in the call stack.

The first program then initiates the next sequential instruction following the Call (CALL) command.

The Transfer Control (TFRCTL) command is not valid in Integrated Language Environment (ILE) CL procedures.

Example: Using the Transfer Control command

This is an example of transferring control to improve performance.

In the following illustration, if Program A is specified with USRPRF(*OWNER), the owner's authorities are in effect for all of the programs shown. If Program B is specified with USRPRF(*OWNER), the owner's authorities are in effect only while Programs B and C are active. When Program B transfers control to Program D, Program B is no longer in the call stack and the owner of Program B is no longer considered for authorization during the running of Program D. When the programs complete processing (by returning or transferring control), the owner's authorities are no longer in effect. Any overrides issued by Program B remain in effect while Program D is running and are lost when Program D does a return.

The Transfer Control (TFRCTL) command has the following format:
TFRCTL PGM(library-name/program-name) PARM(CL-variable)

 

It is important to note that only variables may be used as parameter arguments on this command, and that those variables must have been received as a parameter in the argument list from the program that called the transferring program. That is, the Transfer Control (TFRCTL) command cannot pass a variable that was not passed to the program running the Transfer Control (TFRCTL) command.

In the following example, the first Transfer Control (TFRCTL) is valid. The second Transfer Control (TFRCTL) command is not valid because &B was not passed to this program. The third TFRCTL command is not valid because a constant cannot be specified as an argument.

PGM PARM(&A)
DCL &A *DEC 3
DCL &B *CHAR 10
IF (&A *GT 100) THEN (TFRCTL PGM(PGMA) PARM(&A)) /* valid */
IF (&A *GT 50) THEN (TFRCTL PGM(PGMB) PARM(&B)) /* not valid */
ELSE (TFRCTL PGM(PGMC) PARM(’1’)) /* not valid */
ENDPGM

Passing parameters using the Transfer Control command

The Transfer Control (TFRCTL) command passes parameters to the program being called.

The TFRCTL command can be used to pass parameters to the program being called in the same way the CALL command passes parameters, but with these restrictions:

  • The parameters passed must be CL variables.
  • The CL variables passed by the transferring program must have been received as parameters by that program.
  • This command is valid only within original program model (OPM) CL programs.

In the following example, PROGA calls PROGB and passes two variables, &A and &B, to it. PROGB uses these two variables and another internally declared variable, &C. When control is transferred to PROGC, only &A and &B can be passed to PROGC. When PROGC finishes processing, control is returned to PROGA, where these variables originated.

Post Comments