SQL/MP Programming Manual for COBOL85

Data Retrieval and Modification
HP NonStop SQL/MP Programming Manual for COBOL85429326-004
4-9
Updating a Single Row
return the contents of the SQLCA structure, use the SQLCA_DISPLAY2_ or
SQLCA_TOBUFFER2_ procedure.
For more information, see Section 5, SQL/MP System Procedures, and Section 9,
Error and Status Reporting.
Updating a Single Row
This example updates a single row of the ORDERS table that contains information
about the order number specified by UPDATE-ORDERNUM. In a typical application, a
user enters the values for UPDATE-DATE and UPDATE-ORDERNUM. If the UPDATE
operation fails, check for SQL error 8227, which indicates you attempted to update a
row with an existing key (primary or unique alternate).
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 ORDERS.
02 ORDERNUM PIC 9(6) DISPLAY.
02 ORDER-DATE PIC 9(6) DISPLAY
02 DELIV-DATE PIC 9(6) DISPLAY.
02 SALESREP PIC 9(4) DISPLAY.
02 CUSTNUM PIC 9(4) DISPLAY.
01 NEWDATE PIC 9(6) DISPLAY.
EXEC SQL END DECLARE SECTION END-EXEC.
...
PROCEDURE DIVISION.
...
MOVE UPDATE-DATE TO NEWDATE.
MOVE UPDATE-ORDERNUM TO ORDERNUM OF ORDERS.
EXEC SQL UPDATE ORDERS SET DELIV-DATE = :NEWDATE
WHERE ORDERNUM = :ORDERNUM OF ORDERS
STABLE ACCESS END-EXEC.
Updating Multiple Rows
If you do not need to check a value in a row before you update the row, use a single
UPDATE statement to update multiple rows in a table. This example updates the
SALARY column of all rows in the EMPLOYEE table where the SALARY value is less
than HOSTVAR-MIN-SALARY. A user enters the values for HOSTVAR-INC and
HOSTVAR-MIN-SALARY.
EXEC SQL UPDATE PERSNL.EMPLOYEE
SET SALARY = SALARY * :HOSTVAR-INC
WHERE SALARY < :HOSTVAR-MIN-SALARY END-EXEC.
This example updates all rows in the EMPLOYEE. DEPTNUM column that contain the
value in HOSTVAR-OLD-DEPTNUM. After the update, all employees who were in the
department specified by HOSTVAR-OLD-DEPTNUM are moved to the department