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
 

 

Coding SQL statements in REXX

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

New User


Joined: 16 Aug 2009
Posts: 60
Location: chennai

PostPosted: Wed Oct 14, 2009 8:55 pm    Post subject: Coding SQL statements in REXX
Reply with quote

Hi All,

Plz help me to write a REXX program using SQL query with example.

Help me with sample code to run DB2 - REXX program.

I saw in manuals but could not understand.

Regards
Shreejita
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Oct 14, 2009 8:58 pm    Post subject:
Reply with quote

Hello and welcome to the forum,

Please post what you found in the manuals that is not clear. Someone here should be able to clarify.

Also, there are multiple topics in the forum of using SQL in REXX.
Back to top
View user's profile Send private message
John Alexander1

New User


Joined: 22 Sep 2009
Posts: 7
Location: Sydney Australia

PostPosted: Thu Oct 22, 2009 6:31 am    Post subject:
Reply with quote

Hi
below is a simple example, selecting 3 columns from a table, to test just change the table & column names and run .
Hope this helps.

/* Rexx */
PARSE UPPER ARG SSID

"ISPEXEC VGET ZSYSID"
"ISPEXEC VGET ZPREFIX"

SAY
SAY'SSN = 'SSID
SAY

"SUBCOM DSNREXX"
IF RC THEN S_RC= RXSUBCOM('ADD','DSNREXX','DSNREXX')

ADDRESS DSNREXX "CONNECT" SSID
ADDRESS DSNREXX "EXECSQL SET CURRENT PACKAGESET='DSNREXUR'"

SQL='SELECT COL1, COL2, COL3 ',
'FROM CRT.TABLE_XYZ ',
'WITH UR'
ADDRESS DSNREXX "EXECSQL DECLARE C1 CURSOR FOR S1"
K=1
IF SQLCODE¬=0 THEN CALL BYE
ADDRESS DSNREXX "EXECSQL PREPARE S1 INTO :OUTSQLDA FROM :SQL "
K=2
IF SQLCODE¬=0 THEN CALL BYE
ADDRESS DSNREXX "EXECSQL OPEN C1"
K=3
IF SQLCODE¬=0 THEN CALL BYE
N=0

DO UNTIL(SQLCODE=100)
ADDRESS DSNREXX "EXECSQL FETCH C1 USING DESCRIPTOR :OUTSQLDA "

ADDRESS DSNREXX "EXECSQL FETCH C1 INTO :HV1 :HV1IND,
:HV2 :HV2IND,
:HV3 :HV3IND"
IF SQLCODE=0 THEN DO
N=N+1
DO I=1 TO OUTSQLDA.SQLD /* FOR EACH COLUMN */
END
SAY 'LINE 'N' 'HV1' 'HV2' 'HV3
END
END

EXIT

BYE:

SAY'SQLCODE='SQLCODE
SAY'SQLSTATE='SQLSTATE
SAY'SQLERRMC='SQLERRMC
OUTCODE=SQLCODE-K*1000
SAY
SAY'OUTCODE=SQLCODE-K*1000='OUTCODE
SAY

EXIT OUTCODE
Back to top
View user's profile Send private message
shreejita

New User


Joined: 16 Aug 2009
Posts: 60
Location: chennai

PostPosted: Thu Oct 22, 2009 7:02 pm    Post subject:
Reply with quote

Thanks for the help

Regards
Shreejita
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
No new posts Passing data from REXX to C programme... chong.zhou CLIST & REXX 2 Wed Jul 26, 2017 9:11 pm
No new posts Passing data from REXX to C programme... chong.zhou All Other Mainframe Topics 0 Wed Jul 26, 2017 4:55 pm
No new posts REXX to get the all datasets name parasmalik20 CLIST & REXX 5 Tue Jul 18, 2017 9:10 pm
No new posts How system know which REXX to excute? jackzhang75 CLIST & REXX 14 Thu Jul 06, 2017 1:09 am
No new posts REXX - Dynamic file Creation d_sarlie CLIST & REXX 7 Tue Jun 27, 2017 7:30 pm


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