Object Reference Utility

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

Brief: Because every programming change has the potential to cause unexpected problems, fear of change is something every programmer lives with. Using the utility in this article, you can find the relationships between objects.

Programmers are not particularly close-minded or staunchly traditional. But experience has taught them that changing a file or data area can often have an unintended and detrimental effect elsewhere.

These unwelcome surprises have led to the popularity of change-management systems. The tools continue to become more important as AS/400s grow increasingly complex.

The down side is that many organizations have a small MIS budget, and a pricey change-management system can be a tough sell.

The following utility offers one of the best features of change management without the big price tag. The object reference utility presented here gives you access to information about where an object is used and allows you to determine how an object interacts with the rest of the system. The utility is made up of the Create Object Reference (CRTOBJREF) and Display Object Reference (DSPOBJREF) commands.

The CRTOBJREF command creates an object reference file for a specified library, and the DSPOBJREF command displays the object references. 1 illustrates the display presented by the DSPOBJREF command for ITEM01PF physical file. This subfile display essentially tells you what programs use the object; and if the object is a file, its usage is shown (e.g., update, input, or output).

The CRTOBJREF command creates an object reference file for a specified library, and the DSPOBJREF command displays the object references. Figure 1 illustrates the display presented by the DSPOBJREF command for ITEM01PF physical file. This subfile display essentially tells you what programs use the object; and if the object is a file, its usage is shown (e.g., update, input, or output).

How to Use It

Before you can display an object's references, you must create an object reference file for a given library with the CRTOBJREF command. CRTOBJREF accepts three parameters: the reference library, the library that is to contain the OBJRFPF output file, and an option to add records to or replace records in the output file. If you need to find references across multiple libraries, you must execute the CRTOBJREF command for each library with the add records (*ADD) option.

To display an object's references, use the DSPOBJREF command. Key the name of an object (program, file, or data area) in the first parameter and the library that contains the OBJRFPF file in the second parameter.

How It Works

The file containing the program references is called OBJRFPF (see 2). It is created in the library you designate when you run the CRTOBJREF command (see 3). The file is created by the CPP for the CRTOBJREF command, OBJ012CL (see 4). CRTOBJREF uses a master copy of OBJRFPF, which resides in the same library that contains the object reference utility. OBJ012CL will, if necessary, build the OBJRFPF file in the designated library.

The file containing the program references is called OBJRFPF (see Figure 2). It is created in the library you designate when you run the CRTOBJREF command (see Figure 3). The file is created by the CPP for the CRTOBJREF command, OBJ012CL (see Figure 4). CRTOBJREF uses a master copy of OBJRFPF, which resides in the same library that contains the object reference utility. OBJ012CL will, if necessary, build the OBJRFPF file in the designated library.

A monitor message command checks for a condition in which no object references another object in the designated library. For instance, this condition would exist if you ran the command over a library that contains nothing but files. Other error handling was removed to shorten the code so that it could be printed with this article.

The OBJRFPF file is automatically rebuilt if you told the command to replace the file. The file is not cleared each time, so you can build a reference file over more than one library. For instance, you create a file over all libraries that make up your accounting system. OBJ012CL then calls the OBJ012RG program (see 5), which reads the PGMREFO work file and writes the cross- reference records to the OBJRFPF file.

The OBJRFPF file is automatically rebuilt if you told the command to replace the file. The file is not cleared each time, so you can build a reference file over more than one library. For instance, you create a file over all libraries that make up your accounting system. OBJ012CL then calls the OBJ012RG program (see Figure 5), which reads the PGMREFO work file and writes the cross- reference records to the OBJRFPF file.

Displaying the Reference File

The DSPOBJREF command (see 6) displays the records from the OBJRFPF file using a subfile defined in display file OBJ013DF (see 7). RPG program OBJ013RG (see 8, page 52) reads the OBJRFPF file and loads the records into the subfile. The OBJ013RG program accepts parameters for the object name and the library name that contains the OBJRFPF file. Since the DSPPGMREF command does not accept more than one library name, you must call this command for each library in the search.

The DSPOBJREF command (see Figure 6) displays the records from the OBJRFPF file using a subfile defined in display file OBJ013DF (see Figure 7). RPG program OBJ013RG (see Figure 8, page 52) reads the OBJRFPF file and loads the records into the subfile. The OBJ013RG program accepts parameters for the object name and the library name that contains the OBJRFPF file. Since the DSPPGMREF command does not accept more than one library name, you must call this command for each library in the search.

Let's examine the RPG code. First, it overrides the OBJRFPF file to the correct library and opens the file. Next, it sets lower limits in the OBJRFPF file with the object name. The load subfile (LODSFL) subroutine is called to load the subfile.

The LODSFL subroutine sets up a loop that causes all records to be read from the OBJRFPF file. The code within this loop ensures that if there are multiple references to an object within the same source member, only one record is written to the subfile. You may prefer to remove this code and include all references in the subfile depending upon your needs. Another option you may want to consider is to count the references and add a field to the subfile record. In any case, the subfile fields are loaded up. If the object is a file, the code converts the file usage field into a description, and the subfile record is then written.

After the subfile is loaded, the main processing loop is entered and continues until F3 or F12 is pressed (indicator 03 is on).

Make Mine Cajun, Please

The utility in this article has been reduced to fit within the confines of the standards of this publication. You can really spice it up by adding the following functions.

The subfile can be modified to bring source members up in SEU. You can do this by including a CL program that will run the Display Object Description (DSPOBJD) command to an outfile to get the source library and file names and then initiating the SEU command for the selected member.

More importantly, you can add the ability to include all logical references to a physical file when searching for object references. To do this, modify the OBJ013RG program to call a CL program that executes a Display Data Base Relations (DSPDBR) command to an outfile for physical file object references. You will then need to open the outfile as a user-controlled file within the RPG program. Read the outfile records and include them when writing the subfile records.

The net result would be that all references to the physical file, even those made using a logical file, would be displayed.

Disclaimer and Limitations

Like most utilities, this tool has limitations. Only files (all types), programs, and data area object references in RPG and CL programs are included. For COBOL programs, only files and literal program names on the CALL command are referenced. (Object references in other program languages are limited. See the help text for DSPPGMREF for more information.) Fortunately, this list covers almost all objects that would include references to others within the system.

The referenced object names and libraries used in this tool may not reflect the actual names of the objects, since the information is stored when the programs were compiled. If overrides were in effect during the compile or objects were moved, the results may not be accurate.

Security can also be a problem if you do not have *USE rights for the programs and libraries being searched. Refer to the Display Program References (DSPPGMREF) command in the CL Reference manual if you think that this problem may affect you.

A Tool for All Seasons

You will find that this tool can save valuable time when you have to change a file, data area, or program. Knowing that you reviewed all of the associated source members when you modify an object can offer a little peace of mind to an otherwise traumatic experience.

Doug Pence is the founder and Ron Hawkins is the research and development manager of Computing Processing Unlimited, Inc. in San Diego, California.


Object Reference Utility

Figure 1 The DSPOBJREF Display

 UNABLE TO REPRODUCE GRAPHICS 
Object Reference Utility

Figure 2 OBJRFPF Physical File

 *=============================================================== * To compile: * * CRTPF FILE(QGPL/OBJREFPF) SRCFILE(XXX/QDDSSRC) + * SIZE(*NOMAX) *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A R OBJREC A OBJNAM 10 COLHDG('OBJECT NAME') A OBJLIB 10 COLHDG('OBJECT LIBRARY') A OBJTXT 40 COLHDG('OBJECT TEXT') A OBRNAM 10 COLHDG('REFERENCED OBJECT') A OBRLIB 10 COLHDG('REFERENCED LIBRARY') A OBRTYP 10 COLHDG('REFERENCED TYPE') A OBRUSE 2 COLHDG('FILE USAGE') A K OBRNAM A K OBRLIB A K OBJNAM A K OBJLIB 
Object Reference Utility

Figure 3 The CRTOBJREF Command Definition

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/CRTOBJREF) PGM(XXX/OBJ012CL) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ /*==================================================================*/ CRTOBJREF: CMD PROMPT('Create Object Reference') PARM KWD(REFLIB) TYPE(*NAME) LEN(10) MIN(1) + PROMPT('Reference library') PARM KWD(LIB) TYPE(*NAME) LEN(10) MIN(1) + PROMPT('Output file (OBJRFPF) library') PARM KWD(OPTION) TYPE(*CHAR) LEN(8) RSTD(*YES) + DFT(*ADD) VALUES(*ADD *REPLACE) MIN(0) + PROMPT('Add or replace records') 
Object Reference Utility

Figure 4 CL Program OBJ012CL, CPP for CRTOBJREF Command

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/OBJ012CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ OBJ012CL: + PGM PARM(&LIBRARY &REFLIB &OPTION) DCL VAR(&LIB) TYPE(*CHAR) LEN(10) DCL VAR(&LIBRARY) TYPE(*CHAR) LEN(10) DCL VAR(&OPTION) TYPE(*CHAR) LEN(8) DCL VAR(&REFLIB) TYPE(*CHAR) LEN(10) DSPPGMREF PGM(&LIBRARY/*ALL) OUTPUT(*OUTFILE) + OUTFILE(QTEMP/PGMREFO) OUTMBR(*FIRST) MONMSG MSGID(CPF3033) EXEC(GOTO CMDLBL(ENDPGM)) /* No references */ CHKOBJ OBJ(&REFLIB/OBJRFPF) OBJTYPE(*FILE) MONMSG MSGID(CPF9801) EXEC(DO) RTVOBJD OBJ(OBJRFPF) OBJTYPE(*FILE) RTNLIB(&LIB) CRTDUPOBJ OBJ(OBJRFPF) FROMLIB(&LIB) OBJTYPE(*FILE) + TOLIB(&REFLIB) ENDDO OVRDBF FILE(OBJRFPF) TOFILE(&REFLIB/OBJRFPF) OVRDBF FILE(PGMREFO) TOFILE(QTEMP/PGMREFO) IF COND(&OPTION *EQ '*REPLACE') THEN(DO) CLRPFM FILE(&REFLIB/OBJRFPF) ENDDO CALL PGM(OBJ012RG) /* Write to permanent file */ DLTOVR FILE(PGMREFO) DLTOVR FILE(OBJRFPF) ENDPGM: + ENDPGM 
Object Reference Utility

Figure 5 RPG Program OBJ012RG

 *=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/OBJ012RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FPGMREFO IF E DISK FOBJRFPF O E DISK C 1 SETLLPGMREFO C *IN50 DOUEQ*ON C READ PGMREFO 50 C *IN50 IFEQ *OFF C MOVELWHLIB OBJLIB C MOVELWHPNAM OBJNAM C MOVELWHTEXT OBJTXT C MOVELWHFNAM OBRNAM C MOVELWHLNAM OBRLIB C MOVELWHFUSG OBRUSE C MOVELWHOTYP OBRTYP C WRITEOBJREC C ENDIF C ENDDO C SETON LR 
Object Reference Utility

Figure 6 DSPOBJREF Command Definition

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/DSPOBJREF) PGM(XXX/OBJ013RG) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ /*==================================================================*/ DPSOBJREF: CMD PROMPT('Display Object Reference') PARM KWD(NAME) TYPE(*NAME) MIN(1) PROMPT('Object + name') PARM KWD(LIB) TYPE(*NAME) PROMPT('OBJRFPF library') 
Object Reference Utility

Figure 7 Display File OBJ013DF

 *=============================================================== * To compile: * * CRTDSPF FILE(XXX/OBJ013DF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A PRINT A CA03(03) A CA12(03) A R SFLRCD SFL A 40 SFLNXTCHG A DOBJNM 10A O 7 3 A DOBJLB 10A O 7 15 A DOBJTX 38A O 7 27 A DUSEDS 7A O 7 67 A R SFLCTL SFLCTL(SFLRCD) A CHGINPDFT A SFLSIZ(0026) A SFLPAG(0014) A OVERLAY A 21 SFLDSP A SFLDSPCTL A 51 SFLEND(*MORE) A UDATE 6Y 0O 1 2EDTCDE(Y) A DSPATR(HI) A WSID 10A O 1 70DSPATR(HI) A 1 29'Object Reference Screen' A DSPATR(HI) A 21 3 3'Object name . . .' A 21 OBJ 10A O 3 22 A 21 4 3'OBJRFPF library .' A 21 RFFLIB 10A O 4 22 A N21 ERROR 50A O 4 3DSPATR(HI) A 21 6 3'Name' A DSPATR(HI) A 21 6 15'Library' A DSPATR(HI) A 21 6 27'Text' A DSPATR(HI) A 21 6 67'Usage' A DSPATR(HI) A R FOOTER A 22 2'F3=Exit' A COLOR(BLU) A 22 12'F12=Cancel' A COLOR(BLU) 
Object Reference Utility

Figure 8 RPG Program OBJ013RG

 *=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/OBJ013RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FOBJ013DFCF E WORKSTN F RRN KSFILE SFLRCD F KINFDS INFO FOBJRFPF IF E K DISK UC IINFO DS I 197 206 WSID I B 378 3790FSTL I 'OVRDBF FILE(OBJRFPF)-C OVR I ' TOFILE(' I '/OBJRFPF)' C FILENM I 'No references exist -C NOREF I 'for this object.' * C *ENTRY PLIST C PARM OBJ 10 C PARM RFFLIB 10 C MOVELOVR CMD P C CAT RFFLIB:0 CMD C CAT FILENM:0 CMD C CALL 'QCMDEXC' 50 C PARM CMD 50 C PARM 50 LEN 155 C OPEN OBJRFPF 50 C OBJ SETLLOBJRFPF C EXSR LODSFL C RRN IFGT *ZEROS C SETON 21 C ELSE C MOVE NOREF ERROR C SETON 03 C ENDIF C *IN03 DOUEQ*ON C WRITEFOOTER C EXFMTSFLCTL C ENDDO * C SETON LR * *================================================================ C LODSFL BEGSR *================================================================ C *IN51 DOUEQ*ON C OBJ READEOBJRFPF 51 C *IN51 IFEQ *OFF * * If object referenced more than once in same program, only want IT * shown once. * C MOVELOBJLIB F20 20 C MOVE OBJNAM F20 C F20 IFNE DUPES C MOVE F20 DUPES 20 * C MOVE OBJNAM DOBJNM C MOVE OBJLIB DOBJLB C MOVELOBJTXT DOBJTX C MOVE *BLANKS DUSEDS C OBRTYP IFEQ '*FILE' C MOVEL'UNKNOWN' DUSEDS P C SELEC C OBRUSE WHEQ '01' C MOVEL'INPUT' DUSEDS P C OBRUSE WHEQ '02' C MOVEL'OUTPUT' DUSEDS P C OBRUSE WHEQ '03' C MOVEL'WRKSTN' DUSEDS P C OBRUSE WHEQ '04' C MOVEL'UPDATE' DUSEDS P C OBRUSE WHEQ '06' C MOVEL'UPD/ADD' DUSEDS P C OBRUSE WHEQ '09' C OBRUSE OREQ '11' C MOVEL'DEL/CRT' DUSEDS P C ENDSL C ENDIF C ADD 1 RRN 40 C WRITESFLRCD C ENDIF C ENDIF C ENDDO C ENDSR * *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
BLOG COMMENTS POWERED BY DISQUS