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.