Calling DSNTIAR to display SQLCA fields

来源:互联网 发布:danee的发展前景知乎 编辑:程序博客网 时间:2024/05/22 05:26

 If you're using DB2-COBOL, you're bound to have obtained something similar to the following in the spool: 

DSNT408I SQLCODE = -501, ERROR: THE CURSOR IDENTIFIED IN A FETCH OR CLOSE STATEMENT IS NOT OPEN 

followed by more details about why the DB2 operation failed. It could be anything: like timeout, deadlock message etc. 

CALL 'DSNTIAR' USING SQLCA 
                                             WT-DSNTIAR-ERROR-TABLE 
                                            WT-DSNTIAR-ERROR-TEXT-LENGTH. 

Hmm....you may wonder, "i never code such a line in my COBOL code!" Well we usually just copy paste the error routine. You might use a common ABEND-para. And this abend-para might be coded in another copylib. If you locate this copylib you'll find the above statement.

So, whenever we have a SQL problem, we call this abend para, which in turn calls the DSNTIAR routine which inturn uses the SQLCA structure to decode the sqlcode+other error numbers to produce a text message in our spool. The message might be something like below: 

DSNT408I SQLCODE = -501, ERROR: THE CURSOR IDENTIFIED IN A FETCH OR
CLOSE STATEMENT IS NOT OPEN
DSNT418I SQLSTATE = 24501 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNXERT SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = -315 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'FFFFFEC5' X'00000000' X'00000000'
X'FFFFFFFF' X'00000000' X'00000000' SQL DIAGNOSTIC INFORMATION 

Notice all the messages begin with a "DSNT"!