The DO command allows you to process a group of commands together.
The group is defined as all those commands between the DO command and the corresponding End Do Group (ENDDO) command.
Processing of the group is usually conditioned on the evaluation of an associated command. Do groups are most frequently associated with the IF, ELSE, or MONMSG commands. For instance:
If the logical expression (&A=&B) is true, then the Do group is processed. If the expression is not true, then processing starts after the ENDDO command; the Do group is skipped.
In the following procedure, if &A is not equal to &B, the system calls PROCB. PROCA is not called, nor are any other commands in the Do group processed.
Do groups can be nested within other Do groups, up to a maximum of 25 levels of nesting.
There are three levels of nesting in the following example. Note how each Do group is completed by an End Do Group (ENDDO) command.
In this example, if &A in the first nest does not equal 5, PGMC is called. If &A does equal 5, the statements in the second Do group are processed. If &AREA in the second Do group does not equal YES, procedure ACCTSPAY is called, because processing moves to the next command after the Do group.
The CL compiler does not indicate the beginning or ending of Do groups. If the CL compiler notes any unbalanced conditions, it is not easy to detect the actual errors.