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
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 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 REXX cdoe to purge a JOB from spool a... Sulabh Agrawal CLIST & REXX 11 Thu Mar 09, 2017 11:36 am
No new posts Overriding PS data in rexx Shaheen Shaik CLIST & REXX 8 Fri Mar 03, 2017 5:08 pm


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