This post is inspired by a situation that I encountered a couple of weeks ago that left me flabbergasted. It started with a phone call from a department head complaining that another department was eating into his department's time to run a report. At first I was confused, and after talking to three department heads I discovered that each one has a time they can run this report. Department A can run the report with any selection criteria they desire from 8:00 – 8:59 AM, Department B can do the same from 9:00 – 9:59 AM, and Department C from 10:00 – 10:59 AM. Anyone can run the report in the afternoon, but only after calling the other departments to make sure they are not running the report at the same time.
Why was this an issue? In this job the programmer who had created it used a work file that was in a production library. Therefore, only one person could run the report at a time to ensure that only one department's data was included in the report. If two people ran the report at the same time the work file could contain mixed data from both jobs. I also found that when the job completed the work file was not cleared, still containing all of the data from the last run, wasting disk space.
The programmer who created these programs has retired so I was not able to ask the question I wanted to: Why?
Looking at library list for the jobs from this application I found that QTEMP was in the library below all of the production libraries. Could this be the reason why?
Never mind the why, the solution was simple. In the job just before the work file was needed I would copy it into QTEMP, and use it there. I could have used a OVRDBF to ensure that the job would know which file to use, but I thought another approach would be easier for other programmers to quickly understand which file was being used: adding the EXTFILE keyword to the file definition in the File Definition specifications. I have discussed this approach in an earlier post, Useful keywords for your F-specs, but I will be repeating parts of it here and giving examples using the free DCL-F too.
I create two work files using the CRTDUPOBJ command, from the same original file:
CRTDUPOBJ OBJ(TESTFILE) FROMLIB(*LIBL) OBJTYPE(*FILE) + TOLIB(QTEMP) NEWOBJ(TESTFILE1) CST(*NO) + TRG(*NO) CRTDUPOBJ OBJ(TESTFILE) FROMLIB(*LIBL) OBJTYPE(*FILE) + TOLIB(QTEMP) NEWOBJ(TESTFILE2) CST(*NO) + TRG(*NO)
In the example below I have defined in which library to find the files using the EXTFILE. The EXTDESC is only used at compile time. It gives where to find the description for the files, as all the files are based on the same file they all contain the same name. I use this so I do not have to create any files in QTEMP before compiling this program/procedure. The RENAME is needed as the record format name is the same in both the input and output files.
FTESTFILE1 IF E K DISK extfile('QTEMP/TESTFILE1') F extdesc('TESTFILE') F rename(TESTFILER:INPUT) FTESTFILE2 O E DISK extfile('QTEMP/TESTFILE2') F extdesc('TESTFILE') F rename(TESTFILER:OUTPUT) dcl-f TESTFILE1 keyed extfile('QTEMP/TESTFILE') extdesc('TESTFILE') rename(TESTFILER:INPUT) ; dcl-f TESTFILE2 usage(*output) extfile('QTEMP/TESTFILE') extdesc('TESTFILE') rename(TESTFILER:OUTPUT) ;
Personally I think it is easier for another programmer to see where each file is used from. And if the same program is called by multiple jobs it prevents the problem of a program missing an OVRDBF and using the wrong file.
The EXTFILE can be used with any file type. I have a suite of programs where I have used the EXTFILE with all data, display, and printer files, therefore, the programs can be called without having to be in the users' library list.
FDISPLAYF CF E WORKSTN extfile('MYLIB/DISPLAYF') FPRINTERF O E PRINTER extfile('MYLIB/PRINTERF') dcl-f DISPLAYF workstn extfile('MYLIB/DISPLAYF') ; dcl-f PRINTERF printer extfile('MYLIB/PRINTERF') ;
I went through all the programs in that library and all of the report programs that did not copy use work files in QTEMP have now been changed to use this method, and now any department can run the report when they want.
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.