SQL/MP Programming Manual for COBOL85

Data Retrieval and Modification
HP NonStop SQL/MP Programming Manual for COBOL85429326-004
4-8
Inserting a Timestamp
Inserting a Timestamp
This example inserts a timestamp value into COLUMNA of TABLET. The COLUMNA
definition specifies the data type TIMESTAMP DEFAULT CURRENT. This example
uses the JULIANTIMESTAMP and CONVERTTIMESTAMP system procedures and the
SQL CONVERTTIMESTAMP function.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 DATETIME PIC S9(18) COMP.
EXEC SQL END DECLARE SECTION END-EXEC.
PROCEDURE DIVISION.
MAIN-DRIVER.
...
* Get current Julian timestamp in Greenwich mean time.
ENTER TAL "JULIANTIMESTAMP" GIVING DATETIME.
* Convert timestamp to local time.
ENTER TAL "CONVERTTIMESTAMP" USING DATETIME GIVING DATETIME.
...
* Insert value into COLUMNA of TABLET.
EXEC SQL INSERT INTO TABLET (COLUMNA)
VALUES ( CONVERTTIMESTAMP (:DATETIME))
END-EXEC.
UPDATE Statement
The UPDATE statement updates the values in one or more columns in a single row or
a set of rows of a table or protection view. (To update a set of rows one row at a time
by using a cursor, see Using SQL Cursors on page 4-11.)
To execute an UPDATE statement, a program’s PAID must have read and write access
to the table or view being updated and read access to any table or view specified in
subqueries of the search condition.
For audited tables and views, SQL/MP holds a lock on an updated row until the TMF
transaction is committed or rolled back. For a nonaudited table, SQL/MP holds the lock
until the program releases it.
SQL/MP returns these values to SQLCODE after an UPDATE statement.
The UPDATE statement updates rows in sequence. If an error occurs, SQL/MP returns
an error code to SQLCODE and terminates the UPDATE operation. The SQLCA
structure contains the number of rows updated. (If the UPDATE statement fails, do not
rely on the SQLCA structure for an accurate count of the number of rows updated.) To
SQLCODE Value Description
0
The UPDATE statement was successful.
100
No rows were found on a search condition.
< 0
An error occurred; SQLCODE contains the error number.
> 0 (not 100)
A warning occurred; SQLCODE contains the first warning number.