Wednesday, January 23, 2008

Model Files:

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:
DSPFFD FILE(MYFILE) OUTPUT(*OUTFILE) OUTFILE(FFDOUT)
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 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:
DCLF FFDOUT
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:
PGM
|
|
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:
FQADSPOBJ IF E K disk extfile('QTEMP/QADSPOBJ') usropn
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.

No comments: