Natural for OpenVMS Version 6.3.12 for OpenVMS
 —  Statements  —

IF SELECTION

Structured Mode Syntax

IF SELECTION [NOT UNIQUE [IN [FIELDS]]] operand1
  [THEN] statement
  [ELSE statement]
END-IF

Reporting Mode Syntax

IF SELECTION [NOT UNIQUE [IN [FIELDS]]] operand1
  [THEN]

statement

 
  DO statement DOEND

ELSE

statement
DO statement DOEND

This document covers the following topics:

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.

Related Statements: DECIDE FOR | DECIDE ON | IF

Belongs to Function Group: Processing of Logical Conditions


Function

The IF SELECTION statement is used to verify that in a sequence of alphanumeric fields one and only one contains a value.

Top of page

Syntax Description

Operand Definition Table:

Operand Possible Structure Possible Formats Referencing Permitted Dynamic Definition
operand1   S A     A U               L C     yes no

Syntax Element Description:

Syntax Element Description
operand1
Selection Field(s):

As operand1 you specify the fields which are to be checked.

If you specify an attribute control variable (Format C), it is considered to contain a value if its status has been changed to MODIFIED.

Note:
To check if a specific attribute control variable has been assigned the status MODIFIED, use the MODIFIED option of, for example, an IF statement. This enables you to check that exactly one field was modified.

THEN statement ...
THEN Clause:

The statement(s) specified in the THEN clause will be executed if one of the following conditions is true:

  • None of the fields specified in operand1 contains a value.

  • More than one of the fields specified in operand1 contains a value.

This statement is generally used to verify that a terminal user has entered only one function in response to a map displayed via an INPUT statement.

Note:
If no action is to be performed if one of the conditions is met, you specify the statement IGNORE in the THEN clause.

ELSE statement ...
ELSE Clause:

In the ELSE clause, you specify the statement(s) to be executed if exactly one field contains a value.

END-IF
End of IF SELECTION Statement:

In structured mode, the Natural reserved word END-IF must be used to end the IF SELECTION statement.

In reporting mode, use the DO ... DOEND statements to supply one or several suitable statements, depending on the situation, and to end the clauses and the IF SELECTION statement. If you specify only a single statement, you can omit the DO ... DOEND statements. With respect to good coding practice, this is not recommended.

statement ...
DO statement ... DOEND

Top of page

Example

** Example 'IFSEL': IF SELECTION                                        
************************************************************************
DEFINE DATA LOCAL                                                       
1 #A (A1)                                                               
1 #B (A1)                                                               
END-DEFINE                                                              
*                                          
INPUT 'Select one function:' //            
   9X 'Function A:' #A                     
   9X 'Function B:' #B                     
*                                          
IF SELECTION NOT UNIQUE #A #B              
  REINPUT 'Please enter one function only.'
END-IF                                    
*                                          
IF #A NE ' '                               
  WRITE 'Function A selected.'             
END-IF                                     
IF #B NE ' '                               
  WRITE 'Function B selected.'             
END-IF                                     
*                                          
END                                       

Output of Program IFSEL:

Select one function:                        
                                            
         Function A:           Function B: 

After selecting and confirming function A:

Page      1                                                  05-01-17  11:04:07
                                                                               
Function A selected.                               

Top of page