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   
 *                                   
 /free                               
    // 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;                    
       endif;                             
    enddo;                                
    exec sql CLOSE C1;                                                        
    *inlr=*on;                                      
    return;                                         
                                                    
    begsr movdet;                                   
       clear det1;                                 
       eval %subst(sdet1: 1)=prfnme;                
       eval %subst(sdet1:14)=prlnme;                
       write detail;                                                                
    endsr;                                          
 /end-free 

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.