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 Submit Job (SBMJOB), Change Job (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 (IF) and Change Variable (CHGVAR) commands. Switches can be changed in a CL procedure by the Change Job (CHGJOB) command. For CL procedures, these changes take effect immediately.