IF-THEN-ELSE Command Sequence

The syntax of the IF-THEN-ELSE command sequence, which controls command execution, is:

Command Parameters
IF {LASTCC|MAXCC} operator  number
   THEN[ command|
     DO
     command set
     END]
  [ELSE[ command|
     DO
     command set
     END]]  
   
where:
IF
States that one or more functional commands should run based on a test of a condition code. A SET command sets the condition code, or the condition code reflects the completion status of previous functional commands.

Nested IF commands: When an IF command appears within a THEN or ELSE clause, it is called a nested IF command. To see an example of a nested IF command, see Using Nested IF Commands, Example 1,on page 22.

  • The maximum level of nesting allowed is 10, starting with the first IF.
  • Within a nest of IF commands:
  • The innermost ELSE clause is associated with the innermost THEN clause,
  • The next innermost ELSE clause with the next innermost THEN clause, and so on. (Each ELSE is matched with the nearest preceding unmatched THEN.)
  • If there is an IF command that does not require an ELSE clause, follow the THEN clause with a null ELSE clause (ELSE) unless the nesting structure does not require one.
LASTCC
LASTCC specifies that the condition code resulting from the preceding function command be compared, as indicated by the operator, to the number that follows the operator to determine if the THEN action is to be done.
MAXCC
MAXCC specifies that the maximum condition code value established by any previous function command or by a SET command be compared, as indicated by the operator, to the number following the operator to determine if the THEN action is to be done.
operator
operator requires a comparison to be made between the variable and number. There are six possible comparisons:
  • Equal to, written as = or EQ
  • Not equal to, written as ¬= or NE
  • Greater than, written as > or GT
  • Less than, written as < or LT
  • Greater than or equal to, written as >= or GE
  • Less than or equal to, written as <= or LE
number
number is the decimal integer that the program compares to MAXCC or LASTCC. Access method services initializes both LASTCC and MAXCC to zero upon entry. See Condition Codes for the meaning of condition codes.
THEN
THEN states that a single command or a group of commands (introduced by DO) is to be run if the comparison is true. THEN can be followed by another IF command.
ELSE
ELSE specifies that a single command or a group of commands (introduced by DO) is to be run if the previous comparison is false. ELSE can be followed by another IF command.