Free Format SQLRPGLE Shell Program 1

Author: Lionel Halvorsen

This is a portion of a shell program that I use for writing simple reports. There is only one file here and I only use two fields.

The basic idea of the program is to use an SQL statement to select a file and fields, select the records, sort the records and then print each one.

d filestr         ds                 
d  fname                        11a   
d  lname                        16a   
    // loop through file                  
    exec sql                              
     declare C1 cursor for                
     SELECT fname,lname  
       FROM library1/file1                
       WHERE lname<'B'                   
       ORDER BY lname,fname
     for fetch only;                      
    exec sql OPEN C1;                     
    dow sqlcod=0;                         
       exec sql FETCH C1 INTO:filestr;    
       if sqlcod=0;                       
          exsr movdet;                    
    exec sql CLOSE C1;                                                        
    begsr movdet;                                   
       clear det1;                                 
       eval %subst(sdet1: 1)=prfnme;                
       eval %subst(sdet1:14)=prlnme;                
       write detail;                                                                

You can easily expand this shell by creating more complex SQL statements and adding more fields. You can also do more within the 'movdet' subroutine.