Problem in connecting to DB2 through REXX



IBM's Command List programming language & Restructured Extended Executor

Problem in connecting to DB2 through REXX

Postby Bangaru » Thu Feb 07, 2008 3:50 pm

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.
Bangaru
 
Posts: 3
Joined: Thu Feb 07, 2008 3:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem in connecting to DB2 through REXX

Postby dick scherrer » Thu Feb 07, 2008 10:12 pm

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?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Problem in connecting to DB2 through REXX

Postby Bangaru » Fri Feb 08, 2008 9:51 am

Yes generally i connect to databsae using spufi only. but i want now to connect through the REXX code.
Bangaru
 
Posts: 3
Joined: Thu Feb 07, 2008 3:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem in connecting to DB2 through REXX

Postby Bangaru » Fri Feb 08, 2008 10:25 am

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?
Bangaru
 
Posts: 3
Joined: Thu Feb 07, 2008 3:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem in connecting to DB2 through REXX

Postby snuggiebug » Wed Apr 09, 2008 10:53 pm

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
snuggiebug
 
Posts: 7
Joined: Thu Mar 13, 2008 8:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem in connecting to DB2 through REXX

Postby snuggiebug » Wed Apr 09, 2008 10:57 pm

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')
snuggiebug
 
Posts: 7
Joined: Thu Mar 13, 2008 8:16 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Problem in connecting to DB2 through REXX

Postby dick scherrer » Thu Apr 10, 2008 12:23 am

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
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post