Previous Topic: Checking for Set MembershipNext Topic: Using the IF MEMBER Statement


Using the IF EMPTY Statement

After you have retrieved the owner record in a set, you can issue the IF EMPTY statement to determine if the set owns any member record occurrences. This allows you to control processing based on whether the set is empty.

Steps in Determining if a Set Is Empty

To determine if a set is empty, perform the following steps:

  1. Establish currency for the set.
  2. Issue the IF EMPTY statement.
  3. Perform further processing as specified.

Note: If the set contains a member record, the first record in the set is always accessed during the processing of an IF EMPTY DML statement, in order to determine whether or not it is logically deleted. This can result in additional I/Os particularly if the member records are not stored VIA the set being tested.

How to Avoid an OBTAIN

You can also use the IF EMPTY statement to eliminate the need for using an OBTAIN FIRST WITHIN SET statement to walk a set, as illustrated in the program excerpt below.

Because the IF EMPTY statement determines that the set is not empty, you can be assured that the program can read at least one EMPLOYEE record before an ERROR-STATUS of 0307 (DB-END-OF-SET) is returned.

 .
 .
 .
    IF DEPT-EMPLOYEE IS EMPTY
        MOVE NO-EMP-MESSAGE TO TITLE-OUT
    ELSE
        PERFORM A100-DEPT-EMP-WALK THRU A100-EXIT
            UNTIL DB-END-OF-SET.
A100-DEPT-EMP-WALK.
    OBTAIN NEXT WITHIN DEPT-EMPLOYEE.
 .
 .
 .