Rules for the LIKEFILE keyword:

Table 1. File properties which are inherited and which can be overridden
Property or keyword Inherited from parent file Can be specified for new file
File type (Input, update, output, combined) Yes No
File addition Yes No
Record address type (RRN, keyed) Yes No
Record length (Program-described files) Yes No
Key length (Program-described files) Yes No
File organization (Program-described files) Yes No
Device Yes No
Start of changeALIAS End of change Start of changeYesEnd of change Start of changeNo End of change
BLOCK Yes No
COMMIT No Yes
DATFMT N/A, see Note 1
DEVID No Yes
Start of changeDISK End of change Start of changeYesEnd of change Start of changeNo End of change
EXTDESC Yes No
EXTFILE Yes, see Note 2 Yes
EXTIND No Yes
EXTMBR Yes, see Note 2 Yes
FORMLEN Yes Yes
FORMOFL Yes Yes
Start of changeHANDLER End of change Start of changeN/A, the HANDLER keyword is not supported for either the new file or the parent file.End of change
IGNORE Yes No
INCLUDE Yes No
INDDS No Yes
INFDS No Yes
INFSR No Yes
Start of changeKEYED End of change Start of changeYesEnd of change Start of changeNo End of change
KEYLOC Yes No
LIKEFILE Yes N/A
MAXDEV Yes Yes
OFLIND No Yes
PASS Yes No
PGMNAME Yes Yes
PLIST No Yes
PREFIX Yes No
Start of changePRINTER End of change Start of changeYesEnd of change Start of changeNo End of change
PRTCTL No Yes
QUALIFIED N/A, QUALIFIED is always implied for new file
RAFDATA N/A, see Note 3
RECNO No Yes
RENAME Yes No
SAVEDS No Yes
SAVEIND No Yes
Start of changeSEQ End of change Start of changeYesEnd of change Start of changeNo End of change
SFILE Yes, see Note 4 Yes, see Note 4
SLN No Yes
Start of changeSPECIAL End of change Start of changeYesEnd of change Start of changeNo End of change
STATIC No Yes
TEMPLATE No Yes
TIMFMT N/A, see Note 1
Start of changeUSAGE End of change Start of changeYesEnd of change Start of changeNo End of change
USROPN No Yes
Start of changeWORKSTN End of change Start of changeYesEnd of change Start of changeNo End of change
Note:
  1. The DATFMT and TIMFMT keywords relate to Date and Time fields coded on program-described Input specifications for the file, but Input specifications are not relevant for files defined with the LIKEFILE keyword.
  2. The external file associated with the RPG file depends on the EXTFILE and EXTMBR keywords specified for both the parent file and the new file. By default, the external file associated with each file is the name specified in the Name entry for the file. The new file inherits the EXTFILE or EXTMBR keywords from the parent file if the parameters are constants, but these keywords may also be specified for the new file. If the parameter for EXTFILE or EXTMBR is not a constant, the EXTFILE or EXTMBR keyword is not inherited. The following table shows the external files that would be used at runtime for some examples of EXTFILE and EXTMBR values for a parent file and a new file that is defined LIKEFILE the parent file.
    Table 2. File specification examples: EXTFILE and EXTMBR
    File Specifications External files used at runtime (Inherited values appear in bold)
    Examples where the EXTFILE and EXTMBR values are both constants
    FFILE1  IF  E    DISK
    FFILE2                 LIKEFILE(FILE1)
    *LIBL/FILE1(*FIRST)
    *LIBL/FILE2(*FIRST)
    FFILE1  IF  E    DISK  EXTFILE('MYLIB/MYFILE')
    FFILE2                 LIKEFILE(FILE1)
    MYLIB/MYFILE(*FIRST)
    MYLIB/MYFILE(*FIRST)
    FFILE1  IF  E    DISK
    FFILE2                 LIKEFILE(FILE1) EXTFILE('MYLIB/MYFILE')
    *LIBL/FILE1(*FIRST)
    MYLIB/MYFILE(*FIRST)
    FFILE1  IF  E    DISK  EXTFILE('MYLIB/MYFILE1')
    FFILE2                 LIKEFILE(FILE1) EXTFILE('MYLIB/MYFILE2')
    MYLIB/MYFILE1(*FIRST)
    MYLIB/MYFILE2(*FIRST)
    FFILE1  IF  E    DISK  EXTMBR('MBR1')
    FFILE2                 LIKEFILE(FILE1)
    *LIBL/FILE1(MBR1)
    *LIBL/FILE2(MBR1)
    FFILE1  IF  E    DISK
    FFILE2                 LIKEFILE(FILE1) EXTMBR('MBR1')
    *LIBL/FILE1(*FIRST)
    *LIBL/FILE2(MBR1)
    FFILE1  IF  E    DISK  EXTMBR('MBR1')
    FFILE2                 LIKEFILE(FILE1) EXTFILE('MYLIB/MYFILE2')
    *LIBL/FILE1(MBR1)
    MYLIB/MYFILE2(MBR1)
    Examples where the EXTFILE and EXTMBR values are both variable
    FFILE1  IF  E    DISK  EXTFILE(extfileVariable)
    FFILE2                 LIKEFILE(FILE1)
    Value of extfileVariable: 'MYLIB/MYFILE'
    MYLIB/MYFILE(*FIRST)
    *LIBL/FILE2(*FIRST)
    FFILE1  IF  E    DISK
    FFILE2                 LIKEFILE(FILE1) EXTFILE(extfileVariable)
    Value of extfileVariable: 'MYLIB/MYFILE'
    *LIBL/FILE1(*FIRST)
    MYLIB/MYFILE(*FIRST)
    FFILE1  IF  E    DISK  EXTFILE(extfileVariable1)
    FFILE2                 LIKEFILE(FILE1) EXTFILE(extfileVariable2)
    Value of extfileVariable1: 'MYLIB/MYFILE1'
    Value of extfileVariable2: 'MYLIB/MYFILE2'
    MYLIB/MYFILE1(*FIRST)
    MYLIB/MYFILE2(*FIRST)
    FFILE1  IF  E    DISK  EXTMBR(extmbrVariable)
    FFILE2                 LIKEFILE(FILE1)
    Value of extmbrVariable: 'MBR1'
    *LIBL/FILE1(MBR1)
    *LIBL/FILE2(*FIRST)
    FFILE1  IF  E    DISK
    FFILE2                 LIKEFILE(FILE1) EXTMBR(extmbrVariable)
    Value of extmbrVariable: 'MBR1'
    *LIBL/FILE1(*FIRST)
    *LIBL/FILE2(MBR1)
    FFILE1  IF  E    DISK  EXTMBR(extmbrVariable)
    FFILE2                 LIKEFILE(FILE1) EXTFILE(extfileVariable)
    Value of extmbrVariable: 'MBR1'
    Value of extfileVariable: 'MYLIB/MYFILE2'
    *LIBL/FILE1(MBR1)
    MYLIB/MYFILE2(*FIRST)
    Examples where the EXTFILE and EXTMBR values are mixed variables and constants
    FFILE1  IF  E    DISK  EXTFILE(extfileVariable1) EXTMBR('MBR1')
    FFILE2                 LIKEFILE(FILE1)
    Value of extfileVariable1: 'MYLIB/MYFILE1'
    MYLIB/MYFILE1(MBR1)
    *LIBL/FILE2(MBR1)
    FFILE1  IF  E    DISK  EXTMBR(extmbrVariable)
    FFILE2                 LIKEFILE(FILE1)
    Value of extmbrVariable: 'MBR1'
    *LIBL/FILE1(MBR1)
    *LIBL/FILE2(*FIRST)
    FFILE1  IF  E    DISK  EXTFILE('MYLIB/MYFILE1') EXTMBR(extmbrVariable)
    FFILE2                 LIKEFILE(FILE1)
    Value of extmbrVariable: 'MBR1'
    MYLIB/MYFILE1(MBR1)
    MYLIB/MYFILE1(*FIRST)
  3. The RAFDATA keyword is relevant only for Primary and Secondary files, but the parent file must be a Full Procedural file.
  4. The SFILE keyword indicates that the record format is a subfile record format, and it also indicates the name of the variable used to specify the relative record number for the subfile. The new file automatically inherits the fact that a particular record format is a subfile record format; however, it does not inherit the name of the variable used to specify the RRN. The SFILE keyword must be specified for the new file to indicate which variable is to be used to specify the relative record number for the subfile.