Tip

Override files with out using the OVRDBF command

Sometimes an ILE RPG program needs to operate on several different files serially (e.g., a print utility that processes all the data members of a particular file object), opening and closing each file in succession. In these cases, you often want to avoid the overhead of program initiation and instead just open each file in turn within the program. But to do so, you must override the database file using the OVRDBF command, which normally requires the existing CL program.

You can, however, execute the OVRDBF command within the RPGLE program using the QCMDEXC API. In either case we are taking the help of another program to override the file.

Can't we do this with out using any program or even without using the OVRDBF command? The answer is yes; we can achieve this in V5R1 using EXTFILE and EXTMBR operation codes.


Let us consider a file FILE1, which is having three members say MBR1, MBR2 and MBR3. Now I want to process all members' data in a single program with out using OVRDBF, how we can do? See the following sample code.

 
FFile1     if   e             Disk    Extfile(FilNam) ExtMbr(MbrNam)
F                                            UsrOpn                        
 *                                                                  
D FilNam            s             10a   Inz                           
D MbrNam          s             10a   Inz                           
 *                                                                  
 * Process first member data.                                       
 *                                                                  
C                   Eval      FilNam  =  'FILE1'                    
C                   Eval      MbrNam  =  'MBR1'                     
 *                                                                  
C                   Open      File1                                 
C                   Read      File1                                 
 *                                                                  
C                   DoW       Not %Eof(File1)                       
C                                                                   
C                                                                   
C                                                                   
C                   EndDo                                           
C                   Close     File1                   
 *                                                    
 * Process second member data.                        
 *                                                    
C                   Eval      FilNam  =  'FILE1'      
C                   Eval      MbrNam  =  'MBR2'       
 *                                                    
C                   Open      File1                   
C                   Read      File1                   
 *                                                    
C                   DoW       Not %Eof(File1)         
C                                                     
C                                                     
C                                                     
C                   EndDo                             
C                   Close     File1                   
 *                                                    
 * Process Third member data.                         
 *                                                    
C                   Eval      FilNam  =  'FILE1'  
C                   Eval      MbrNam  =  'MBR3'   
 *                                                
C                   Open      File1               
C                   Read      File1               
 *                                                
C                   DoW       Not %Eof(File1)     
C                                                  
C                                                 
C                                                 
C                   EndDo                         
C                   Close     File1    

With this code we can override the files without using the OVRDBF command and QCMDEXC API.

All these are BIG changes in RPG Land!

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

This was first published in November 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.