Controlling processing within a CL program or CL procedure

You can use commands to change the flow of logic within your CL procedure.

Commands in a CL procedure are processed in consecutive sequence. Each command is processed, one after another, in the sequence in which it is encountered. You can alter this consecutive processing using commands that change the flow of logic in the procedure. These commands can be conditional or unconditional.

Unconditional branching means that you can instruct processing to branch to commands or sets of commands located anywhere in the procedure without regard to what conditions exist at the time the branch instruction is processed. Unconditional processing commands include:

  • GOTO
  • ITERATE
  • LEAVE
  • CALLSUBR

Conditional branching means that under certain specified conditions, processing can branch to sections or commands that are not consecutive within the procedure. The branching can be to any statement in the procedure. This is called conditional processing because the branching only occurs when the specified condition is true. Conditional processing is typically associated with the IF command. With the ELSE command, you can specify alternative processing if the condition is not true.The simple DO command allows you to create groups of commands that are always processed together, as a group, under specified conditions. Conditional processing commands include:

  • IF and THEN
  • SELECT, WHEN, and OTHERWISE
  • DOFOR
  • DOWHILE
  • DOUNTIL