Here is a CL program that places the interpretation in the job message queue for debugging purposes. I also this from the RPG.
SQLCODE: PGM PARM(&CODE &PSMSG)
DCL VAR(&CODE) TYPE(*INT) /* Error Code from SQLCOD */
DCL VAR(&PSMSG) TYPE(*CHAR) LEN(70) /* Message Data from SQLCOD */
DCL VAR(&MSG) TYPE(*CHAR) LEN(70) /* Interpreted Message */
DCL VAR(&TEST) TYPE(*DEC) LEN(4 0)
DCL VAR(&SCODE) TYPE(*CHAR) LEN(4)
DCL VAR(&SQLCODE) TYPE(*CHAR) LEN(7)
/* check parameters */
CHGVAR VAR(&MSG) VALUE(&PSMSG)
MONMSG MSGID(CPF0000) EXEC(DO)
CHGVAR VAR(&MSG) VALUE(' ')
ENDDO
/* Translate error code to get the last four characters of the Message code */
CHGVAR VAR(&TEST) VALUE(&CODE * -1)
IF COND(&TEST > &CODE) THEN(CHGVAR VAR(&CODE) +
VALUE(&TEST))
CHGVAR VAR(&SCODE) VALUE(&CODE)
IF COND(&CODE > 999) THEN(DO)
CHGVAR VAR(&SQLCODE) VALUE('SQ1' || &SCODE)
ENDDO
ELSE CMD(DO)
CHGVAR VAR(&SQLCODE) VALUE('SQL' || &SCODE)
ENDDO
SNDPGMMSG MSG('**** SQL Message Decode Follows ****')
SNDPGMMSG MSGID(&SQLCODE) MSGF(QSQLMSG) MSGDTA(&MSG)
SNDPGMMSG MSG('**** SQL Message Decode Complete ****')
ENDPGM
Thanks,
Marvin
------------------------------
message: 5
date: Wed, 22 Oct 2008 14:25:13 -0500
from: "Lim Hock-Chai" <Lim.Hock-Chai@xxxxxxxxxxxxxxx>
subject: Using SQLCODE to access QSQLMSG
I was under the impression that I can retrieve the SQL error message by
concatenating the text "SQL" and SQLCode to form the message ID. See
link
below:
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?to
pic=/rzala/rzalamess.htm . Is this correct? If so, how should I deal
with SQL code that is greater the 9999?
------------------------------
As an Amazon Associate we earn from qualifying purchases.