Previous Topic: Retrieving RecordsNext Topic: Walking a Set


Accessing CALC Records

To access a record occurrence based on its CALC-key value, perform the following steps:

  1. Move the CALC-key value(s) to the CALC-key field(s) in the database record in variable storage.
  2. Issue the FIND/OBTAIN CALC command.
  3. Check the ERROR-STATUS field for the value 0326 (DB-REC-NOT-FOUND).
  4. Perform the IDMS-STATUS routine if the DBMS returns a nonzero value other than 0326.

Example of Retrieving CALC Records

The program excerpt below shows retrieval of CALC records.

The MOVE statement initializes the CALC-key field before the database access is performed. If the DBMS returns an ERROR-STATUS of 0326 (condition DB-REC-NOT-FOUND), the program prints a message and goes on to the next input record.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  SWITCHES.
   05 EOF-SW                  PIC X    VALUE 'N'.
      88 END-OF-FILE                   VALUE 'Y'.
PROCEDURE DIVISION.
         .
         .
    READ EMP-FILE-IN
         AT END MOVE 'Y' to EOF-SW.
    IF NOT END-OF-FILE
         PERFORM A400-GET-EMP-REC THRU A400-EXIT
            UNTIL END-OF-FILE.
    FINISH.
    GOBACK.
A400-GET-EMP-REC.
   *** INITIALIZE CALC KEY ***
    MOVE EMP-ID-IN TO EMP-ID-0415.
   *** RETRIEVE RECORD ***
    OBTAIN CALC EMPLOYEE.
      *** CHECK FOR ERROR-STATUS = 0326 ***
    IF DB-REC-NOT-FOUND THEN
       DISPLAY 'EMPLOYEE ID: ' EMP-ID-IN ' NOT FOUND'
      *** CHECK FOR ERROR-STATUS = 0000 ***
    ELSE IF DB-STATUS-OK
       PERFORM B100-WRITE-EMP-REPORT
    ELSE
       PERFORM IDMS-STATUS.
     READ EMP-FILE-IN
         AT END MOVE 'Y' to EOF-SW.
A400-EXIT.
    EXIT.

Retrieving Records with Duplicate CALC-keys

Record types may be defined to allow duplicate CALC-keys. To retrieve all records that have the same CALC-key value, retrieve the first by using the FIND/OBTAIN CALC statement shown above and then use the DUPLICATE option of the FIND/OBTAIN CALC statement to retrieve the additional records. An '0326' error status signals when no more records with the same key exist.