This example uses TEST with WAIT. The program asynchronously spawns two update requests, req_1 and req_2, respectively, then waits until both req_1 and req_2 have completed before proceeding.TEST statements monitor SQLCODE to determine when both req_1 and req_2 have returned successful completion codes (SQLCODE = 0) before continuing with the rest of the main program.
If either request has not completed (SQLCODE = -651), then the wait continues.
When both statements have completed, then the main program continues processing.
The non-SQL statements are pseudocode that show how the WAIT and TEST SQL statements may fit into a host main program.
... EXEC-SQL ASYNC req_1 UPDATE table_a SET a = :a; EXEC-SQL ASYNC req_2 UPDATE table_b SET b = :b; ... 100 EXEC-SQL WAIT req_1, req_2 COMPLETION; ... EXEC-SQL TEST req_1 COMPLETION; IF SQLCODE = -651 THEN GOTO 100 IF SQLCODE = 0 THEN CONTINUE EXEC-SQL TEST req_2 COMPLETION; IF SQLCODE = -651 THEN GOTO 100 IF SQLCODE = 0 THEN CONTINUE ...