Wednesday, July 10, 2013

Useful keywords for your F-specs

Update: The post linked here is updated to use totally free RPG definitions.

I was working within earshot of a colleague who had to recompile several programs he had built, over six months ago, that an user finally wanted to test. The objects had been deleted as part of a software refresh of our development IBM i (AS400), therefore, he would have to compile all of the program objects. He was going through all of the programs’ source code and recreating the work files he needed for the compiles, while grumbling that there must be an easier way to do this. That is when I offered to show him something that would make it easier in the future.

There are several File specification, F-specs, keywords that I use especially with “work” files:


In this scenario I have created a “work” file in QTEMP, WRK_FILE, that is a copy of the production file, TESTPF. I need to read one of the members, ONE, only, and I need to rename the record format so that it is not the same name as the record format name of the production file.

Below is an example of the code I could write:

1 FTESTPF    IF   E           K DISK
2 FANY_NAME  IF A E           K DISK    extfile('QTEMP/WRK_FILE')
3 F                                       extdesc('TESTPF')
4 F                                       extmbr('ONE')
5 F                                       rename(TESTPFR:WORK_RCD)

Line 2 shows how you can call the file any name you would like. The EXTFILE tells the program where to find the file, the library name is optional. In this case I want it to find the file in QTEMP. This could be considered a replacement for the CL command OVRDBF.

The EXTDESC, on line 3, tells the compiler that it can use the file description of TESTPF when compiling. At compile time QTEMP/WRK_FILE does not have to exist.

One line 4 the EXTMBR is used to denote which member should be read. If this is not given then the first member is read. As most files I deal with have only one member, EXTMBR is rarely used.

The RENAME, line 5, renames the record format of the file. As we have TESTPF in the program this keyword is needed as without it the program will not compile.

In the example below I am passing to this program the file to use and which member to use.

1 FANY_NAME  IF   E           K DISK    extfile(inFile)
2 F                                       extdesc('TESTPF') 
3 F                                       extmbr(inMbr) 
4 F                                       rename(TESTPFR:INPUT)
5 F                                       usropn
6  ************************************************************
7 D inFile          S             21
8 D inMbr           S             10

The file has to be “user opened”, see line 5, as at program initialization the file and member to use are not known. The OPEN operation in the Calculation specifications, C-spec, will do this.

I made the field inFile 21 long, see line 7, so it can be big enough to contain the largest library name, slash character, and file name.

More information about these keywords can be found on the IBM website...


This article was written for IBM i 7.1, and it should work with earlier releases too.


  1. Thanks Simon. This will be helpful.

  2. I've use almost all the keywords in earlier projects. The examples are great and worth a reading. Thought I'm not into development now, this post reminds me of the valuable keywords. Thanks for the post.

  3. I still maintain legacy RPG programs and the F-Spec will always stay. Also thanks for the reminder.

  4. Well done, Simon. Thanks for the reminder. F specs are not going away.

  5. I'm excited by the newer capabilities of qualified files, locally declared files, passing files as parameters etc.

  6. Just what I needed to valadate container file in another Company Library,

    Thank you,

  7. Hi Simon,could you please reply to below queries

    1.file ending in cl to read member in rpg physival having 2 members in to open files in rpg implicitly - to handle errors in rpg - infds ppsr to use particular member in rpg n how we read tht in rpg witout using EXTMBR and without using OVRDBF

    1. 1. Do you mean how to monitor when you reach the end of file you are reading in CL? If so insert a MONMSG after the RCVF.

      2. Read the post this comment is on.

      3. Do not understand what you mean.

      4. OPEN operation code. You will find more information at the link to the OS i 7.1 manuals on this page. Go to it & search for "RPG OPEN file". Don't be afraid to use the IBM manuals, that is why I put a link to them on this blog.

      5. I don't use the PSSR. I use the info from the Program Status Data Structure. For an example see:

      6. If there is more than one member & you do not use the EXTMBR or OVRDBF you will only read the first member.

  8. Can i mention psds in F specf

  9. thanks for introducing me to extdesc - J

  10. Hi Simon, you are doing great Work. Just a query can we read two members of same file in a single RPGLE program. I tried F-spec like below but dint work out. Can you please advise.
    FMMFILE IF E K disk Extfile(FMFILE)
    F extmbr('MMFILE')
    F Prefix(A_)
    FMMFILE IF E K disk Extfile(SMFILE)
    F extmbr('SMMFILE')
    F Prefix(B_)


To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.