3. Embedded SQL for COBOL : The SQL Communications Area : Error Handling Using the SQLCA : How to Determine the Number of Affected Rows
 
Share this page                  
How to Determine the Number of Affected Rows
The SQLCA variable SQLERRD(3) indicates how many rows were affected by the last insert, update, or delete statement. The following program fragment, which deletes all employees whose employee numbers are greater than a given number, demonstrates how SQLERRD is used:
Example: SQLERRD usage
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL BEGIN DECLARE SECTION.
  01 LOWER-BOUND-NUM PIC S9(8) USAGE COMP.
EXEC SQL END DECLARE SECTION.
01 SQLERRD-DISP PIC Z9(4) USAGE DISPLAY.
PROCEDURE DIVISION.
BEGIN.
    ...
    EXEC SQL DELETE FROM employee
        WHERE eno > :LOWER-BOUND-NUM
        END-EXEC.
* Print the number of employees deleted
    MOVE SQLERRD(3) TO SQLERRD-DISP.
    DISPLAY SQLERRD-DISP " rows were deleted."
    ...