Was this helpful?
Multiple Sessions and the SQLCA
The SQL Communications Area (SQLCA) is a data area in which OpenSQL passes query status information to your application program. Although an application can sustain multiple sessions, there is only one SQLCA per application. By contrast, the values returned by INQUIRE_SQL(ERRORCODE) and INQUIRE_SQL(ERRORTEXT) are specific to a session.
If you switch sessions in a select loop (for example, by calling a routine that switches sessions) and execute database statements in the alternate session, the values in the SQLCA will be reset. When you return to the original session, the SQLCA will not reflect the results of the select loop.
When switching between sessions, the values in the SQLCA fields are not updated until after the first OpenSQL statement in the current session has completed. If you switch sessions, the values in the SQLCA will apply to the previous session until an OpenSQL statement in the current session resets them. In contrast, the error information returned by INQUIRE_SQL(ERRORTEXT and ERRORNO) always apply to the current session.
When an application switches sessions within a select loop or other block statement, the SQLCA field values are updated to reflect the status of the statements executed inside the nested session. After the application switches back to the session with the loop, the SQLCA field values reflect the status of the last statement in the nested session. Sqlcode and sqlwarn are not updated until the statement immediately following the loop completes. (The information obtained by INQUIRE_SQL is not valid until the statement following a loop completes.) For this reason, the application should reset the sqlcode and sqlwarn fields before continuing the loop.
Last modified date: 01/30/2023