SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Transaction Management
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
14-2
Steps for Ensuring Data Consistency
Figure 14-2 shows the steps presented within the complete COBOL program. These 
steps are executed in the sample program Example C-2 on page C-4.
/* Set attributes for the transaction. */
EXEC SQL SET TRANSACTION 
 READ WRITE,
 ISOLATION LEVEL SERIALIZABLE,
 DIAGNOSTICS SIZE 10; 
...
EXEC SQL BEGIN WORK; /* Begin the transaction. */
...
EXEC SQL UPDATE ... ; /* Process database changes. */
...
if (strcmp(SQLSTATE, SQLSTATE_OK) == 0) { /* Test if OK. */
 ...
 ...
 EXEC SQL COMMIT WORK; /* Commit database changes. */
}
else {
 ...
 EXEC SQL ROLLBACK WORK; /* Rollback database changes. */
}
...
Figure 14-2. Coding Transaction Control Statements in a COBOL Program
 ...
 01 SQLSTATE-OK PIC X(5) VALUE "00000". 
 ...
 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
 01 SQLSTATE PIC X(5). 
 ...
 EXEC SQL END DECLARE SECTION END-EXEC.
 ...
* Set attributes for the transaction. 
 EXEC SQL SET TRANSACTION 
 READ WRITE,
 ISOLATION LEVEL SERIALIZABLE,
 DIAGNOSTICS SIZE 10
 END-EXEC. 
 ...
* Begin the transaction.
 EXEC SQL BEGIN WORK END-EXEC.
 ...
* Process database changes.
 EXEC SQL UPDATE ... END-EXEC.
 ...
Figure 14-1. Coding Transaction Control Statements in a C Program
C
2
3
4
5
6
7
COBOL
1
2
3
4










