BS2000 makes 32 job switches (numbered from 0 to 31) available to each job (task) and 32 user switches (numbered from 0 to 31) available to each user identification (see “Commands” manual [3]). Each switch is able to assume an ON or an OFF status. They may be used to control activities within a task or to coordinate the activities of several tasks. Thus, for example:
job switches can be used when two or more (COBOL) programs within one job need to communicate, e.g. when the execution of one program is dependent on the processing steps of another program that was invoked earlier;
user switches can be used when two or more jobs need to communicate. When the communicating jobs belong to different user IDs, user switches associated with one ID can be interrogated by the jobs of another ID, but cannot be modified by these jobs.
Job and user switches can be accessed and modified at operating system level (by means of commands) or at program level (via COBOL statements). COBOL2000 supports access to job and user switches with the following language elements (see “COBOL2000 Reference Manual” [1]):
Program-internal mnemonic names for job and user switches and their status, declared in the SPECIAL-NAMES paragraph of the Environment Division:
These mnemonic names allow Procedure Division statements to reference the assigned switches and their status (see below). The mnemonic names can be declared as described below:
For the job switches via the implementor-names TSW-0, TSW-1,..., TSW-31, where the additional phrase ON IS... and OFF IS... allow the user to define condition names for the respective switch status.
It is thus possible, for example, to declare the mnemonic name and status for task switch 17 with the phrasesTSW-17 IS mnemonic-name-17 ON IS switch-status-on-17 OFF IS switch-status-off-17
For the user switches via the implementor-names USW-0, USW-1,..., USW-31, where the additional phrases ON IS... and OFF IS... allow the user to define condition names for the respective switch status.
It is thus possible, for example, to declare the mnemonic name and status for user switch 18 with the phrasesUSW-18 IS mnemonic-name-18 ON IS switch-status-on-18 OFF IS switch status-off-18
Interrogation and modification of switches in the Procedure Division:
Conditions (e.g. in the IF, PERFORM or EVALUATE statement) can contain the names (declared in the SPECIAL-NAMES paragraph) of switch status conditions and in this way evaluate them for the control of program execution.
SET (format 3; see “COBOL2000 Reference Manual” [1]) can access switches (via the mnemonic names declared in the SPECIAL-NAMES paragraph) and change their status.
Example 8-2
Use of job switches
In the following extract from an interactive task, a procedure provides for different processing paths, depending on the status of job switches 12 and 13. The switches are evaluated and changed both at operating system level and at program level:
First, job switch 12 can be set at operating system level in order to control processing within the succeeding procedure, where its status will be evaluated at program level. Job switch 13 is then set, depending on the status of program execution. This switch is subsequently evaluated at operating system level.
|
(1) | Job switch 12 is set to ON, job switch 13 to OFF at the operating system level. |
(2) | Extract from a procedure. |
(3) | The COBOL program PROG-1 is called. |
(4) | The internal names SWITCH-12 and SWITCH-13 are declared in the program for job switches 12 (TSW-12) and 13 (TSW-13) respectively, and the condition names ON-12 or ON-13 for their respective ON status. |
(5) | If job switch 12 is ON (see (1)), the statement PERFORM A-PAR is executed before PERFORM B-PAR. |
(6) | If the indicator FIELD contains the value 99 at the end of program execution, PROG-1 sets the job switch to ON. |
(7) | The procedure evaluates the status of job switch 13: if it was not set to ON by PROG-1, the procedure branches to the end. Otherwise, PROG-2 is executed in addition to PROG-1. |
(8) | At the operating system level, job switches 12 and 13 are reset. |
Example 8-3
Use of user switches
In the following extract, interactive job A generates two batch jobs, B and C. In job B, an ISAM file is updated. Job C can only execute after this takes place. User switch 21 is used in three different jobs. It is set at program level, and evaluated and reset at operating system level.
(1) | User switch 21 is initialized to OFF. |
(2) | The ENTER procedure B.BATCH is called; it generates batch job B. |
(3) | Batch job B calls the COBOL program COB-ISAM. |
(4) | COB-ISAM updates the file ISAM-FILE. |
(5) | When updating is completed, COB-ISAM sets user switch 21 to ON. |
(6) | The ENTER procedure C.BATCH is called; it generates batch job C. |
(7) | Job C waits until the user switch is set to ON in job B. |
(8) | As soon as user switch 21 is set to ON, job C calls the COBOL program SUCC-PRO; it can then access the ISAM-FILE updated in job B. |
(9) | User switch 21 is set to OFF, in order to mark the (normal) end of job C. |