How will you detect the condition of the end of cursor rows in a COBOL-DB2 program?

DB2DatabaseBig Data Analytics

The cursor can be used to fetch multiple rows from a DB2 table. However, we have to fetch this cursor in a loop so that values corresponding to a single row are assigned to host variables at a time. Based on this logic we have to process our loop till the cursor reaches the last row result.

The SQLCODE field takes the value as 100 when there are no more rows left in the cursor to be fetched. Practically, we can implement this in the following way.

SET WF-END-CURSOR-N TO TRUE
PERFORM UNTIL WF-END-CURSOR-Y
   EXEC SQL
      FETCH ORDER_CUR INTO :ORDER-ID
   END-EXEC
   IF SQLCODE = 100
      SET WF-END-CURSOR-Y TO TRUE
   ELSE
      PERFORM A20-PROCESS-RECORD
   END-IF
END-PERFORM

WF-END-CURSOR-Y and WF-END-CURSOR-N are two flags at 88 level which is used to control the loop. Once the SQLCODE has the value 100 that means the cursor has reached at the last row and loop is terminated.

raja
Published on 14-Sep-2020 15:26:52
Advertisements