Previous Topic: Accessing a Sorted SetNext Topic: Accessing Owner Records


Performing an Area Sweep

To access a record occurrence based on its physical position within an area, perform the following steps to establish the correct starting position:

  1. Issue the FIND/OBTAIN FIRST/LAST/nth WITHIN area-name statement.
  2. Check the ERROR-STATUS field for the value 0307 (DB-END-OF-SET).
  3. Perform the IDMS-STATUS routine if a value other than 0307 is returned.

Accessing Subsequent Records

To retrieve subsequent record occurrences within an area, perform the following steps:

  1. Issue the FIND/OBTAIN NEXT/PRIOR WITHIN area-name statement.
  2. Check the ERROR-STATUS field for the value 0307 (DB-END-OF-SET).
  3. Perform the IDMS-STATUS routine if a value other than 0307 is returned.

Relative Db-key Values

The first record occurrence in an area is the one with the lowest db-key; the last record has the highest db-key. The next record occurrence in an area is the one with the next higher db-key relative to the current record of the named area; the prior record is the one with the next lower db-key relative to the current of area.

Accessing Multiple Record Types

When accessing multiple records types while sweeping an area, be sure that the correct record occurrence is current of area before issuing the next FIND...WITHIN AREA. The easiest way to do this is by issuing the FIND CURRENT record-name statement each time before reissuing the OBTAIN NEXT WITHIN AREA statement. Failure to reestablish area currency ca CAuse your program to loop or skip records during retrieval.

The figure below shows retrieval of records within an area that contains multiple record types.

In this example, a sweep of the EMP-DEMO-REGION is performed, retrieving sequentially each EMPLOYEE record and all records in the associated EMPLOYEE-EXPERTISE set. The first command retrieves EMPLOYEE 119. Subsequent OBTAIN WITHIN SET statements retrieve the associated EXPERTISE records and establish currency on EXPERTISE 03. The FIND CURRENT statement is used to reestablish the proper position before retrieving EMPLOYEE 48. If FIND CURRENT EMPLOYEE is not specified, an attempt to retrieve the next EMPLOYEE record in the area would return EMPLOYEE 23.

Area Sweep of the EMP-DEMO-REGION

The program excerpt below shows a program that sequentially retrieves all occurrences of the EMPLOYEE record in the EMP-DEMO-REGION.

 A000-MAIN-LINE.
       .
 A400-GET-FIRST.
*** RETRIEVE FIRST EMPLOYEE IN AREA ***
     OBTAIN FIRST EMPLOYEE WITHIN EMP-DEMO-REGION.
*** CHECK FOR ERROR-STATUS = 0307 ***
     IF DB-END-OF-SET
        DISPLAY 'AREA EMPTY'
        FINISH
        GOBACK
     ELSE IF DB-STATUS-OK
        PERFORM A400-AREA-LOOP THRU A400-EXIT
             UNTIL DB-END-OF-SET
     ELSE
        PERFORM IDMS-STATUS.
     FINISH.
     GOBACK.
 A400-AREA-LOOP.
     DISPLAY 'EMPLOYEE: ' EMP-ID-0415
             'FIRST NAME: ' EMP-FIRST-NAME-0415
             'LAST NAME: ' EMP-LAST-NAME-0415.
*** RETRIEVE NEXT EMPLOYEE IN AREA ***
     OBTAIN NEXT EMPLOYEE WITHIN EMP-DEMO-REGION.
*** CHECK FOR ERROR-STATUS = 0307 ***
     IF DB-END-OF-SET
        GO TO A400-EXIT
     ELSE IF DB-STATUS-OK
        NEXT SENTENCE
     ELSE
        PERFORM IDMS-STATUS.
 A400-EXIT.
     EXIT.