No matter how well you plan the design of a database file, it will eventually need to be changed. When a file is changed, all the programs using the file need to be re-compiled. If this is not done, then while executing the program, you will get a level check error (CPF4131).
To avoid this, either the (i) file needs to be compiled with Level Check (*NO) or (ii) the programs using the file need to be re-compiled. The first solution is very simple since you just need to set Level Check as *NO while compiling the file.
If you need to maintain the data integrity, then it's better to re-compile all the programs that are using the particular file(s).
If you choose to use the second method, the first thing you must know is all the programs that are using the particular file(s). One way of finding this out is to check the sources of all the programs for the particular file. This will be an easy task if you have only one library where the sources of all the programs are present.
But if the sources are spread across different libraries and there are lots of libraries present, then it will be a tedious task to find all the programs that are using the file(s) and there are always possibilities that one or more programs might get missed out.
In order to overcome the above problem, iSeries provides us with the DSPPGMREF command. This command provides us with the list of the objects used by a specified program. Use this command and then take F4.
Type choices and press Enter.
Program . . . . . . . . . . . . > *ALL Name, generic*, *ALL Library . . . . . . . . . . . > *ALLUSR Name, *LIBL, *CURLIB... Output . . . . . . . . . . . . . > *OUTFILE *, *PRINT, *OUTFILE Object type . . . . . . . . . . > *ALL *ALL, *PGM, *SQLPKG... + for more values File to receive output . . . . . Name Library . . . . . . . . . . . *LIBL Name, *LIBL, *CURLIB Output member options: Member to receive output . . . *FIRST Name, *FIRST Replace or add records . . . . *REPLACE *REPLACE, *ADD
Enter the values as given above and in the File to receive output Field, give the name of the physical file to be created and in the Library, give the name of the library where it should reside and press Enter.
This creates an outfile in the library mentioned (Lets say the outfile is DSPOUTPUT created in the library QGPL).
Now, run a query on this file with the following selection criteria and press Enter.
WHFNAM EQ 'Filename'
Where the 'Filename' was will be the physical, logical or the display file that needs to be delivered.
The output of this query shows all the programs that are using the particular file. This helps you to determine all the programs that are using the particular file and then you can re-compile the programs accordingly.
This outfile also contains the information regarding the mode in which the file is opened. This can be obtained with the WHFUSG field.
This outfile is not only used for finding the programs that are using a particular file(s), but also the programs that are calling a particular program. Example, if you want to find out all the programs that are calling a particular program (lets say program ABC), then just give the following selection criteria.
WHFNAM EQ 'ABC'
The output of this query will show all the programs that are calling program 'ABC'.
The time taken for the creation of the outfile depends upon the number of user libraries present in the iSeries server.