Model files are little-known features of i5/OS. But with some basic knowledge, developers can use them to simplify some programming tasks.
Model files are physical files supplied by i5/OS commands and used to generate output to outfiles. They provide the model record format and fields needed to create the user-specified outfiles. Because they are used as models, they normally don't have any data themselves; they may not even have a member.
To discuss model files, let's talk about one in particular: QADSPFFD. This model file is a physical file with an object of type *FILE and an attribute of PF-DTA. QADSPFFD is specifically used by the DSPFFD command. Consider the command:
When the command runs, it uses the model file QADSPFFD to create FFDOUT, which contains the same field layout, record format name, and field names as QADSPFFD.
So what does this mean to you, the developer? You can use model files to simplify some of your programming steps.
Consider the above command in a CL program, which also contains this:
To compile this program, you would need to create a file called FFDOUT so that the CL compiler can find the description. The same is true if you call an HLL program that accesses FFDOUT and its description.
Now, consider the same CL program, with this:
|
|
DCLF QTEMP/QADSPFFD
|
|
DSPFFD FILE(MYFILE) OUTPUT(*OUTFILE) OUTFILE(QTEMP/QADSPFFD)
|
|
CALL MYHLLPGM
|
|
ENDPGM
Now, you don't need to create the file for compilation. QADSPFFD already exists as a model file. Your change management package will thank you.
Note the use of QTEMP. You cannot use the model file itself as your output file. i5/OS doesn't like that. The model files are in QSYS.
You still may need to do some database overriding when the program runs, but even that step can be eliminated. You may even be able to eliminate the CL driver program altogether. Consider this RPG F-spec that uses DSPOBJD's model file QADSPOBJ:
The RPG compiler will pull in the description for this file directly from the model file. At runtime, the file in QTEMP will be accessed. With USROPN, you can generate the file directly from the RPG program by issuing a DSPOBJD command with QCMDEXC or system() before opening the file.
Finding a Model File
There are quite a few model files. Some commands—like DSPFD or DSPJRN—have many model files. So how can you find the one you want? The easiest way is to look up the command in the CL Command Reference in the InfoCenter. The documentation for any command that uses model files will have the files listed, usually under the section about the command's OUTFILE keyword.
Model files are a good way to simplify use of command outfiles by using their external descriptions but eliminating the need to have an outfile present when compiling a program.
Doug Eckersley is the chief iSeries developer at Dominion Homes in Dublin, Ohio. He has over 16 years of application development experience and is the co-author of Brainbench’s RPG/IV certification test.
LATEST COMMENTS
MC Press Online