The switch built-in function (%SWITCH) compares one or more of eight switches with the eight switch settings already established for the job and returns a logical value of '0' or '1'. The initial values of the switches for the job are determined first by the Create Job Description (CRTJOBD) command; the default value is 00000000. You can change this if necessary using the SWS parameter on the SBMJOB, CHGJOB, or JOB command; the default for these is the job description setting. Other high-level languages may also set job switches.
If, in the comparison of your %SWITCH values against the job values, every switch is the same, a logical value of '1' (true) is returned. If any switch tested does not have the value indicated, the result is a '0' (false).
The syntax of the %SWITCH built-in function is:
%SWITCH(8-character-mask)
The 8-character mask is used to indicate which job switches are to be tested, and what value each switch is to be tested for. Each position in the mask corresponds with one of the eight job switches in a job. Position 1 corresponds with job switch 1, position 2 with switch 2, and so on. Each position in the mask can be specified as one of three values: 0, 1, or X.
If %SWITCH(0X111XX0) is specified, job switches 1 and 8 are tested for 0s; switches 3, 4, and 5 are tested for 1s; and switches 2, 6, and 7 are not tested. If each job switch contains the value (1 or 0 only) shown in the mask, the result of %SWITCH is true '1'.
Switches can be tested in a CL procedure to control the flow of the procedure. This function is used in CL procedures with the IF and CHGVAR commands. Switches can be changed in a CL procedure by the Change Job (CHGJOB) command. For CL procedures, these changes take effect immediately.
On the IF command, %SWITCH can be specified on the COND parameter as the logical expression to be tested. In the following example, 0X111XX0 is compared to the predetermined job switch setting:
IF COND(%SWITCH(0X111XX0)) THEN(GOTO C)
If job switches 1, 3, 4, 5, and 8 contain 0, 1, 1, 1, and 0, respectively, the result is true and the procedure branches to the command having the label C. If one or more of the switches tested do not have the values indicated in the mask, the result is false, and the branch does not occur.
In the following example, switches control conditional processing in two procedures.
SBMJOB JOB(APP502) JOBD(PAYROLL) CMD(CALL APP502) SWS(11000000) PGM /* CONTROL */ IF (%SWITCH(11XXXXXX)) CALLPRC PROCA IF (%SWITCH(10XXXXXX)) CALLPRC PROCB IF (%SWITCH(01XXXXXX)) CALLPRC PROCC IF (%SWITCH(00XXXXXX)) CALLPRC PROCD ENDPGM PGM /* PROCA */ CALLPRC TRANS IF (%SWITCH(1XXXXXXX)) CALLPRC CUS520 ELSE CALLPRC CUS521 ENDPGM
On the CHGVAR command, you can specify %SWITCH to change the value of a logical variable. The value of the logical variable is determined by the results of comparing your %SWITCH settings with the job switch settings. If the result of the comparison is true, the logical variable is set to '1'. If the result is false, the variable is set to '0'. For instance, if the job switch is set to 10000001 and this procedure is processed:
PGM DCL &A *LGL CHGVAR VAR(&A) VALUE(%SWITCH(10000001)) . . . ENDPGM
then the variable &A has a value of '1'.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.