TechTip: What Are Model Files?

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 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:

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.

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.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: