Previous Topic: Accessing CALC RecordsNext Topic: Accessing a Sorted Set


Walking a Set

To access a record occurrence based on its logical position within a set, perform the following steps:

  1. Establish the current of set for the specified set type (for example, by issuing an OBTAIN CALC).
  2. Issue the FIND/OBTAIN WITHIN SET command.
  3. Check the ERROR-STATUS field for the value 0307 (DB-END-OF-SET).
  4. Perform the IDMS-STATUS routine if the DBMS returns a nonzero value other than 0307.

Example of Walking a Set

The program excerpt below shows the procedure for retrieving all member records in a set.

The program enters the database on the CALC-key field DEPT-ID-0410 and establishes currency on the DEPARTMENT record. It then walks the DEPT-EMPLOYEE set until the DBMS returns an ERROR-STATUS of 0307 (DB-END-OF-SET).

WORKING-STORAGE SECTION.
01  SWITCHES.
   05 EOF-SW                  PIC X    VALUE 'N'.
      88 END-OF-FILE                   VALUE 'Y'.
PROCEDURE DIVISION.
         .
    READ DEPT-RECORD-IN
         AT END MOVE 'Y' TO EOF-SW.
    PERFORM A300-GET-DEPT-SET THRU A300-EXIT
                       UNTIL EOF-SW = 'Y'.
    FINISH.
    GOBACK.
A300-GET-DEPT-SET.
    MOVE DEPT-ID-IN TO DEPT-ID-0410.
    OBTAIN CALC DEPARTMENT.
    IF DB-REC-NOT-FOUND
       DISPLAY 'DEPT: ' DEPT-ID-IN ' NOT FOUND'
       GO TO A300-GET-NEXT
    ELSE IF DB-STATUS-OK
       NEXT SENTENCE
    ELSE
       PERFORM IDMS-STATUS.
    MOVE DEPT-NAME-0410 TO DEPT-NAME-OUT.
    PERFORM U0900-WRITE-LINE.
A300-SET-WALK.
      *** RETRIEVE NEXT EMPLOYEE IN SET ***
    OBTAIN NEXT EMPLOYEE WITHIN DEPT-EMPLOYEE.
      *** CHECK FOR ERROR-STATUS = 0307 ***
    IF DB-END-OF-SET
       GO TO A300-GET-NEXT
      *** CHECK FOR ERROR-STATUS = 0000 ***
    ELSE IF DB-STATUS-OK
       NEXT SENTENCE
    ELSE
       PERFORM IDMS-STATUS.
    MOVE EMP-NAME-0415 TO EMP-NAME-OUT.
    MOVE EMP-ID-0415 TO EMP-ID-OUT.
    PERFORM U0900-WRITE-LINE.
    GO TO A300-SET-WALK.
A300-GET-NEXT.
    READ DEPT-RECORD-IN
         AT END MOVE 'Y' TO EOF-SW.
A300-EXIT.
    EXIT.