Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Accessing DB2 tables using Rexx

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
diwa_thilak

Active User


Joined: 13 Jul 2006
Posts: 205
Location: At my desk

PostPosted: Thu Oct 11, 2007 12:55 pm    Post subject: Accessing DB2 tables using Rexx
Reply with quote

Hi Friends,

I am planning to retrieve a single row from a table (DB2) using REXX utility.

Please throw some light about connecting DB2 tables using rexx and retrieving a data(row) from the table.
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10254
Location: italy

PostPosted: Thu Oct 11, 2007 1:15 pm    Post subject: Reply to: Accessing DB2 tables using Rexx
Reply with quote

Start looking at

Quote:
DB2 UDB for OS/390 and z/OS V7 Application Programming and SQL Guide"


http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/SEARCH?SEARCHREQUEST=rexx&Book=DSNAPH16&DN=SC26-9933-06&DT=20061206114427&TYPE=FUZZY&RANK=RANK&SEARCHTOPIC=TOPIC&SEARCHTEXT=TEXT&SEARCHINDEX=INDEX&SHELF=DSNSHHA7.bks
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1228
Location: Israel

PostPosted: Thu Oct 11, 2007 4:16 pm    Post subject:
Reply with quote

You have to declare a cursor and fetch the row from the table, even if you know there will never be more than one row.

The format is:
To load DB2 and connect:
Code:
Address TSO "SUBCOM DSNREXX"                 
If RC <> 0 Then Do                           
   S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')
   If S_RC <> 0 Then Do                     
      Say 'Problem Loading DB2 environment'
      Exit                                   
   End                                       
End
Address DSNREXX "CONNECT "DB2Name


To fetch the row:
Code:
SQLSTMT = "SELECT ... FROM ... WHERE ..."
Address DSNREXX                   
"EXECSQL DECLARE C7 CURSOR FOR S7"
"EXECSQL PREPARE S7 FROM :SQLSTMT"
"EXECSQL OPEN C7"                 
"EXECSQL FETCH C7 INTO :fld1, :fld2 ..."
LastSQL = SQLCODE
"EXECSQL CLOSE C7"                 
Address                           
Back to top
View user's profile Send private message
diwa_thilak

Active User


Joined: 13 Jul 2006
Posts: 205
Location: At my desk

PostPosted: Thu Oct 11, 2007 4:42 pm    Post subject: Reply to: Accessing DB2 tables using Rexx
Reply with quote

Thanks Marso,

I could able to connect to the DB2 successfully. But i could not able to retrieve the records.

I need to dynamically send values to the query.

SQLSTMT = "SELECT NUM_VAL_I FROM DSN.TABNAME WHERE ID_I = 045"

Also let me know whether :SQLSTMT , :FLD1 variables are accepted in REXX.

How to dynamically send values to the query ?
Back to top
View user's profile Send private message
diwa_thilak

Active User


Joined: 13 Jul 2006
Posts: 205
Location: At my desk

PostPosted: Thu Oct 11, 2007 4:58 pm    Post subject:
Reply with quote

Hi All,

Yeah :SQLSTMT and : FLD1 are valid statements in REXX.

But when i execute my below query i am getting SQLCODE as -981.

Quote:

-981 THE SQL STATEMENT FAILED BECAUSE THE RRSAF CONNECTION IS NOT IN A STATE THAT ALLOWS SQL OPERATIONS, REASON reason-code.


That means i could not able to connect to DB2. How to rebind and connect to DB2 ?
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Thu Oct 11, 2007 10:56 pm    Post subject:
Reply with quote

The instructions regarding binding REXX to DB2 are well described in the fine manual.

O.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1228
Location: Israel

PostPosted: Sun Oct 14, 2007 1:09 pm    Post subject: Reply to: Accessing DB2 tables using Rexx
Reply with quote

Send values to the query like usual:
Code:
MyVal = 45
SQLSTMT = "SELECT NUM_VAL_I FROM DSN.TABNAME WHERE ID_I = "MyVal

If the variable is alphabetic, add quotes:
Code:
MyVal = "diwa"
SQLSTMT = "SELECT NUM_VAL_I FROM DSN.TABNAME WHERE ID_I = '"MyVal"'"

About -981, try to get the reason-code by displaying SQLERRMC:
Code:
If SQLCODE <> 0 Then Do
   Say "SQLCODE = "SQLCODE
   Say "SQLERRMC = "SQLERRMC
End
Back to top
View user's profile Send private message
diwa_thilak

Active User


Joined: 13 Jul 2006
Posts: 205
Location: At my desk

PostPosted: Tue Oct 23, 2007 1:08 pm    Post subject:
Reply with quote

Hi All,

I found the bug, The connection identifier to connect to the DB2 tables needs to be specified while connecting to the tables.

I missed to specify.

Thanks All Buddies (e.s, Marso, Ofer).
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Tue Dec 16, 2008 4:46 pm    Post subject: Return code 1 for open c7 statement
Reply with quote

Hi All,
I have used similiar code in my REXX routine.
It is throwing a return code of 1 for open cursor.

My code :
SQLSTMT="SELECT CIM FROM DB2TEST.MASTER"
ADDRESS DSNREXX
"EXECSQL DECLARE C7 CURSOR FOR S7"
"EXECSQL PREPARE S7 FROM :SQLSTMT"
"EXECSQL OPEN C7"
"EXECSQL FETCH C7 INTO :FLD1"

I'm able to connect to DB2 subsystem.

Please comment.
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Tue Dec 16, 2008 4:51 pm    Post subject:
Reply with quote

Take a look at Marso's post above.

O.
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Wed Dec 17, 2008 12:18 pm    Post subject:
Reply with quote

It is working with return code 1 (warning?).
Is it possible to connect to two subsystems in one rexx routine?

ADDRESS DSNREXX "CONNECT " DSN1
ADDRESS DSNREXX
"EXECSQL DECLARE C7 CURSOR FOR S7"
"EXECSQL PREPARE S7 FROM :SQLSTMT"
"EXECSQL OPEN C7"
"EXECSQL FETCH C7 INTO :FLD1

ADDRESS DSNREXX "CONNECT " DSN2
ADDRESS DSNREXX
"EXECSQL DECLARE C7 CURSOR FOR S7"
"EXECSQL PREPARE S7 FROM :SQLSTMT"
"EXECSQL OPEN C7"
"EXECSQL FETCH C7 INTO :FLD1

Data is present in DSN1 and not in DSN2.
I'm getting sqlcode(for fetch) 0 for both regions which is wrong.
Output of 2nd region is same as 1st.
Should i do anything different?
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2360
Location: Israel

PostPosted: Wed Dec 17, 2008 12:35 pm    Post subject:
Reply with quote

Return code 1 for RXSUBCOM is not a warning. Read the manual.

O.
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Wed Dec 17, 2008 1:34 pm    Post subject:
Reply with quote

Ok. But can i have answer for my doubts?
Is it possible to connect to two subsystems in one rexx routine?
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Wed Dec 24, 2008 4:46 am    Post subject:
Reply with quote

Hi,

Ya you can, But you have to disconnect the first Sub-System

For Ex: You have 2 sub systems Prod & Test

1) Connect to prod
2) Execute the query
3) Disconnect from prod
4) Connect to test
5) Execute the query
6) Disconnect from prod


Thanks
Sai
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Need help on If condition continuatio... ashok_uddaraju CLIST & REXX 4 Fri May 19, 2017 8:55 am
No new posts Accessing first bit of PD value rajatbagga DFSORT/ICETOOL 11 Wed May 03, 2017 6:03 am
No new posts Running an REXX EXEC implicitly sho7hills CLIST & REXX 3 Thu Apr 20, 2017 8:14 am
No new posts Need help in REXX CALL program Raje1002 CLIST & REXX 5 Wed Apr 19, 2017 11:18 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us