29
Fri, Nov
0 New Articles

Beware of the Outlaw Logical File

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

We all have done it at one time or another. Our object library option in PDM was not what we thought it was, or our library list was messed up when we went to compile that new logical file. In many cases, we ended up with a job that did not complete normally, and we went on to correct the situation.

But what if the conditions were such that the job did complete normally? The end result would be that we created an "Outlaw Logical" file that resides in a different library from the physical file.

This condition is potentially dangerous for a number of reasons. For instance, error messages come up when a called program is looking for a logical file that is nowhere to be found in the library list. Another problem could be revealed during the save/restore process. If the physical file does not already reside on disk when the system attempts to restore the logical file, the system will give you an error message, and the logical file will not be restored.

What makes this situation alarming is that you may have an outlaw on your system and not even know it. It may be lurking around the next corner waiting to pounce upon some poor unsuspecting end user at the worst possible time.

The good news is that you can do something about it. Think of the utility in this article as your own Wyatt Earp or Matt Dillon. You can use it to sniff out those nasty outlaws and put them back where they belong.

Find Me Some Bad Guys

The Display Displaced Logical Files (DSPDISLF) command (1) may be run over a specific library, a library list, or all libraries on your system. The program will find all outlaw logical files in the libraries specified and bring them up in a subfile display (see 2).

The Display Displaced Logical Files (DSPDISLF) command (Figure 1) may be run over a specific library, a library list, or all libraries on your system. The program will find all outlaw logical files in the libraries specified and bring them up in a subfile display (see Figure 2).

The program DIS001RG (3) will display outlaw logical files, even if the physical files they are over are not in the libraries specified. If the physical file and logical file both meet the designated search criteria, you will see the record listed twice in the subfile (more on this later). 4 (page 94) contains the DDS for the display file DIS001DF.

The program DIS001RG (Figure 3) will display outlaw logical files, even if the physical files they are over are not in the libraries specified. If the physical file and logical file both meet the designated search criteria, you will see the record listed twice in the subfile (more on this later). Figure 4 (page 94) contains the DDS for the display file DIS001DF.

We'll Need a Good Scout

DIS001RG is a simple subfile display program over the system file QADBLDNC. This file is the dependency logical multiple format file over the QADBFDEP file found in library QSYS. The QADBLDNC file is used to define the relationship between all of the physical and logical files on your system.

The QADBLDNC logical file has two formats. One format, QDBFDEP, is keyed by library and physical file. The other format in the file is QDBNC2, which is keyed by library and dependent file. Our program uses both formats depending upon the option selected when running the command.

The command accepts one parameter?library name. Valid values are *ALL, *LIBL, or a library name. If the parameter entered is a library name, the EXIST subroutine in the RPG program will check to ensure the library does, in fact, exist.

The EXIST subroutine uses the QUSR-OBJD API and monitors for an error message. If the library does not exist, the SNDERR subroutine is called to use the QMHSNDPM API to send the error message back to the caller.

If the library does exist, a status message is sent back to the caller's screen stating that the search for outlaws is taking place. This is necessary because, if you take the option to search all libraries on the system, the program may chug away for a minute or two while it reads all records in the file. The program ran in less than one minute on a fully loaded E20 with over 7,000 files filling 4.7GB of DASD.

If the library list option was chosen when running the command, the LIBLST subroutine is executed. LIBLST uses the JOBI0700 format of the QUSRJOBI API to retrieve a variable that contains the library list. This variable is then loaded into the AR work array.

How we determine which libraries are system libraries and which are user production libraries can be confusing, but here goes. Let's start with a refresher course on library lists. A library list contains four types of entries in this order: system libraries, product libraries, current library (maximum one entry), and user libraries.

The system libraries begin in posi-tion 81, and each library entry is 11 characters. Since we want to ignore the system libraries, we use the variable SYS#, which contains the number of system libraries, multiplied by 11 (the size of each library entry), plus 81 to yield the starting position of the product libraries.

The number of product libraries is in PRD#; the number of current libraries is in CUR#; and the number of user libraries is in USR#. These libraries are loaded into array ALIB, and the first element of ALIB is loaded into the LIB field, so only files in the first library will be read the first time through the main loop.

Once the search libraries have been identified, the dependent file is read. Any record in which the physical file's library is different from the dependent file's library is written to the subfile. The subroutine GETCRT uses the OBJD0300 format of the QUSROBJD API to retrieve who created the file and when.

At end of file, if the library list is being searched, the next element of ALIB is used to start the main loop again. This will continue until all of the libraries in the list are searched, at which time the subfile is displayed.

Note that we read the QDBFDEP format (keyed by library and physical file) if the value *ALL or *LIBL is specified and the QDBNC2 format (keyed by library and dependent file) if a single library (or library list) is being searched. This ensures that logicals based on a file in another library will be included in the search along with physical files residing in the search library. Because both the physical and logical files could be encountered in this search, the outlaw logical could appear twice in the subfile.

The only problem we encountered while testing this utility is that occasionally the system file QADBLDNC doesn't track file dependencies properly. This only happens if the physical file and the dependent logical file were created into QTEMP and then moved to other libraries. Since this is apparently a problem with the operating system, we were unable to make this utility work correctly under these conditions. However, this would probably happen only rarely, if ever, so it shouldn't prevent you from making use of this utility.

Should We Hang 'em or

Shoot 'em?

The penalty for creating outlaw logical files can differ by shop, but this article has given you a posse for hunting them down. If you run the DSPDISLF command on a regular basis, you can hunt down the varmints and get them before they get you.

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

Reference

System Programmers Interface Reference (SC41-8223, CD-ROM QBKA8402).


Beware of the Outlaw Logical File

Figure 1: Command DSPDISLF

 /*===============================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/DSPDISLF) PGM(XXX/DIS001RG) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ /*===============================================================*/ CMD PROMPT('Display Displaced Logicals') PARM KWD(LIB) TYPE(*NAME) DFT(*ALL) SPCVAL((*ALL) + (*LIBL)) PROMPT('Library') 
Beware of the Outlaw Logical File

Figure 2: Output from the DSPDISLF Command



Beware of the Outlaw Logical File

Figure 3: RPG Program DIS001RG

 *=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/DIS001RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FDIS001DFCF E WORKSTN F RRN KSFILE SFLRCD FQADBLDNCIF E K DISK E AR 4096 1 E ALIB 50 10 IERROR IDS I B 1 40BYTPRV I B 5 80BYTAVA I 9 15 MSGID I 16 16 ERR### I 17 116 MSGDTA I DS I B 1 40RCVLEN I B 5 80MSGKEY I B 9 120MSGDLN I B 13 160MSGQNB IRCVVAR DS 4096 I B 1 40BYTTOT I B 5 80BYTAVL I B 65 680SYS# I B 69 720PRD# I B 73 760CUR# I B 77 800USR# IRCVVR1 DS 460 I 66 670WHENYR I 68 710WHENMD I 220 229 CRE8BY IFILLIB DS I 1 10 FLIB I 11 20 FSYS I 'No displaced logical-C CONER1 I ' files found in' I 'Searching for displa-C CONMS1 I 'ced logical files' C *ENTRY PLIST C PARM INLIB 10 C 'QCPFMSG' CAT 'QSYS':3 MSGF C Z-ADD116 BYTPRV C MOVE *OFF ERR C MOVE INLIB LIB 10 * Make sure library exists C LIB IFNE '*ALL' C LIB ANDNE'*LIBL' C EXSR EXIST C ENDIF C ERR IFEQ *OFF C Z-ADD50 MSGDLN C MOVELCONMS1 MDATA P C MOVEL'CPF9898' MSGID C MOVEL'*STATUS' MSGTYP C MOVEL'*EXT' MSGQ C Z-ADD0 MSGQNB C EXSR SNDERR C SELEC C LIB WHEQ '*ALL' C *LOVAL SETLLQDBFDEP C LIB WHEQ '*LIBL' C EXSR LIBLST C LIB SETLLQADBLDNC C OTHER C LIB SETLLQADBLDNC C ENDSL C *IN41 DOUEQ*ON C LIB IFEQ '*ALL' C LIB OREQ '*LIBL' C READ QDBFDEP 41 C ELSE C LIB READEQADBLDNC 41 C ENDIF C *IN41 IFEQ *OFF C DBFLIB IFNE DBFLDP C EXSR GETCRT C Z-ADD0 WHEN C MOVELWHENMD WHEN C MOVE WHENYR WHEN C ADD 1 RRN 40 C WRITESFLRCD C ENDIF C ELSE C INLIB IFEQ '*LIBL' C ADD 1 I C ALIB,I IFNE *BLANKS C MOVEAALIB,I LIB C LIB SETLLQADBLDNC C MOVE *OFF *IN41 C ENDIF C ENDIF C ENDIF C ENDDO * C RRN IFNE *ZEROS C MOVE *ON *IN21 C WRITEFKEYS C EXFMTSFLCTL C ELSE * No libraries found with displaced logical files C Z-ADD50 MSGDLN C MOVELCONER1 MDATA P C MDATA CAT LIB:1 MDATA C MOVEL'CPF9898' MSGID C MOVEL'*DIAG ' MSGTYP C MOVEL'* ' MSGQ C Z-ADD1 MSGQNB C EXSR SNDERR C ENDIF C ENDIF C MOVE *ON *INLR *=============================================================== C GETCRT BEGSR *=============================================================== * Get who created logical file and when C MOVELDBFFDP FILLIB 20 C MOVELDBFLDP FSYS C CALL 'QUSROBJD' C PARM RCVVR1 C PARM 460 RCVLEN C PARM 'OBJD0300'FILFMT 8 C PARM FILLIB C PARM '*FILE' OBJTYP 10 C PARM ERROR C ENDSR *=============================================================== C EXIST BEGSR *=============================================================== * Make sure requested library exists C MOVELLIB FILLIB 20 C MOVEL'QSYS' FSYS C CALL 'QUSROBJD' C PARM RCVVAR C PARM 5000 RCVLEN C PARM 'OBJD0100'FILFMT 8 C PARM FILLIB C PARM '*LIB' OBJTYP C PARM ERROR C MSGID IFNE *BLANKS C Z-ADD50 MSGDLN C MOVELLIB MDATA C MOVEL'*ESCAPE' MSGTYP C MOVEL'* ' MSGQ C Z-ADD1 MSGQNB C EXSR SNDERR C ENDIF C ENDSR *=============================================================== C SNDERR BEGSR *=============================================================== * Send error back to caller C CALL 'QMHSNDPM' C PARM MSGID C PARM MSGF 20 C PARM MDATA 50 C PARM MSGDLN C PARM MSGTYP 10 C PARM MSGQ 10 C PARM MSGQNB C PARM MSGKEY C PARM ERROR C MOVE *ON ERR 1 C ENDSR *=============================================================== C LIBLST BEGSR *=============================================================== * Get library list C CALL 'QUSRJOBI' C PARM RCVVAR C PARM 5000 RCVLEN C PARM 'JOBI0700'FILFMT 8 C PARM '*' JOBNAM 26 C PARM INTJOB 16 C MOVEARCVVAR AR,1 C SYS# MULT 11 I 40 C ADD 81 I C Z-ADD1 J 40 C DO PRD# C MOVEAAR,I ALIB,J C ADD 1 J C ADD 11 I C ENDDO C DO CUR# C MOVEAAR,I ALIB,J C ADD 1 J C ADD 11 I C ENDDO C DO USR# C MOVEAAR,I ALIB,J C ADD 1 J C ADD 11 I C ENDDO C MOVEAALIB,1 LIB C Z-ADD1 I C ENDSR *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
Beware of the Outlaw Logical File

Figure 4: Display File DIS001DF

 *=============================================================== * To compile: * * CRTDSPF FILE(XXX/DIS001DF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A PRINT A CA03(03 'Exit') A CA12(12 'Cancel') A R SFLRCD SFL A DBFFIL 10A O 4 5 A DBFLIB 10A O 4 18 A DBFFDP 10A O 4 31 A DBFLDP 10A O 4 44 A CRE8BY 10A O 4 57 A WHEN 6Y 0O 4 70EDTCDE(Y) A R SFLCTL SFLCTL(SFLRCD) A SFLSIZ(0032) A SFLPAG(0016) A OVERLAY A 21 SFLDSP A SFLDSPCTL A 41 SFLEND(*MORE) A 1 25'Display Displaced' A DSPATR(HI) A 1 43'Logical Files' A DSPATR(HI) A 3 5'Physical' A DSPATR(HI) A 3 18'Library' A DSPATR(HI) A 3 31'Logical' A DSPATR(HI) A 3 44'Library' A DSPATR(HI) A 3 57'Created By' A DSPATR(HI) A 3 70'Created On' A DSPATR(HI) A R FKEYS A 22 6'F3=Exit' A COLOR(BLU) A 22 17'F12=Cancel' A COLOR(BLU) *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • 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.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • 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

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

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