× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: SQL - just looking for a little guidance.
  • From: "Smith, Mike" <Mike_Smith@xxxxxxxxxxxxxxxx>
  • Date: Fri, 4 May 2001 09:45:57 -0400

Well i already see, that i didn't need the fetchs on the UPRM and UCBS files
and that the update subroutines should have been changed to have a where
clause on them.

-----Original Message-----
From: Smith, Mike [mailto:Mike_Smith@RGCResources.com]
Sent: Friday, May 04, 2001 8:43 AM
To: RPG400-L@midrange.com
Subject: SQL - just looking for a little guidance.


I would just like for you to look at this program, and tell me if it should
have been done differently.
It doesn't do a whole lot, but i would like to make it as efficient as
possible.  
Should i have done a multirow fetch?  
could i have done a join on the update and made the whole thing work in 1 or
2 sql statements.?

I'm just trying to figure out how to do things better.

Oour shop is exploring SQL and trying to use it as much as possible and i'm
the guy that gets to experiment with it.  So any help is appreciated.

I have this program that updates 2 files based on the data from the first
file
  * DATA STRUCTURES                                         
 D UPRMDS       E DS                  EXTNAME(UPRM) INZ    
 D UCBSDS        E DS                  EXTNAME(UCBS) INZ    
 D RTUPDWFDS E DS                  EXTNAME(RTUPDWF) INZ 

C/EXEC SQL                                                  
C+  Declare WRKCURS CURSOR FOR                              
C+  SELECT * FROM RTUPDWF                                   
C/END-EXEC                                                  
                                                            
 * OPEN THE CURSOR - ROUTE CHANGE WORK FILE                 
                                                            
C/EXEC SQL                                                  
C+  OPEN WRKCURS                                            
C/END-EXEC                                                  
                                                            
 * READ THROUGH THE FILE UNTIL EOF                          
                                                            
C                   DOU       SQLCOD = 100                  
C/EXEC SQL                                                  
C+  FETCH WRKCURS INTO :RTUPDWFDS                           
C/END-EXEC                                                  

                                                                
 C                   IF        SQLCOD <> 100                    
 C                   IF        SQLCOD =  00000                  
                                                                
  * GET ALL RECORDS IN UPRM FOR THE ROUTE SELECTED IN RTUPDWF   
                                                                
 C/EXEC SQL                                                     
 C+  Declare PRMCURS CURSOR FOR                                 
 C+  SELECT * FROM UPRM                                         
 C+  WHERE  UPRTE = :RTORT                                      
 C/END-EXEC                                                     
                                                                
  * OPEN THE CURSOR - PREMISE FILE                              
                                                                
 C/EXEC SQL                                                     
 C+  OPEN PRMCURS                                               
 C/END-EXEC                                                     
                                                                
  * READ THROUGH THE FILE UNTIL EOF                             
                                                                
 C                   DOU       SQLCOD = 100                     
                                                                
 C/EXEC SQL                                                         
 C+  FETCH PRMCURS INTO :UPRMDS                                     
 C/END-EXEC                                                         
                                                                    
 C                   IF        SQLCOD <> 100                        
 C                   IF        SQLCOD =  00000                      
 C                   EXSR      $UPDATEPRM                           
 C                   ENDIF                                          
 C                   ENDIF                                          
 C                   ENDDO                                          
                                                                    
 C                   EXSR      $CLOSEPRM                            
                                                                    
  * GET ALL RECORDS IN UCBS FOR THE ROUTE SELECTED IN RTUPDWF       
                                                                    
 C/EXEC SQL                                                         
 C+  Declare CBSCURS CURSOR FOR                                     
 C+  SELECT * FROM UCBS                                             
 C+  WHERE  USORT = :RTORT                                          
 C/END-EXEC                                                         
  * OPEN THE CURSOR - ACCOUNT BILLED SERVICES FILE          
                                                            
 C/EXEC SQL                                                 
 C+  OPEN CBSCURS                                           
 C/END-EXEC                                                 
                                                            
  * READ THROUGH THE FILE UNTIL EOF                         
                                                            
 C                   DOU       SQLCOD = 100                 
 C/EXEC SQL                                                 
 C+  FETCH CBSCURS INTO :UCBSDS                             
 C/END-EXEC                                                 
                                                            
 C                   IF        SQLCOD <> 100                
 C                   IF        SQLCOD =  00000              
 C                   EXSR      $UPDATECBS                   
 C                   ENDIF                                  
 C                   ENDIF                                  
 C                   ENDDO                                  
                                                                      
 C                   EXSR      $CLOSECBS                              
                                                                      
 C                   ENDIF                                            
 C                   ENDIF                                            
                      ENDDO                                            
 C                   EXSR      $CLOSEWRK                              
                      EVAL      *INLR = *ON                            
 *================================================================   
  *  PROGRAM SUBROUTINES                                              
  *----------------------------------------------------------------   
 *****************************************************************    
C     $UPDATEPRM    BEGSR                                            
C/EXEC SQL                                                           
C+                  UPDATE UPRM SET                                  
C+                     UPRTE = :RTNRT                                
C/END-EXEC                                                           
                                                                   
 C                   ENDSR                                            
 *****************************************************************    
                                                                RTU
 C     $UPDATECBS    BEGSR                                         
 C/EXEC SQL                                                        
 C+                  UPDATE UCBS SET                               
 C+                     USORT = :RTNRT                             
 C/END-EXEC                                                        
                                                                   
 C                   ENDSR                                         
 ***************************************************************** 
 C     $CLOSEWRK     BEGSR                                         
 C/EXEC SQL                                                        
  + CLOSE WRKCURS                                                  
 C/END-EXEC                                                        
 C                   ENDSR                                         
 ***************************************************************** 
 C     $CLOSEPRM     BEGSR                                         
 C/EXEC SQL                                                        
  + CLOSE PRMCURS                                                  
 C/END-EXEC                                                        
 C                   ENDSR                                         
 *****************************************************************

 *************************************
C     $CLOSECBS     BEGSR            
C/EXEC SQL                           
 + CLOSE CBSCURS                     
C/END-EXEC                           
C                   ENDSR            
 *===================================


Michael Smith

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator:
david@midrange.com
+---
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.