Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REXX DB2 SQL EXECUTE command fails with Host Variables SQLState 2000

Status
Not open for further replies.

TheArchies

Technical User
Oct 14, 2011
2
0
0
US
New to DB2/SQL, but I have worked with REXX. I've searched books, etc., I do not see what I'm doing wrong (obviously!). I connect to DB2, create the SQL statement, but fail when I perform "EXECSQL EXECUTE S1 USING :nfname, :nlname, :chguser". I have tried many different configuration regarding the SQL Statement's "?" and the execute statement - but no luck - the results are: SQLSTATE 2000, -110 (invalid Hexadecimal), -1, 100

I can get it to work if I don't use the host variables - but just the rexx names within the SQL statement -
" SET FRST_NM = '"nfname"'," , - any direction, assistance is greatly appreciated.

TRACE R
PARSE VAR NEWNAME NEWFNAME ' ' NEWLNAME
"ISPEXEC LIBDEF ISPLLIB DATASET ID('"MY.SDSNLOAD"')"
ADDRESS TSO "SUBCOM DSNREXX"
IF RC THEN DO
S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
END
ADDRESS DSNREXX
SSID = "DBZ1"
"CONNECT "SSID
IF SQLCODE <> 0 THEN CALL DBERROR

NAMSTMT="UPDATE APLGRP.USER_CNTCT ",
"SET FRST_NM = '"||?||"',",
"LAST_NM = '"||?||"'",
"WHERE ",
"USER_ID_CD = '"||?||"'"
nfname = NEWFNAME
nlname = NEWLNAME
chguser = USERID

ADDRESS DSNREXX
ADDRESS DSNREXX
"EXECSQL DECLARE C1 CURSOR FOR S1"
IF SQLCODE <> 0 THEN CALL DBERROR
ADDRESS DSNREXX
"EXECSQL PREPARE S1 FROM :NAMSTMT"
IF SQLCODE <> 0 THEN CALL DBERROR
ADDRESS DSNREXX
"EXECSQL EXECUTE S1 USING :nfname, :nlname, :chguser"
IF SQLCODE <> 0 THEN CALL DBERROR
ADDRESS DSNREXX
"EXECSQL COMMIT"
IF SQLCODE <> 0 THEN CALL DBERROR
ADDRESS ISPEXEC
'SETMSG MSG(ISRZ001)'
CALL USER_NAME
 
You don't need cursor for update.

Instead of declaring NAMESTR as
Code:
UPDATE APLGRP.USER_CNTCT
  SET FRST_NM = '?', 
  LAST_NM = '?' 
WHERE USER_ID_CD = '?'
declare it like this
Code:
UPDATE APLGRP.USER_CNTCT
  SET FRST_NM = ?, 
  LAST_NM = ? 
WHERE USER_ID_CD = ?

Then use this order:
Code:
EXECSQL 'PREPARE S1 FROM :NAMSTMT'
EXECSQL 'EXECUTE S1 USING :nfname, :nlname, :chguser'


 
Yes, I didn't think I needed to declare a cursor either, but I saw another link where someone with a similar issue said they had declared a cursor and that solved there problem. I was at the 'try anything' point.

Thanks so much - it works now. I could have sworn I tried the plain "?" - but must have had a comma off or something (it did take me a while to see a missing comma in the SQL).

Yee Haw!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top