IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Coding SQL statements in REXX


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Wed Oct 14, 2009 8:58 pm
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts run rexx code with jcl CLIST & REXX 15
Search our Forums:

Back to Top