ILE COBOL Language Reference

Simple Conditions

There are five simple conditions:

A simple condition has a truth value of either true or false.

Class Condition

The class condition determines whether the content of a data item is alphabetic, alphabetic-lower, alphabetic-upper, numeric, or contains only the characters in the set of characters specified by the CLASS clause as defined in the SPECIAL-NAMES paragraph of the Environment Division.

Class Condition - Format
 
>>-identifier--+----+--+-----+--+-NUMERIC----------+-----------><
               '-IS-'  '-NOT-'  +-ALPHABETIC-------+
                                +-ALPHABETIC-LOWER-+
                                +-ALPHABETIC-UPPER-+
                                |      (1)         |
                                +-DBCS-------------+
                                |       (1)        |
                                +-KANJI------------+
                                '-class-name-------'
 
 

Notes:

  1. IBM Extension

identifier

Must reference a data item whose usage is DISPLAY. When the identifier is a group item of zero length and NOT is specified in the class condition, the result is always true. If NOT is not specified, the result is always false.

If identifier is a function identifier, it must reference an alphanumeric, DBCS, or date-time function.

NOT
When used, NOT and the next keyword define the class test to be executed for truth value. For example, NOT NUMERIC is a truth test for determining that a data item is nonnumeric.
NUMERIC
The data item consists entirely of the characters 0 through 9,

with or without an operational sign.

If its PICTURE does not contain an operational sign, the item being tested is determined to be numeric only if the contents are numeric and an operational sign is not present.

If its PICTURE does contain an operational sign, the item being tested is determined to be numeric only if the item is an elementary item, the contents are numeric, and a valid operational sign is present.

In the EBCDIC character set, valid embedded operational positive signs are hexadecimal F, C, E, and A. Negative signs are hexadecimal D and B. The preferred positive sign is hexadecimal F, and the preferred negative sign is hexadecimal D. For items described with the SIGN IS SEPARATE clause, valid operational signs are + (hex 4E) and - (hex 60).

+-------------------------------IBM Extension--------------------------------+

For numeric and date-time data items, the identifier being tested can be described implicitly or explicitly as USAGE DISPLAY, USAGE PACKED-DECIMAL, USAGE COMP, or USAGE COMP-3.

+----------------------------End of IBM Extension----------------------------+

ALPHABETIC

The data item referenced by the identifier consists entirely of any combination of the lowercase or uppercase alphabetic characters A through Z, and the space.
ALPHABETIC-LOWER

The data item referenced by the identifier consists entirely of any combination of the lowercase alphabetic characters a through z, and the space.
ALPHABETIC-UPPER

The data item referenced by the identifier consists entirely of any combination of the uppercase alphabetic characters A through Z, and the space.
class-name

The data item referenced by the identifier consists entirely of the characters listed in the definition of class-name in the SPECIAL-NAMES paragraph.

The class-name test must not be used with an identifier described as numeric.

+-------------------------------IBM Extension--------------------------------+

DBCS
Identifier consists entirely of DBCS characters, with the following rules:
KANJI
Identifier consists entirely of DBCS characters, with the following rules:

+----------------------------End of IBM Extension----------------------------+

The class test is not valid for items whose usage is INDEX, POINTER, or PROCEDURE-POINTER because these items do not belong to any class or category.

+-------------------------------IBM Extension--------------------------------+

The class condition cannot be used for external floating-point (USAGE DISPLAY) or internal floating-point (USAGE COMP-1 and USAGE COMP-2) items.

+----------------------------End of IBM Extension----------------------------+

Table 20 shows valid forms of the class test.

Table 20. Valid Forms of the Class Test

Type of Identifier Valid Forms of the Class Test
Alphabetic
ALPHABETIC
ALPHABETIC-LOWER
ALPHABETIC-UPPER
class-name
NOT ALPHABETIC
NOT ALPHABETIC-LOWER
NOT ALPHABETIC-UPPER
NOT class-name
Alphanumeric,
Alphanumeric-edited,
or Numeric-edited
ALPHABETIC
ALPHABETIC-LOWER
ALPHABETIC-UPPER
NUMERIC
class-name
NOT ALPHABETIC
NOT ALPHABETIC-LOWER
NOT ALPHABETIC-UPPER
NOT NUMERIC
NOT class-name
External-Decimal
Internal-Decimal
NUMERIC
NOT NUMERIC

+-------------------------------IBM Extension--------------------------------+


DBCS
DBCS-edited

+----------------------------End of IBM Extension----------------------------+

 
 
DBCS
KANJI
 
 
NOT DBCS
NOT KANJI

+-------------------------------IBM Extension--------------------------------+


Date-Time

+----------------------------End of IBM Extension----------------------------+

 
 
NUMERIC
class-name
 
 
NOT NUMERIC
NOT class-name

Condition-Name Condition

A condition-name condition tests a conditional variable to determine whether its value is equal to any value(s) associated with the condition-name.

Condition-Name Condition - Format
 
>>-condition-name----------------------------------------------><
 
 

A condition-name is used in conditions as an abbreviation for the relation condition. The rules for comparing a conditional variable with a condition-name value are the same as those specified for relation conditions.

If the condition-name has been associated with a range of values (or with several ranges of values), the conditional variable is tested to determine whether or not its value falls within the range(s), including the end values. The result of the test is true if one of the values corresponding to the condition-name equals the value of its associated conditional variable.

+-------------------------------IBM Extension--------------------------------+

Condition-names with floating-point and DBCS values are allowed.

+----------------------------End of IBM Extension----------------------------+

The following example illustrates the use of conditional variables and condition-names:

01  NUMBER               PIC  99.
    88  FIVE             VALUE 5.
    88  ONE-DIGIT-EVEN   VALUE 0, 2, 4, 6, 8
    88  TWO-DIGIT-NUMBER VALUE 10 THRU 99

NUMBER is the conditional variable; FIVE, ONE-DIGIT-EVEN, TWO-DIGIT-NUMBER are condition-names.

The following IF statements can be added to the above example to determine the age group of a specific record:

IF FIVE...             (Tests for value 5)
IF ONE-DIGIT-EVEN      (Tests for values 0, 2, 4, 6, 8)
IF TWO-DIGIT-NUMBER    (Tests for values 10 thru 99)

Depending on the evaluation of the condition-name condition, alternative paths of execution are taken by the object program.

Relation Condition

A relation condition compares two operands, either of which may be an identifier, a literal, an arithmetic expression, index-name or a function-identifier. The relation condition must contain at least one reference to an identifier.

Relation Condition - Format
 
>>-operand-1--+----+--+----------+------------------------------>
              '-IS-'  |     (1)  |
                      '-NOT------'
 
>--+-+-GREATER--+------+-+---------------+--operand-2----------><
   | |          '-THAN-' |               |
   | +->-----------------+               |
   | +-LESS--+------+----+               |
   | |       '-THAN-'    |               |
   | +-<-----------------+               |
   | +-EQUAL--+----+-----+               |
   | |        '-TO-'     |               |
   | '-=-----------------'               |
   +-GREATER--+------+--OR EQUAL--+----+-+
   |          '-THAN-'            '-TO-' |
   +->=----------------------------------+
   +-LESS--+------+--OR EQUAL--+----+----+
   |       '-THAN-'            '-TO-'    |
   '-<=----------------------------------'
 
 

Notes:

  1. NOT GREATER THAN OR EQUAL TO, NOT >=, NOT LESS THAN OR EQUAL TO, and NOT <=, are IBM Extensions.

operand-1
The subject of the relation condition. Can be an identifier, literal, function-identifier, arithmetic expression, or index-name.
operand-2
The object of the relation condition. Can be an identifier, literal, function-identifier, arithmetic expression, or index-name.

The relational operator specifies the type of comparison to be made. Each relational operator must be preceded and followed by a space.

Relational Operator
Can Be Written

IS GREATER THAN
IS >

IS NOT GREATER THAN
IS NOT >

IS LESS THAN
IS <

IS NOT LESS THAN
IS NOT <

IS EQUAL TO
IS =

IS NOT EQUAL TO
IS NOT =

IS GREATER THAN OR EQUAL TO
IS >=

IS LESS THAN OR EQUAL TO
IS <=

+-------------------------------IBM Extension--------------------------------+

IS NOT GREATER THAN OR EQUAL TO
IS NOT >=

IS NOT LESS THAN OR EQUAL TO
IS NOT <=

+----------------------------End of IBM Extension----------------------------+

Related Information:

+-------------------------------IBM Extension--------------------------------+

DBCS Items

DBCS data items and literals can be used with all relational operators. Comparisons (between two DBCS items only) are based on the binary collating sequence of the hexadecimal values of the DBCS characters. If the items are not of the same length, the smaller item is padded with DBCS spaces to the right.

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

Pointer Data Items

Pointer data items are items defined explicitly as USAGE IS POINTER. Otherwise, they are ADDRESS OF data items or ADDRESS OF special registers, which are implicitly defined as USAGE IS POINTER.

Only EQUAL and NOT EQUAL are allowed as relational operators when you specify pointer data items. The operands are equal if the two addresses used in the comparison would both result in the same storage location.

This relation condition is allowed in IF, PERFORM, EVALUATE, and SEARCH Format 1 statements. It is not allowed in SEARCH Format 2 (SEARCH ALL) statements, because there is not a meaningful ordering that can be applied to pointer data items.

ADDRESS Comparison - Format
 
>>-+-ADDRESS OF--identifier-1-+--+----+--+-----+---------------->
   +-identifier-2-------------+  '-IS-'  '-NOT-'
   +-NULL---------------------+
   '-NULLS--------------------'
 
>--+-EQUAL--+----+-+--+-ADDRESS OF--identifier-3-+-------------><
   |        '-TO-' |  +-identifier-4-------------+
   '-=-------------'  +-NULL---------------------+
                      '-NULLS--------------------'
 
 
identifier-1, identifier-3
May specify any level item defined in the Data Division Section, except level 66 and level 88.
identifier-2, identifier-4
Must be described as USAGE IS POINTER.
NULL(S)
Can be used only if the other operand is one of these:

That is, NULL=NULL is not allowed.

+----------------------------End of IBM Extension----------------------------+

+-------------------------------IBM Extension--------------------------------+

Procedure-pointer Data Items

Procedure-pointer data items are items defined explicitly as USAGE IS PROCEDURE-POINTER.

Only EQUAL and NOT EQUAL are allowed as relational operators when you specify procedure-pointer data items. The operands are equal if the two addresses used in the comparison would both result in the same storage location.

This relation condition is allowed in IF, PERFORM, EVALUATE, and SEARCH Format 1 statements. It is not allowed in SEARCH Format 2 (SEARCH ALL) statements, because there is not a meaningful ordering that can be applied to procedure-pointer data items.

Procedure-Pointer Comparison - Format
 
>>-+-identifier-1-+--+----+--+-----+--+-EQUAL--+----+-+--------->
   +-NULL---------+  '-IS-'  '-NOT-'  |        '-TO-' |
   '-NULLS--------'                   '-=-------------'
 
>--+-identifier-2-+--------------------------------------------><
   +-NULL---------+
   '-NULLS--------'
 
 
identifier-1, identifier-2
Must be described as USAGE IS PROCEDURE-POINTER (see PROCEDURE-POINTER Phrase for more information).
NULL(S)
Used only if the other operand is defined as USAGE IS PROCEDURE-POINTER. NULL=NULL is not allowed.

+----------------------------End of IBM Extension----------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]