EXTMBR

735 Views


Using EXTMBR keyword, read data from a particular member of a file in RPG.

The EXTMBR keyword specifies which member of the file is opened.

You can specify a member name, '*ALL', or '*FIRST'

EXTMBR(mbrname)

You can even use a variable name for member name in EXTMBR.If a variable name is used, it must be set before the file is opened.

 Variable must be set:

  • Using the INZ keyword on the D specification
  • Passing the value in as an entry parameter

Examples:

Variable pMBRNME received as input parameter is used for EXMBR

FFileN     O  A E             DISK    ExtFile('LIB/FILENAME')             
F                                     ExtMbr(pMBRNME)                            
D pJobDate        S              7                      
D pMbrNme         S              7                      
 ********************************************************************** 
 * Entry Parameters                                                     
 ********************************************************************** 
C     *Entry        Plist                                               
C                   Parm                    pJobDate                    
C                   Parm                    pMbrNme                                         

Notice the file opened user open mode as the member name is set at a later stage.

FOBMbrFile IF A F 5295        DISK    ExtFILE(#ObFile)    
F                                     ExtMbr(#OBMBR)      
F                                     UsrOpn              
D #ObFile         S             21                          
D #OBMBR          S             10                          
C                   Eval      #ObFile = %Trim(#Lib) +          
C                             '/' + %Trim(#Fil)                
C                   Eval      #OBMBR = #FeedMBR                
 *                                                              
C                   If        Not %Open(OBMbrFile)              
C                   Open      OBMbrFile                         
C                   EndIf                                       

 

Dcl-f METRICFIL Usage(*Input:*Output) 
                UsrOpn 
                Rename(METRICFIL:@METR)      
                ExtFile('LIB/METRICFILE') 
                ExtMbr(Mbrname);         

Dcl-s  Mbrname               Char(10);
                        
MBRNAME= 'ADD'+ DatMMDD + SeqC;     

 If not %open(METRICFIL);    
    Open METRICFIL;            
 EndIf;                    
 Setgt *hival METRICFIL;   
 Readp  METRICFIL;  
   //Logic
 Close METRICFIL;        

 

Post Comments