IF (COBOL)
The IF statement tests for the presence of member record occurrences in a set and determines the membership status of a record occurrence in a specified set. After the set has been evaluated, the IF statement specifies further action based on the outcome of the evaluation. For example, an IF statement can determine whether a set occurrence is empty and, if it is empty, erase the owner record.
idmscu
The IF statement tests for the presence of member record occurrences in a set and determines the membership status of a record occurrence in a specified set. After the set has been evaluated, the IF statement specifies further action based on the outcome of the evaluation. For example, an IF statement can determine whether a set occurrence is empty and, if it is empty, erase the owner record.
Depending on its format, the IF statement uses set or run-unit currency. The owner of the current record of the named set determines the object set occurrence of an IF statement. The current of run unit determines the object record occurrence.
Each IF statement contains a conditional phrase and an imperative statement. When an IF is issued, the precompiler generates a call to the DBMS to execute the conditional phrase. Then, the precompiler generates a COBOL IF statement that tests the results of the DBMS call to determine whether to execute the imperative statement.
Exercise care when nesting DML IF within COBOL IF statements because the logic can be difficult to follow. You may need to code explicit scope terminators.
If AUTOSTATUS is in use (see AUTOSTATUS Protocols), IDMS-STATUS is
not
performed automatically when an IF statement is issued.Native VSAM users:
The IF statement is invalid for sets having member records that are stored in native VSAM data sets.Syntax
►►─┬─ IFset-name is─┬───────┬─ EMPTY ─┬─imperative-statement. ────────────►◄ │ └─ NOT ─┘ │ │ │ └─ IF ─┬───────┬─set-nameMEMBER ───┘ └─ NOT ─┘
Parameters
- set-nameSpecifies which set owner to examine for the presence of member record occurrences. The specified set must be included in the subschema.
- EMPTYExecutes the imperative statement when the current occurrence of the named set is empty.
- NOT EMPTYExecutes the imperative statement when the current occurrence of the named set isnotempty.
- MEMBERExecutes the imperative statement when the current record of the run unit is a member of any occurrence of the specified set.
- NOTset-nameMEMBERExecutes the imperative statement when the current record of the run unit isnota member of any occurrence of the specified set.
- imperative-statementSpecifies the action to take when the specified condition is true.
Examples
The following examples illustrate the use of the IF statement.
- Example 1The following statement tests the COVERAGE-CLAIMS set for existing CLAIMS members. If no occurrences of the CLAIMS record are found (ERROR-STATUS is 0000), a message to that effect is moved to location CLAIMS-WS:IF COVERAGE-CLAIMS IS EMPTY MOVE 'NONE' TO CLAIMS-WS.If the current occurrence of the COVERAGE-CLAIMS set contains one or more occurrences of the CLAIMS record (ERROR-STATUS is 1601), the MOVE statement is ignored and the next statement in the program is executed.
- Example 2The following statement verifies that the EMPLOYEE record that is current of run unit is not a member of the current occurrence of the OFFICE-EMPLOYEE set before executing code to connect the EMPLOYEE record to that set:IF NOT OFFICE-EMPLOYEE MEMBER PERFORM LINK-SET.If the EMPLOYEE record is not a member of the OFFICE-EMPLOYEE set (ERROR-STATUS is 1601), the program performs the LINK-SET paragraph. If the EMPLOYEE record is already a member of the OFFICE-EMPLOYEE set (ERROR-STATUS is 0000), the PERFORM statement is ignored and the next statement in the program is executed.
Status Codes
After completion of the IF function, the ERROR-STATUS field in the IDMS communications block indicates the outcome:
Status code
| Meaning
|
0000 | The set is empty or the record that is current of run unit is a member of the set. |
1601 | The set is not empty or the record that is current of run unit is not a member of the set. |
1606 | Currency has not been established for the named set. |
1608 | An invalid set name has been specified or the current record of run unit is not a member of the named set. |
1613 | A current record of run unit has not been established or has been nullified by a preceding ERASE statement. |