Page 1 of 1
Problem in connecting to DB2 through REXX
Posted:
Thu Feb 07, 2008 3:50 pm
by Bangaru
I want to connect to database through rexx and want to execute some queries. I searched for this and wrote one code. I am getting error. Can any one correct this please?
/*rexx*/
Address TSO "SUBCOM DSNREXX"
If RC = 0 Then do
address dsnrexx
"connect" ABC
if rc <> 0 then
say rc
say sqlcode
end
exit
After executing this i am not able to connect to ABC database. I am getting rc = -1 and sqlcode=-107.
Re: Problem in connecting to DB2 through REXX
Posted:
Thu Feb 07, 2008 10:12 pm
by dick scherrer
Hello,
Have you looked up the -107 sqlcode?
A -107 says that some name is too long.
Can you connect to the same database using spufi?
Re: Problem in connecting to DB2 through REXX
Posted:
Fri Feb 08, 2008 9:51 am
by Bangaru
Yes generally i connect to databsae using spufi only. but i want now to connect through the REXX code.
Re: Problem in connecting to DB2 through REXX
Posted:
Fri Feb 08, 2008 10:25 am
by Bangaru
now i got sqlcode as 0 but where can isee the output for the query?
/*rexx*/
Address TSO "SUBCOM DSNREXX"
If RC <> 0 Then Do
S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
If S_RC <> 0 Then
Say 'Problem Loading DB2 environment'
else
say 'success'
End
else
address dsnrexx
"connect" TDSN
if rc = 0 then do
say rc
say sqlcode
"execsql select * from frspsup.vcl03 where s_clntlocn_numb = ''11111'"
end
exit
where to see the output for the query?
Re: Problem in connecting to DB2 through REXX
Posted:
Wed Apr 09, 2008 10:53 pm
by snuggiebug
This is the code that I have used to view the output on the screen. To view the ouput in a file, you will have to write the TBSQLDA.I.SQLDATA to a flat file
SQLSTMT = "SELECT *
FROM SYSIBM.SYSTABLES
WHERE NAME = 'PLAN_TABLE'"
ADDRESS DSNREXX "EXECSQL PREPARE S4 INTO :TBSQLDA FROM :SQLSTMT"
ADDRESS DSNREXX "EXECSQL DECLARE C4 CURSOR FOR S4"
ADDRESS DSNREXX "EXECSQL OPEN C4"
DO UNTIL (SQLCODE <> 0)
ADDRESS DSNREXX "EXECSQL FETCH C4 USING DESCRIPTOR :TBSQLDA"
IF SQLCODE = 0 THEN DO
LINE = ''
DO I = 1 TO TBSQLDA.SQLD
LINE = LINE TBSQLDA.I.SQLDATA
END I
SAY LINE
END
END
Re: Problem in connecting to DB2 through REXX
Posted:
Wed Apr 09, 2008 10:57 pm
by snuggiebug
Don't forget to close the cursor and disconnect at the end of the code previously submitted. Use this...
ADDRESS DSNREXX "EXECSQL CLOSE C4"
ADDRESS DSNREXX "DISCONNECT"
S_RC = RXSUBCOM('DELETE','DSNREXX','DSNREXX')
Re: Problem in connecting to DB2 through REXX
Posted:
Thu Apr 10, 2008 12:23 am
by dick scherrer
Hello,
Good to hear this it is working as needed.
Thank you for posting your resolution - it will probably help someone else with the same requirement later
d