Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Defining conditional branches

&pagelevel(4)&pagelevel

IF blocks can be used to generate branches during procedure execution. The sequence of commands in an IF block is executed or not, depending on the result of a condition.
An IF block begins with the IF command, and ends with the END-IF command. It may be given a tag.

If there is only one condition to be tested, the IF block consists of an IF command defining the condition, the associated sequence of commands and an END-IF command. The condition must be specified as a Boolean value.

/IF condition
   command sequence1

/END-IF

As in higher programming languages, a distinction can be made between THEN and ELSE branches in IF blocks. command sequence1 in the above example is the THEN branch, and the jump to the END-IF is the ELSE branch.Here, if the condition in the IF command is satisfied, then command sequence1 will be executed. If the condition is not satisfied, the IF block will be terminated. The command which follows the END-IF will then be executed.

If another command sequence is to be executed as an alternative to command sequence1, the IF block must contain an explicit ELSE branch. This ELSE branch contains the alternative command sequence. It begins with the ELSE command and ends with the END-IF command.

/IF condition
   command sequence1

/ELSE
   command sequence2

/END-IF

If the condition in the IF command is satisfied, command sequence1 is executed and the block is terminated. If the condition is not satisfied, command sequence2 is executed.
It is also possible to test several conditions consecutively within an IF block.

/IF condition
   command sequence1

/ELSE-IF condition
   command sequence2

/ELSE-IF condition
   command sequence3

...
/ELSE
   command sequencei

/END-IF

If the condition in the IF command is met, command sequence1 is executed. If it is not met, the condition in the first ELSE-IF command is tested. If this condition is met, command sequence2 is executed; if not, the condition in the next ELSE-IF command is tested, and so on. If no conditions are met, then command sequencei which follows the ELSE command is executed.


Each of the command sequences between the IF, ELSE-IF, ELSE and END-IF commands forms a separate block.

Example

Depending on the value of variable A, a file is to be created whose file name is to contain the value of the variable as a subname:

  • If the value of variable A is less than 11, the file FILE.SMALL.&A is to be created.

  • If the value of variable A is from 11 to 100, the file FILE.MEDIUM.&A is to be created.

  • If A is greater than 100, the file FILE.LARGE.&A is to be created.

/DECLARE-PARAMETER A(INITIAL-VALUE=*PROMPT,TYPE=*INTEGER)
/IF (A < 11)
/   CREATE-FILE FILE.SMALL.&A,SUPPORT=*PUB-DISK(SPACE=*RELA(PRIM-ALLOC=30))
/ ELSE-IF (A < 101)
/   CREATE-FILE FILE.MEDIUM.&A,SUPPORT=*PUB-DISK(SPACE=*RELA(PRIM-ALLOC=60))
/ ELSE
/   CREATE-FILE FILE.LARGE.&A,SUPPORT=*PUB-DISK(SPACE=*RELA(PRIM-ALLOC=90))
/END-IF

The files are created by means of the CREATE-FILE command operand SUPPORT = *PUB-DISK(SPACE = *RELA(PRIM-ALLOC = ...)):

  • SUPPORT = *PUBLIC-DISK means that the file is created as a disk file on a public disk.

  • SPACE = *RELATIVE means a relative memory allocation.

  • PRIMARY-ALLOCATION means that the file is allocated n PAM pages of memory.

For a detailed description of how files are generated, see the manual entitled “Introductory Guide to the DMS” [1]. This manual also explains the terms “disk file”, “public disk”, “(relative) memory allocation” and “PAM page”.