Rules for passing and using file parameters

Figure 136. Passing a file as a parameter to a procedure
 * Define a file template to be used for defining actual files       
 * and the file parameter                                            
Finfile_t  IF   E             DISK    TEMPLATE BLOCK(*YES)           
F                                     EXTDESC('MYLIB/MYFILE')        
F                                     RENAME(R01M2:inRec)            
                                                                     
 * Define two actual files that can be passed to the file parameter  
Ffile1                                LIKEFILE(infile_t)             
F                                     EXTFILE('MYLIB/FILE1')         
Ffile2                                LIKEFILE(infile_t)             
F                                     EXTFILE('MYLIB/FILE2')         
                                                                     
 * Define a data structure type for the file data                    
D inData_t        DS                  LIKEREC(infile_t.inRec:*INPUT) 
D                                     TEMPLATE                       
                                                                  
 * Define the prototype for a procedure to handle the files       
D nextValidRec    PR              N                               
D   infile                            LIKEFILE(infile_t)          
D   data                              LIKEDS(inData_t)            
                                                                  
 * Define variables to hold the record data                       
D f1Data          DS                  LIKEDS(inData_t)            
D f2Data          DS                  LIKEDS(inData_t)            
                                                                  
 /FREE                                                            
        // Process valid records from each file until one         
        // of the files has no more valid records                 
        DOW nextValidRec(file1 : f1Data)                          
        AND nextValidRec(file2 : f2Data);                         
           // ... process the data from the files                 
        ENDDO;                                                    
        *INLR = '1';                                             
 /END-FREE                                                       

 * The procedure that will process the file parameter
P nextValidRec    B                                              
D nextValidRec    PI              N                              
D   infile                            LIKEFILE(infile_t)         
D   data                              LIKEDS(inData_t)           
 /FREE                                                           
    // Search for a valid record in the file parameter
    READ infile data;                                            
    DOW NOT %EOF(infile);                                        
       IF data.active = 'Y';                                     
          RETURN *ON;            // This is a valid record       
       ENDIF;                                                    
       READ infile data;                                         
    ENDDO;                                                       
    RETURN *OFF;                 // No valid record was found      
 /END-FREE                                                         
P nextValidRec    E                                                




[ Top of Page | Previous Page | Next Page | Contents | Index ]