Putting It All Together

In this program, which builds upon the previous programs, the following lines of code:

EXEC SQL
   DECLARE COBCUR1 CURSOR FOR 
       SELECT
            C_NUMBER, C_FIRST_NAME, C_LAST_NAME,
            TO_CHAR, C_INFO
       FROM CUSTOMER
       WHERE C_NUMBER >= :C-NUMBER
END-EXEC.

EXEC SQL 
   OPEN COBCUR1 
END-EXEC.

perform until SQLCODE not equal 0

    EXEC SQL
         FETCH COBCUR1 INTO :C-RECORD
    END-EXEC
    IF sqlcode EQUAL 0
         display c-number, ": ",c-first-name, 
                 c-last-name, c-info
    end-if
end-perform.

EXEC SQL
    CLOSE COBCUR1
END-EXEC.

cause the program to do the following:

  1. Identify the cursor: for all customers numbers greater than or equal to that supplied by the user, retrieve the values of C_NUMBER, C_FIRST_NAME, C_LAST_NAME, C_BIRTHDAY, and C_INFO and place them in a table of results.
  2. Open the cursor.
  3. Fetch the values of the indicated variables and assign them to the group item host variable :C_RECORD.
  4. If there are no errors or warnings, display the values of the variables.
  5. Do this until the program internally indicates that there are no more rows left in the table of results.
  6. Close the cursor.