AS400 RPG: override a file that is defined in Fspec


If the need is to just override the file to a single file then in the F Spec we can define the EXTFILE() EXTMBR() to override the file 

FDDMF      UF A E           K DISK    EXTFILE(LIB/FILENAME) EXTMBR(MBRA)


If the need is to override the file to different file then we need to execute the override command based on the logic.

We can use QCMDEXEC to run the CL command so that we dont need another CL program to do Overrides. To override a file that is defined in the F Spec we need to override the file before it is open.. So we need to control the file opening using USROPN option on that file.

Run the command to override using  QCMDEXEC. The scope of the override has to at job level due to ILE concept and activation group the default scope (Activation Group level) wont work. Then open the file and perform the program logic. At end close the file and delete the override (LVL(*JOB))



F Spec:

FDDMF      UF A E           K DISK    PreFix(Ddm_)
F                                                 UsrOpn 

D Spec

DRunCommand       PR                    extpgm('QCMDEXC')     
D pCommand                     2560     const                 
D pCmdLength                       15  5 const                 
D pCommand           S        2560                          
D pCmdLength         S            15  5 inz(2560)             


/FREE

 If Parm1 = 'Today';  pCommand = 'OVRDBF FILE(DDMF) TOFILE(*LIBL/ORDHDR) MBR(JUL320) OVRSCOPE(*JOB)';
 Else;
 pCommand = 'OVRDBF FILE(DDMF) TOFILE(*LIBL/ORDHDR) MBR(JUL310) OVRSCOPE(*JOB)';
 EndIf;

 Monitor;
 Runcommand(pCommand:pCmdLength);
 On-Error;
 EndMon;
 Open DDMF;
    ......
    ......
 Close DDMF;

 pCommand = 'DLTOVR FILE(DDMF) LVL(*JOB)';
 Monitor;
 Runcommand(pCommand:pCmdLength);
 On-Error;    

  .....
  ......

Comments

Popular posts from this blog

AS400 : Add a new line in text in email SNDSMTPEMM

AS400 Display: Radio Button (SNGCHCFLD)

AS400 Display File: Check Box (MLTCHCFLD)