Page 1 of 1

DB2 queries using rexx.

Posted: Tue Dec 29, 2015 4:51 pm
by Om Shah
HI,

Can we code DB2 queries using rexx? How can we do that? Can you please provide an example and or share some links to learn them.

Re: DB2 queries using rexx.

Posted: Tue Dec 29, 2015 6:20 pm
by Akatsukami
Om Shah wrote:HI,Can we code DB2 queries using rexx?
Certainly.
How can we do that?
By establishing a DB2 environment via RXSUBCOM (most shops use the IBM-supplied DSNREXX command processor; mine, however, uses Open Software's RXTASQL). Then, you can use embedded or dynamic SQL as with any other language.
Can you please provide an example and or share some links to learn them.
See here.

Re: DB2 queries using rexx.

Posted: Tue Dec 29, 2015 6:24 pm
by nicc
Please do your reserch BEFORE posting. Many examples and references over the Internet and, as Akatsukami has pointed out, in the DB2 manuals themselves - which you, obviously, did not consult.

Re: DB2 queries using rexx.

Posted: Tue Feb 09, 2016 12:16 pm
by Om Shah
Thanks Akatsukami. I have searched more and got this sample program which was very useful to me:

Code: Select all

"SUBCOM DSNREXX"                                                        
IF RC=0 THEN                                                            
   SAY 'DSNREXX  IS AVAILABLE'                                          
ELSE                                                                    
   DO                                                                    
    SAY 'DSNREXX  IS NOT AVAILABLE'                                      
    SAY 'SUBCOM RC :' RC                                                
   END                                                                  
                                                                        
IF RC THEN                                                              
   DO                                                                    
     S_RC = RXSUBCOM('ADD','DSNREXX','DSNREXX')                          
     SAY 'ADDING DSNREXX....................'                            
     PULL X                                                              
   END                                                                  
                                                                        
SQLSTMT = "SELECT COUNT(*)  FROM DB0*****.****** "                  
ADDRESS DSNREXX                                                          
"CONNECT DB2E"                                                          
                                                                        
"EXECSQL DECLARE C1 CURSOR FOR S1"                                      
                                                                        
"EXECSQL PREPARE S1 INTO :OUTSQLDA FROM :SQLSTMT"                        
                                                                        
"EXECSQL OPEN C1"                                                        
                                                                        
"EXECSQL FETCH C1 USING DESCRIPTOR :OUTSQLDA"                            
                                                                        
        DO I = 1 TO OUTSQLDA.SQLD                                        
           LINE = OUTSQLDA.I.SQLDATA                                    
        END                                                              
                                                                        
SAY LINE                                                                
                                                                        
"EXECSQL EXECUTE S1 USING DESCRIPTOR :OUTSQLDA"
This link http://publib.boulder.ibm.com/cgi-bin/b ... 0209162045 had been very useful too.

Re: DB2 queries using rexx.

Posted: Tue Feb 09, 2016 12:19 pm
by Om Shah
This pdf was also very useful:
DB2 and the Joy of Rexx.pdf