Tips and Techniques: EXTFILE and EXTMBR

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

Using the OVRDBF command to change a member name or point an RPG IV database file at a file in another library has been practiced for years. But in Version 5 of OS/400, IBM added support to RPG IV that allows you to avoid specifying overrides for simple processes, such as opening a different member or pointer at a different library.

The file description keywords EXTFILE and EXTMBR were added in V5R1, and they allow you to specify the name of the file, library, and member to be opened at runtime. The file description still uses the hard-code file name in columns 7 to 16 of the File specification as the externally described file definition, and you still reference the file throughout the program using this name, but the EXTFILE keyword can contain the name of a field that contains the runtime file name, and the EXTMBR keyword can contain the name of a field that contains the runtime member name.

You may use either or both of these keywords. Neither is required. To use them, specify the field name within the parentheses of the keyword and make sure that field contains a valid name when the program is started. If it doesn't, the program will generate an error.

Here's a simple example that uses the EXTFILE keyword only.

     FCUSTMAST  IF   E           K DISK    EXTFILE(myFile

     D myFile          S             21A   Inz('QGPL/CUSTMAST')

EXTFILE(myFile) is specified, and then the variable named MYFILE is defined as a 21-position character field. It must be 21 bytes because the syntax of the file in the field is the same as the way it is specified on the OVRDBF command, which is library/object and includes the forward slash qualifier symbol.

Unlike OVRDBF, EXTFILE and EXTMBR open the file and/or members directly without applying an override. This is subtle but important because if you try to view the open files using option 15 from the WRKJOB menu, you will not see the file listed. You need to use option 14 instead.

Since the variable containing the file or member name must be populated when the program begins, it is often advantageous, although not required, to specify the USROPN keyword along with EXTFILE or EXTMBR and then open the file yourself in the Calculation specifications. For example:

     FCUSTMAST  IF   E           K DISK    EXTFILE(myFile) USROPN

     D myFile          S             21A  

     C                   eval      myFile = 'QGPL/CUSTMAST'
     C                   Open      CustMast

At this point, the file is set to CUSTMAST in QGPL and is open. This could have easily been a file name passed in as a parameter, or retrieved from a data queue, or some other technique.

One last note: The EXTFILE and EXTMBR keywords allow you to specify literals. That is, they allow you to hard-code the file or member names you want to use. If this works for your situation, simply specify the values within quotes in all uppercase and things will work fine. For example, to open the last member in the CUSTMAST file, the following code could be used:

     FCUSTMAST  IF   E           K DISK    EXTMBR('*LAST')

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. He, along with others, speaks at and runs the highly-popular RPG World conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

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: