Manages in-line error handling.
COPY CTPUBLIC.
01 CONNECTION PIC S9(9) COMP SYNC. 01 RETCODE PIC S9(9) COMP SYNC. 01 COMPILER PIC S9(9) COMP SYNC. 01 OPERATION PIC S9(9) COMP SYNC. 01 MSGTYPE PIC S9(9) COMP SYNC. 01 INDEX PIC S9(9) COMP SYNC. 01 BUFFER type.
CALL 'CTBDIAG' USING CONNECTION RETCODE COMPILER OPERATION MSGTYPE INDEX BUFFER.
(I) Handle for this connection. This connection handle must already be allocated with CTBCONALLOC.
(O) Variable where the result from an executed function returns. Its value is one of the codes listed under “Return value,” in this section.
This argument is ignored.
(I) Operation to perform. Assign this argument one of the following values:
Value |
Meaning |
---|---|
CS-GET (33) |
Retrieves a specific message |
CS-CLEAR (35) |
Clears message information for this connection. |
CS-INIT (36) |
Initializes in-line error handling. |
CS-STATUS (37) |
Returns the current number of stored messages. |
CS-MSGLIMIT (38) |
Sets the maximum number of messages to store. |
(I) Type of message or structure on which the operation is to be performed. MSGTYPE can be any of the following symbolic values:
CS-CLIENTMSG-TYPE (4700) |
A CLIENTMSG structure. Indicates Client-Library messages. |
CS-SERVERMSG-TYPE (4701) |
A SERVERMSG structure. Indicates messages sent by the Mainframe ClientConnect or other server. |
CS-ALLMSG-TYPE (4702) |
Operation is performed on both Client-Library and server messages. |
SQLCA-TYPE (4703) |
A SQLCA structure. |
SQLCODE-TYPE (4704) |
A SQLCODE structure. |
(I) Index number of the message being retrieved. Messages are numbered sequentially: the first message has an index of 1, the second an index of 2, and so forth.
If MSGTYP is CS-CLIENTMSG-TYPE, then INDEX refers to Client-Library messages only.
If MSGTYP is CS-SERVERMSG-TYPE, then INDEX refers to server messages only.
If MSGTYP is CS-ALLMSG-TYPE, then INDEX refers to both Client-Library and server messages.
INDEX should be initialized to 1.
(I/O) An integer or a variable (“buffer”) that contains the message. Table 3-11 shows the relationship between BUFFER and other arguments.
This argument is typically either CHAR, a SQLCA structure, or a CLIENTMSG or SERVERMSG structure.
It is the responsibility of the programmer to provide
a buffer large enough to hold the largest possible message. If the
buffer is too small,
the message will overwrite data in adjacent fields.
CTBDIAG returns one of the following values:
Value |
Meaning |
---|---|
CS-SUCCEED (-1) |
The routine completed successfully. |
CS-FAIL (-2) |
The routine failed. Common reasons for a CTBDIAG failure include:
|
CS-NOERR (-207) |
The application attempted to retrieve a message for which the index number is greater than the number of messages in the queue. For example, the application attempted to retrieve message number 3, when only 2 messages are queued. |
The following example uses CTBDIAG to prepare to receive messages. This example is taken from the sample program SYCTSAA5 in Appendix A, “Sample Language Requests.”
*======================================================== *== == *== Subroutine to process input data == *== == *======================================================== PROCESS-INPUT. ********************************* * ALLOCATE A CONNECTION HANDLE. * ********************************* MOVE ZERO TO CSL-CON-HANDLE. CALL 'CTBCONAL' USING CSL-CTX-HANDLE CSL-RC CSL-CON-HANDLE. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBCONAL failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. ******************* * SET THE USER ID * ******************* CALL 'CTBCONPR' USING CSL-CON-HANDLE CSL-RC CS-SET CS-USERNAME PF-USER PF-USER-SIZE CS-FALSE OUTLEN. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBCONPR for user-id failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. ******************** * SET THE PASSWORD * ******************** CALL 'CTBCONPR' USING CSL-CON-HANDLE CSL-RC CS-SET CS-PASSWORD PF-PWD PF-PWD-SIZE CS-FALSE OUTLEN. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBCONPR for password failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. ******************** * SET THE TRAN NAME * ******************** IF PF-TRAN-SIZE IS NOT EQUAL TO ZEROES THEN CALL 'CTBCONPR' USING CSL-CON-HANDLE CSL-RC CS-SET CS-TRANSACTION-NAME PF-TRAN PF-TRAN-SIZE CS-FALSE OUTLEN IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBCONPR for TRAN name failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF END-IF. ******************************* * SET THE NET DRIVER PROPERTY * ******************************* IF PF-NETDRV = SPACES OR PF-NETDRV = 'LU62' X OR PF-NETDRV = 'lu62' MOVE CS-LU62 TO NETDRIVER ELSE IF PF-NETDRV = 'IBMTCPIP' OR PF-NETDRV = 'ibmtcpip' MOVE CS-TCPIP TO NETDRIVER ELSE IF PF-NETDRV = 'INTERLIN' OR PF-NETDRV = 'interlin' MOVE CS-INTERLINK TO NETDRIVER ELSE IF PF-NETDRV = 'CPIC' OR PF-NETDRV = 'cpic' MOVE CS-NCPIC TO NETDRIVER END-IF. IF PF-DRV-SIZE IS NOT EQUAL TO ZEROES THEN CALL 'CTBCONPR' USING CSL-CON-HANDLE CSL-RC CS-SET CS-NET-DRIVER NETDRIVER CS-UNUSED CS-FALSE OUTLEN IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBCONPR for network driver failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF END-IF.
******************************** * SET FOR MAINFRAME EXTRA INFO * ******************************** CALL 'CTBCONPR' USING CSL-CON-HANDLE CSL-RC CS-SET CS-EXTRA-INF CS-TRUE CS-UNUSED CS-FALSE CS-UNUSED. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBCONPR for extra info failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. *********************************** * SETUP retrieval of All Messages * *********************************** CALL 'CTBDIAG' USING CSL-CON-HANDLE, CSL-RC, CS-UNUSED, CS-INIT, CS-ALLMSG-TYPE, CS-UNUSED, CS-UNUSED. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBDIAG CS-INIT failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. ********************************************* * set the upper limit of number of messages * ********************************************* MOVE 5 TO PF-MSGLIMIT. CALL 'CTBDIAG' USING CSL-CON-HANDLE, CSL-RC, CS-UNUSED, CS-MSGLIMIT, CS-ALLMSG-TYPE, CS-UNUSED, PF-MSGLIMIT. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBDIAG CS-MSGLIMIT failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. ************************* * CONNECT TO THE SERVER * ************************* CALL 'CTBCONNE' USING CSL-CON-HANDLE CSL-RC PF-SERVER PF-SERVER-SIZE CS-FALSE. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBCONNE failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. IF NO-ERRORS THEN PERFORM SEND-COMMAND END-IF.
The following example uses CTBDIAG to retrieve diagnostic messages. This example is taken from the sample program SYCTSAA5 in Appendix A, “Sample Language Requests.”
*==================================================== *== == *== Subroutine to retrieve any diagnostic messages == *== == *==================================================== GET-DIAG-MESSAGES. ************************************ * Disable calls to this subroutine * ************************************ MOVE 'N' TO SW-DIAG. ****************************** * First, get client messages * ****************************** CALL 'CTBDIAG' USING CSL-CON-HANDLE, CSL-RC, CS-UNUSED, CS-STATUS, CS-CLIENTMSG-TYPE, CS-UNUSED, DG-NUM-OF-MSGS. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBDIAG CS-STATUS CS-CLIENTMSG-TYP fail' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE ELSE IF DG-NUM-OF-MSGS > 0 THEN PERFORM RETRIEVE-CLIENT-MSGS VARYING I FROM 1 BY 1 UNTIL I IS GREATER THAN DG-NUM-OF-MSGS END-IF END-IF.
***************************** * Then, get server messages * ***************************** CALL 'CTBDIAG' USING CSL-CON-HANDLE, CSL-RC, CS-UNUSED, CS-STATUS, CS-SERVERMSG-TYPE, CS-UNUSED, DG-NUM-OF-MSGS. IF CSL-RC NOT EQUAL CS-SUCCEED THEN STRING 'CTBDIAG CS-STATUS CS-SERVERMSG-TYP fail' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE ELSE IF DG-NUM-OF-MSGS > 0 THEN PERFORM RETRIEVE-SERVER-MSGS VARYING I FROM 1 BY 1 UNTIL I IS GREATER THAN DG-NUM-OF-MSGS END-IF END-IF. GET-DIAG-MESSAGES-EXIT. EXIT. *============================================================ *== == *== Subroutine to retrieve diagnostic messages from client == *== == *============================================================ RETRIEVE-CLIENT-MSGS. MOVE 1 TO I1. CALL 'CTBDIAG' USING CSL-CON-HANDLE, CSL-RC, CS-UNUSED, CS-GET, CS-CLIENTMSG-TYPE, DG-MSGNO, CLIENT-MSG. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBDIAG CS-GET CS-CLIENTMSG-TYPE failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. ************************ * display message text * ************************ MOVE DISP-CLIENT-MSG-HDR TO RSLTNO( I1 ). MOVE 3 TO I1. MOVE CM-SEVERITY TO CM-SEVERITY-DATA. MOVE CM-STATUS TO CM-STATUS-DATA. MOVE DISP-CLIENT-MSG-1 TO RSLTNO( I1 ). COMPUTE I1 EQUAL I1 + 1 MOVE CM-MSGNO TO CM-OC-MSGNO-DATA. MOVE DISP-CLIENT-MSG-2 TO RSLTNO( I1 ). COMPUTE I1 EQUAL I1 + 1 IF CM-MSGNO NOT EQUAL 0 THEN MOVE SPACES TO CM-OC-MSG-DATA MOVE CM-TEXT TO CM-OC-MSG-DATA MOVE CM-TEXT TO DISP-CLIENT-MSG-3A MOVE DISP-CLIENT-MSG-3 TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 IF CM-TEXT-LEN > 66 THEN MOVE CM-OC-MSG-DATA-2 TO CM-OC-MSG-DATA-X MOVE DISP-CLIENT-MSG-3B TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 IF CM-TEXT-LEN > 132 THEN MOVE SPACES TO CM-OC-MSG-DATA-X MOVE CM-OC-MSG-DATA-3 TO CM-OC-MSG-DATA-X MOVE DISP-CLIENT-MSG-3B TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 IF CM-TEXT-LEN > 198 THEN MOVE SPACES TO CM-OC-MSG-DATA-X MOVE CM-OC-MSG-DATA-4 TO CM-OC-MSG-DATA-X MOVE DISP-CLIENT-MSG-3B TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 END-IF END-IF END-IF ELSE MOVE DISP-EMPTY-CLIENT-MSG-3 TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 END-IF. MOVE CM-OS-MSGNO TO CM-OS-MSGNO-DATA. MOVE DISP-CLIENT-MSG-4 TO RSLTNO( I1 ). COMPUTE I1 EQUAL I1 + 1 IF CM-OS-MSGNO NOT EQUAL 0 THEN MOVE SPACES TO CM-OS-MSG-DATA MOVE CM-OS-MSGTXT TO CM-OS-MSG-DATA MOVE SPACES TO DISP-CLIENT-MSG-5A MOVE CM-OS-MSGTXT TO DISP-CLIENT-MSG-5A MOVE DISP-CLIENT-MSG-5 TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 IF CM-OS-MSGTEXT-LEN > 66 THEN MOVE SPACES TO CM-OC-MSG-DATA-X MOVE CM-OS-MSG-DATA-2 TO CM-OC-MSG-DATA-X MOVE DISP-CLIENT-MSG-3B TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 IF CM-OS-MSGTEXT-LEN > 132 THEN MOVE SPACES TO CM-OC-MSG-DATA-X MOVE CM-OS-MSG-DATA-3 TO CM-OC-MSG-DATA-X MOVE DISP-CLIENT-MSG-3B TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 IF CM-OS-MSGTEXT-LEN > 198 THEN MOVE SPACES TO CM-OC-MSG-DATA-X MOVE CM-OS-MSG-DATA-4 TO CM-OC-MSG-DATA-X MOVE DISP-CLIENT-MSG-3B TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 END-IF END-IF END-IF ELSE MOVE DISP-EMPTY-CLIENT-MSG-5 TO RSLTNO( I1 ) COMPUTE I1 EQUAL I1 + 1 END-IF. RETRIEVE-CLIENT-MSGS-EXIT. EXIT. *============================================================ *== == *== Subroutine to retrieve diagnostic messages from server == *== == *============================================================ RETRIEVE-SERVER-MSGS. CALL 'CTBDIAG' USING CSL-CON-HANDLE, CSL-RC, CS-UNUSED, CS-GET, CS-SERVERMSG-TYPE, DG-MSGNO, SERVER-MSG. IF CSL-RC NOT EQUAL CS-SUCCEED THEN MOVE SPACES TO MSGSTR STRING 'CTBDIAG CS-GET CS-SERVERMSG-TYPE failed' DELIMITED BY SIZE INTO MSGSTR PERFORM PRINT-MSG PERFORM ALL-DONE END-IF. ************************ * display message text * ************************ MOVE SM-MSGNO TO SM-MSG-NO-DATA. MOVE SM-SEV TO SM-SEVERITY-DATA. MOVE SM-STATE TO SM-STATE-DATA. MOVE SM-LINE TO SM-LINE-NO-DATA. MOVE SM-STATUS TO SM-STATUS-DATA. MOVE SPACES TO SM-SVRNAME-DATA. MOVE SM-SVRNAME TO SM-SVRNAME-DATA. MOVE SPACES TO SM-PROC-ID-DATA. MOVE SM-PROC TO SM-PROC-ID-DATA. MOVE SPACES TO SM-MSG-DATA. MOVE SM-TEXT TO SM-MSG-DATA. MOVE SPACES TO DISP-SERVER-MSG-5A. MOVE SM-TEXT TO DISP-SERVER-MSG-5A. MOVE DISP-SERVER-MSG-HDR TO RSLTNO (1). MOVE DISP-SERVER-MSG-1 TO RSLTNO (3). MOVE DISP-SERVER-MSG-2 TO RSLTNO (4). MOVE DISP-SERVER-MSG-3 TO RSLTNO (5). MOVE DISP-SERVER-MSG-4 TO RSLTNO (6). MOVE DISP-SERVER-MSG-5 TO RSLTNO (7). IF SM-TEXT-LEN > 66 THEN MOVE SPACES TO SM-MSG-DATA-X MOVE SM-MSG-DATA-2 TO SM-MSG-DATA-X MOVE DISP-SERVER-MSG-5X TO RSLTNO(8) IF SM-TEXT-LEN > 132 THEN MOVE SPACES TO SM-MSG-DATA-X MOVE SM-MSG-DATA-3 TO SM-MSG-DATA-X MOVE DISP-SERVER-MSG-5X TO RSLTNO(9) IF SM-TEXT-LEN > 198 THEN MOVE SPACES TO SM-MSG-DATA-X MOVE SM-MSG-DATA-4 TO SM-MSG-DATA-X MOVE DISP-SERVER-MSG-5X TO RSLTNO(10) END-IF END-IF END-IF. RETRIEVE-SERVER-MSGS-EXIT. EXIT.
CTBDIAG manages in-line message handling for a specific connection. If an application has more than one connection, it must make separate CTBDIAG calls for each connection.
Open ClientConnect applications always use CTBDIAG to handle Client-Library and server messages. Applications built with Open Client can provide alternative message-handling facilities.
An application can perform operations on Client-Library messages, server messages, or both.
For example, an application can clear Client-Library messages without affecting server messages:
CALL 'CTBDIAG' USING CONNECTION RETCODE CS-UNUSED CS-CLEAR CS-CLIENTMSG CS-UNUSED MSGBUFFER.
CTBDIAG allows an application to retrieve message information into standard Client-Library structures (CLIENTMSG, SERVERMSG, SQLCA or SQLCODE).
When retrieving messages, CTBDIAG assumes that BUFFER points to a structure of the type indicated by MSGTYPE.
An application that is retrieving messages into a SQLCA or SQLCODE structure must set the Client-Library property CS-EXTRA-INF to CS-TRUE. This is because the SQL structures require information that is not ordinarily returned by the Client-Library error handling mechanism.
Use CTBCONPROPS or CSBCONFIG to set CS-EXTRA-INF.
An application that does not use the SQLCA or SQLCODE structures can also set CS-EXTRA-INF to CS-TRUE. In this case, the extra information returns as standard Client-Library messages.
For more information about CS-EXTRA-INF, see “Properties” and the reference pages for CTBCONPROPS and CSBCONFIG.
WARNING! If CTBDIAG does not have sufficient internal storage space in which to save a new message, it throws away all unread messages and stops saving messages. The next time it is called with OPERATION as CS-GET, it returns a message to indicate the space problem. After returning this message, CTBDIAG starts saving messages again.
Initializing in-line error handling
An application must initialize in-line error handling before it can retrieve any errors. To initialize in-line error handling, call CTBDIAG with OPERATION as CS-INIT.
Generally, if a connection uses in-line error handling, the application should call CTBDIAG to initialize in-line error handling for a connection immediately after allocating it with CTBCONALLOC.
Clearing messages
To clear message information for a connection, an application calls OPERATION as CS-CLEAR.
To clear Client-Library messages only, set MSGTYPE to CS-CLIENTMSG-TYPE.
To clear server messages only, set MSGTYPE to CS-SERVERMSG-TYPE.
To clear both Client-Library and server messages, set MSGTYPE to SQLCA, SQLCODE, or CS-ALLMSG-TYPE.
If OPERATION is CS-CLEAR and MSGTYPE is not CS-ALLMSG-TYPE:
CTBDIAG assumes that BUFFER is a structure of type MSGTYPE.
CTBDIAG clears the buffer by setting it to blanks or LOW-VALUES, as appropriate.
Message information is not cleared until an application explicitly calls CTBDIAG with OPERATION as CS-CLEAR. Retrieving a message does not remove it from the message queue.
Retrieving messages
To retrieve message information, an application calls CTBDIAG with OPERATION as CS-GET, MSGTYPE as the type of structure in which to retrieve the message, INDEX as the index number of the message of interest, and BUFFER as an integer or a variable, as appropriate.
If MSGTYPE is CS-CLIENTMSG-TYPE, INDEX refers only to Client-Library messages.
If MSGTYPE is CS-SERVERMSG-TYPE, INDEX refers only to server messages.
If MSGTYPE has any other value, INDEX refers to the collective “queue” of both types of messages combined.
CTBDIAG creates a messages queue in the buffer and fills the buffer with message information. It returns messages to the client in the order in which they are received.
If an application attempts to retrieve a message with an index that is higher than the highest valid index, CTBDIAG returns CS-NOMSG to indicate that a message is not available.
Limiting messages
The Client-Library default behavior is to save an unlimited number of messages. Applications running on platforms with limited memory may want to limit the number of messages that Client-Library saves. The default for MVS is 25.
An application can limit the number of saved Client-Library messages, the number of saved server messages, and the total number of saved messages.
To limit the number of saved messages, an application calls CTBDIAG with OPERATION as CS-MSGLIMIT and MSGTYPE as CS-CLIENTMSG-TYPE, CS-SERVERMSG-TYPE, or CS-ALLMSG-TYPE:
If MSGTYPE is CS-CLIENTMSG-TYPE, the number of Client-Library messages is limited.
If MSGTYPE is CS-SERVERMSG-TYPE, the number of server messages is limited.
If MSGTYPE is CS-ALLMSG-TYPE, the total number of Client-Library and server messages combined is limited.
When a specific message limit is reached, Client-Library discards any new messages of that type. When a combined message limit is reached, Client-Library discards any new messages.
Retrieving the number of messages
To find out how many messages were retrieved, an application calls CTBDIAG with OPERATION as CS-STATUS and MSGTYPE as the type of message of interest.
Table 3-11 lists a summary of arguments for CTBDIAG.
Operation |
CTBDIAG action |
MSGTYPE value |
INDEX value |
BUFFER value |
---|---|---|---|---|
CS-INIT |
Initializes in-line error handling. An application must call CTBDIAG with a CS-INIT operation before it can process error messages in line. |
CS-UNUSED |
CS-UNUSED |
Ignored. |
CS-CLEAR |
Clears message information for this connection. |
One of the legal MSGTYPE values.
|
CS-UNUSED |
A buffer for which the type is defined by MSGTYPE or is LOW-VALUES. |
CS-GET |
Retrieves a specific message. |
Any legal MSGTYPE value except CS-ALLMSG-TYPE.
|
The index number of the message to retrieve. |
A buffer whose type is defined by MSGTYPE. |
CS-MSGLIMIT |
Sets the maximum number of messages to store. |
CS-CLIENTMSG-TYPE to limit Client-Library messages only. CS-SERVERMSG-TYPE to limit server messages only. CS-ALLMSG-TYPE to limit the total number of Client-Library and server messages combined. |
CS-UNUSED |
An integer value. |
CS-STATUS |
Returns the current number of stored messages. |
CS-CLIENTMSG-TYPE to retrieve the number of Client-Library messages. CS-SERVERMSG-TYPE to retrieve the number of server messages. CS-ALLMSG-TYPE to retrieve the total number of Client-Library and server messages combined. |
CS-UNUSED |
An integer variable. |
Related topics