Sidebar

Use a Logical File Layer to Minimize Recompiles from Field Additions

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

 

When you add a field to a file, you do not have to recompile all programs that access the data.

By Sam Lennon

Traditionally, if you add a field to a physical file, you have to recompile all programs that use that physical file definition. Generally, you also need to recompile all programs that use logical files over the physical. But with some planning, you can avoid many of these recompiles, thereby shortening and simplifying the installation. And without level checks.

 

Perhaps you're in the position where you need to add a field to a heavily used file, one that has been around for years. You know many programs reference this file. You could create a new file with the same key to hold just the new data, but this is a high-activity file, and you know that, for performance, the right thing to do is to add the field to the existing file. So you bite the bullet, crank up your favorite cross-reference tool (if you have one), and are horrified to find that on top of the 13 programs you need to modify to use the new field, and the three you need to write, you are also going to have to recompile 317 programs and re-create 64 queries. There may even be some non-iSeries uses that you don't know about. (While these numbers are fictional, I have experienced such a project.)

 

Even if you have a smart change-management system that will automatically recompile the programs for you, the installation will take longer and have a higher level of risk. IT management, correctly, likes to minimize risk.

 

If you are in a situation like this, which may not be of your making, it is because the programs and queries are closely dependent on the physical data layout. To solve the problem, or to avoid it in new applications, the view of the data the program sees needs to be divorced from the physical file layout.

 

Logical files, used correctly, can add a layer of abstraction that helps minimize recompiles. Once in place, a logical file layer means that when you add a new field, the only existing programs or queries that need to be touched are those that will actually use the new field.

Why Are Recompiles Needed?

Everyone knows the answer: to avoid level checks.

 

Each record format in an externally defined file has a format level identifier. When an RPG or COBOL program uses a format, the compiler saves the current format level identifier in the program. When the program runs and the file is opened, the system checks the format level identifier of the file against the format level identifier the compiler saved at compile time and, if they are different, sends a CPF4131 escape message (the dreaded level check) to the program. Similar processing occurs with Query/400 query definitions. You can suppress runtime level checking and thus avoid level checks, but doing so is generally considered a bad practice, so the solution for a level check is to recompile the program or open and save the query definition.

The Crux of the Problem

The way we create logical files is the main reason we need to re-create programs and query definitions. When coding the DDS for a logical file, all the fields of the physical file are automatically included if you don't code any field names. This is the quickest and easiest way to define a logical file. So if your physical file is named ORDLINP and is coded like this...

 

A               R ORDLINF

A                 ORDNUM         7P 0

A                 ORDLIN         3P 0

A                 SKU           11P 0

A                 QTYORD         5P 0

A                 QTYRCV         5P 0

A                 LASTRCV         L

 

...then in most cases, the logical file, ORDLIN01, is coded like this:

 

A                                           UNIQUE

A               R ORDLINF                   PFILE(ORDLINP)

A               K ORDNUM

A               K ORDLIN

 

All the fields of ORDLINP are copied into ORDLIN01, and the two files are tightly coupled. If you add a field to ORDLINP, you have to re-create it, which you can do in one of two ways:

  • By deleting ORDLIN01, saving the ORDLINP data, recompiling ORDLINP, copying the data back, and finally re-creating ORDLIN01
  • By using CHGPF and specifying the new DDS

 

Either way, ORDLIN01 gets a new format level identifier, so you must re-create all programs or query definitions that reference ORDLIN01 as well as those that reference ORDLINP.

A Better Way

Minimizing recompiles and object re-creation depends on a few rules that require a small amount of up-front work and a significant commitment to follow the rules. Here they are, with the reasoning behind each rule.

 

Rule #1: When you code a logical file, always explicitly list the fields. This is the little bit of extra work that is needed up front and is the most tempting rule to ignore. ORDLIN01 would be correctly coded like this:

 

A                                           UNIQUE

A               R ORDLINF                   PFILE(ORDLINP)

A                 ORDNUM

A                 ORDLIN

A                 SKU

A                 QTYORD

A                 QTYRCV

A                 LASTRCV

A               K ORDNUM

A               K ORDLIN

 

 

Now if we add a field to the physical file, we have the option of not adding that field to existing logicals. Unchanged logicals will not get a new format level identifier and thus won't cause level checks.

 

Rule #2: Do not reference the physical file anywhere. Instead, always use a logical, including in applications that write new records to the file. This ensures that no application is dependent on the physical file definition. In fact, you can add a field to the physical without re-creating any objects.  (Kent Milligan of IBM says "The one case that is not recommended is on SQL statements since that will force the usage of CQE (Classic Query Engine) instead of SQE.  In that case, the SQL statement should reference the PF directly or they should consider creating an SQL view.")

 

Rule #3: When using embedded SQL, do not use the "SELECT * FROM ..." construct, where "*" means all fields. Instead, specify the fields you need explicitly, even if you are using all the fields. This will make the application not only independent of field additions to the physical file, but also independent of field additions to the logical file (unless, of course, the application needs the new field; in that case, you will have to re-create the application anyway). Selecting only the fields you need is also more efficient.

 

Rule #4: Do not code any keys on the physical file. This encourages enforcement of rule #2, since traditional IO nearly always uses a key. (Note that SQL will happily accept the physical file, keyed or not. This is not a problem, but it will likely generate "noise" in your research and your cross-reference tool.)

 

Rule #5: When you add a new field to the physical file, consider specifying a default value for new date, time, and timestamp fields. Remember: all existing programs that add data records will be doing so through a logical (rule #2) and will not reference your new field, so the default value will be used. Unless coded otherwise in the DDS, these field values default to the current date and time, which is likely to cause confusion. Ideally, you would specify DFT(*NULL), but this might not play well with older code, so something like DFT('0001-01-01') for date fields, DFT('00.00.00') for time fields, or DFT('0001-01-01-00.00.00.000000) for timestamp fields may be more suitable.

Example: Logical File Layer Exists

Let's see how it works. Suppose the ORDLINP file (DDS above) exists and was created about 15 years ago. A user department manager has asked that, when an order is delayed, we keep a status of the reason it was delayed and the date the delay occurred. The delay status is to be a single-character field, where a blank means no delay has occurred and anything else is a delay reason code. The support manager signs off on the change request since it looks easy. (Bear in mind this is a contrived file that would have many more fields in real life.)

 

You are assigned to make the change, and you find there are 330 programs and 64 query definitions that reference the file. Re-creating nearly 400 objects could make for a long and risky install. There are 23 logicals over ORDLINP, but fortunately, the logical file layer is in place and no objects directly reference the physical file.

 

The new ORDLINP will look like this, with fields DELAYSTS and DELAYDATE added at the end:

 

A               R ORDLINF

A                 ORDNUM         7P 0

A                 ORDLIN         3P 0

A                 SKU           11P 0

A                 QTYORD         5P 0

A                 QTYRCV         5P 0

A                 LASTRCV         L

A                 DELAYSTS       1

A                 DELAYDTE        L         DFT('0001-01-01')

 

 

After your analysis, you know you need to write two new programs to maintain the two new delay fields. Both will access the data using SKU and LASTRCV as the key. There are two existing logicals with these fields as the key. You also need to change three existing programs, all of which access the file by ORDNUM and ORDLIN, and there are several logicals with this key.

 

This means that just two logical files will need to contain the new fields. The trick is making the decision: do you want to change an existing logical or add another logical?

 

Consider the two new programs first. Suppose ORDLIN01 has the correct key (SKU and LASTRCV) for the new programs, and 17 programs and 5 queries already use it. ORDLIN05 also has the right key plus a couple of additional non-key fields, and 45 programs and 8 queries use it. You have several choices:

  • Add the new fields to ORDLIN01 and re-create the 17 programs and 3 queries that use it. This seems reasonable, if ORDLIN01 has all the fields that will be required for the logic of the two maintenance programs explicitly coded in the DDS. You will also need to make sure there are no collisions between the new field names and existing variable names in the 17 programs you will have to recompile,
  • It is likely that ORDLIN05 may be newer and will have more fields explicitly coded, so it might be a better choice to change, but the downside is the re-creation of the 45 programs and 8 queries.
  • Create another logical, ORDLIN24, with the needed fields and keyed by SKU and LASTRCV. The downside is there will be another object on the system, but there should be no space or runtime overhead for this new logical because it will share the access path of either ORDLIN01 or ORDLIN05. The upside is that you won't have to change an existing logical and re-create its dependent objects.

 

The third choice is the quickest install with the least risk.

 

You will need to go through a similar exercise for the three existing programs that need to be changed. Find which logicals they use, see how many other programs and queries use those logicals, and weigh the cost, risk, and effort of recompiling those programs against creating another logical.

 

Whichever choice you make, it will be a quicker and safer installation than having to re-create almost 400 objects.

Example: No Logical File Layer Exists

What do you do if no logical file layer exists and you have to make the same change as the previous example, but you want a shorter, less-risky install than one that involves 400+ objects?  The good news is that you can do it incrementally and have a logical file layer in place when you're finished. I am a fan of incremental installs, where possible.

 

The first step is to get rid of all references to the physical file. Create a logical that explicitly defines all the fields in the physical, with the same keys if the physical is keyed. Then change all the references to the physical to use the new logical. You can do this one object at a time or in  groups sized to your comfort level.

 

Next, one at a time, change each logical to explicitly define all fields. This coding is simple, largely cut and paste. The file format level should not change, and you can easily check this using the DSPFD command. Existing programs and queries should not notice that the file has changed, but run a simple regression test if you're nervous.

 

Alternatively, you can make the change to each logical even more granular. One logical at a time, create a new logical with explicitly defined fields and the same keys. The new logical should share the access path of the original, so there should be no system overhead. Then, one by one, change dependent programs and queries to use the new logical. After some time in production, the old logical should show no use and can be deleted. Be aware that when you do the delete, an index build will probably be triggered on the new logical, which up to that point had been sharing the access path of the old logical.

 

Now you have a logical file layer in place and can proceed accordingly.

Conclusion

By making all references to your data through logical files, you can add fields to your physical database without having to re-create programs or queries. This makes for a shorter install that is less risky. Remember, management likes to minimize risk.

Notes

PF-38 or LF-38 Files: Be cautious if you have PF-38 or LF-38 files that were created a long time ago. There was a period when the logic to create the format level identifier on System/38 files was incorrect. Simply re-creating such a file with the same DDS today generates a new, correct format level identifier value. A colleague and I identified this issue with IBM several years ago, but there is no fix, and there probably can't be, since the old IBM code had a bug. We had no choice but to re-create the programs that used the file.

 

If you have any doubts, use DSPFD to check the file format identifier in the old and new versions of the file. You are looking for a column something like this bolded text:

 

Record Format List                         

                       Record  Format Level

 Format       Fields   Length  Identifier  

 ORDLINF           6       28  2B1E6E5BB3280

 

Alternatively, you can run DSPFD to an outfile, like this:

 

DSPFD FILE(yourfile) TYPE(*RCDFMT) OUTPUT(*OUTFILE) OUTFILE(QTEMP/somefile)

 

You will find the format level identifier in field RFID.

 

Shared Access Paths: When talking about an additional logical file sharing an access path with an existing logical, I have used the word "should." There are occasional situations where logical file sharing may not take place. Run a DSPFD on the new logical; if it is shared, you should see output like this:

 

Implicit access path sharing  . . . . . :            Yes             

  Access path journaled . . . . . . . . :            No              

Number of unique partial key values . . :                            

  Key field 1 . . . . . . . . . . . . . :                          2 

  Key fields 1 - 2  . . . . . . . . . . :                          7 

File owning access path . . . . . . . . :            LENNONS1/ORDLINL

 

If it isn't shared, consult the IBM documentation on "Using existing access paths." You can find the V5R3 Info Center documentation at this link.

 

 

Sam Lennon

Sam Lennon is an analyst, developer, consultant and IBM i geek. He started his programming career in 360 assembly language on IBM mainframes, but moved to the AS400 platform in 1991 and has been an AS400/iSeries/i5/IBM i advocate ever since.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

RESOURCE CENTER

  • WHITE PAPERS

  • WEBCAST

  • TRIAL SOFTWARE

  • White Paper: Node.js for Enterprise IBM i Modernization

    SB Profound WP 5539

    If your business is thinking about modernizing your legacy IBM i (also known as AS/400 or iSeries) applications, you will want to read this white paper first!

    Download this paper and learn how Node.js can ensure that you:
    - Modernize on-time and budget - no more lengthy, costly, disruptive app rewrites!
    - Retain your IBM i systems of record
    - Find and hire new development talent
    - Integrate new Node.js applications with your existing RPG, Java, .Net, and PHP apps
    - Extend your IBM i capabilties to include Watson API, Cloud, and Internet of Things


    Read Node.js for Enterprise IBM i Modernization Now!

     

  • Profound Logic Solution Guide

    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 companyare not aligned with the current IT environment.

    Get your copy of this important guide today!

     

  • 2022 IBM i Marketplace Survey Results

    Fortra2022 marks the eighth edition of the IBM i Marketplace Survey Results. Each year, Fortra captures data on how businesses use the IBM i platform and the IT and cybersecurity initiatives it supports.

    Over the years, this survey has become a true industry benchmark, revealing to readers the trends that are shaping and driving the market and providing insight into what the future may bring for this technology.

  • Brunswick bowls a perfect 300 with LANSA!

    FortraBrunswick is the leader in bowling products, services, and industry expertise for the development and renovation of new and existing bowling centers and mixed-use recreation facilities across the entertainment industry. However, the lifeblood of Brunswick’s capital equipment business was running on a 15-year-old software application written in Visual Basic 6 (VB6) with a SQL Server back-end. The application was at the end of its life and needed to be replaced.
    With the help of Visual LANSA, they found an easy-to-use, long-term platform that enabled their team to collaborate, innovate, and integrate with existing systems and databases within a single platform.
    Read the case study to learn how they achieved success and increased the speed of development by 30% with Visual LANSA.

     

  • The Power of Coding in a Low-Code Solution

    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:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks

     

     

  • Why Migrate When You Can Modernize?

    LANSABusiness 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.
    In this white paper, you’ll learn how to think of these issues as opportunities rather than problems. We’ll explore motivations to migrate or modernize, their risks and considerations you should be aware of before embarking on a (migration or modernization) project.
    Lastly, we’ll discuss how modernizing IBM i applications with optimized business workflows, integration with other technologies and new mobile and web user interfaces will enable IT – and the business – to experience time-added value and much more.

     

  • UPDATED: Developer Kit: Making a Business Case for Modernization and Beyond

    Profound Logic Software, Inc.Having trouble getting management approval for modernization projects? The problem may be you're not speaking enough "business" to them.

    This Developer Kit provides you study-backed data and a ready-to-use business case template to help get your very next development project approved!

  • What to Do When Your AS/400 Talent Retires

    FortraIT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators is small.

    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:

    • Why IBM i skills depletion is a top concern
    • How leading organizations are coping
    • Where automation will make the biggest impact

     

  • Node.js on IBM i Webinar Series Pt. 2: Setting Up Your Development Tools

    Profound Logic Software, Inc.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. In Part 2, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Attend this webinar to learn:

    • Different tools to develop Node.js applications on IBM i
    • Debugging Node.js
    • The basics of Git and tools to help those new to it
    • Using NodeRun.com as a pre-built development environment

     

     

  • Expert Tips for IBM i Security: Beyond the Basics

    SB PowerTech WC GenericIn this session, IBM i security expert Robin Tatam provides a quick recap of IBM i security basics and guides you through some advanced cybersecurity techniques that can help you take data protection to the next level. Robin will cover:

    • Reducing the risk posed by special authorities
    • Establishing object-level security
    • Overseeing user actions and data access

    Don't miss this chance to take your knowledge of IBM i security beyond the basics.

     

     

  • 5 IBM i Security Quick Wins

    SB PowerTech WC GenericIn today’s threat landscape, upper management is laser-focused on cybersecurity. You need to make progress in securing your systems—and make it fast.
    There’s no shortage of actions you could take, but what tactics will actually deliver the results you need? And how can you find a security strategy that fits your budget and time constraints?
    Join top IBM i security expert Robin Tatam as he outlines the five fastest and most impactful changes you can make to strengthen IBM i security this year.
    Your system didn’t become unsecure overnight and you won’t be able to turn it around overnight either. But quick wins are possible with IBM i security, and Robin Tatam will show you how to achieve them.

  • Security Bulletin: Malware Infection Discovered on IBM i Server!

    SB PowerTech WC GenericMalicious programs can bring entire businesses to their knees—and IBM i shops are not immune. It’s critical to grasp the true impact malware can have on IBM i and the network that connects to it. Attend this webinar to gain a thorough understanding of the relationships between:

    • Viruses, native objects, and the integrated file system (IFS)
    • Power Systems and Windows-based viruses and malware
    • PC-based anti-virus scanning versus native IBM i scanning

    There are a number of ways you can minimize your exposure to viruses. IBM i security expert Sandi Moore explains the facts, including how to ensure you're fully protected and compliant with regulations such as PCI.

     

     

  • Encryption on IBM i Simplified

    SB PowerTech WC GenericDB2 Field Procedures (FieldProcs) were introduced in IBM i 7.1 and have greatly simplified encryption, often without requiring any application changes. Now you can quickly encrypt sensitive data on the IBM i including PII, PCI, PHI data in your physical files and tables.
    Watch this webinar to learn how you can quickly implement encryption on the IBM i. During the webinar, security expert Robin Tatam will show you how to:

    • Use Field Procedures to automate encryption and decryption
    • Restrict and mask field level access by user or group
    • Meet compliance requirements with effective key management and audit trails

     

  • Lessons Learned from IBM i Cyber Attacks

    SB PowerTech WC GenericDespite the many options IBM has provided to protect your systems and data, many organizations still struggle to apply appropriate security controls.
    In this webinar, you'll get insight into how the criminals accessed these systems, the fallout from these attacks, and how the incidents could have been avoided by following security best practices.

    • Learn which security gaps cyber criminals love most
    • Find out how other IBM i organizations have fallen victim
    • Get the details on policies and processes you can implement to protect your organization, even when staff works from home

    You will learn the steps you can take to avoid the mistakes made in these examples, as well as other inadequate and misconfigured settings that put businesses at risk.

     

     

  • The Power of Coding in a Low-Code Solution

    SB PowerTech WC GenericWhen 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:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks

     

     

  • The Biggest Mistakes in IBM i Security

    SB Profound WC Generic The Biggest Mistakes in IBM i Security
    Here’s the harsh reality: cybersecurity pros have to get their jobs right every single day, while an attacker only has to succeed once to do incredible damage.
    Whether that’s thousands of exposed records, millions of dollars in fines and legal fees, or diminished share value, it’s easy to judge organizations that fall victim. IBM i enjoys an enviable reputation for security, but no system is impervious to mistakes.
    Join this webinar to learn about the biggest errors made when securing a Power Systems server.
    This knowledge is critical for ensuring integrity of your application data and preventing you from becoming the next Equifax. It’s also essential for complying with all formal regulations, including SOX, PCI, GDPR, and HIPAA
    Watch Now.

  • Comply in 5! Well, actually UNDER 5 minutes!!

    SB CYBRA PPL 5382

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

    Request your trial now!

  • Backup and Recovery on IBM i: Your Strategy for the Unexpected

    FortraRobot automates the routine 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:
    - Simplified backup procedures
    - Easy data encryption
    - Save media management
    - Guided restoration
    - Seamless product integration
    Make sure your data survives when catastrophe hits. Try the Robot Backup and Recovery Solution FREE for 30 days.

  • Manage IBM i Messages by Exception with Robot

    SB HelpSystems SC 5413Managing messages on your IBM i can be more than a full-time job if you have to do it manually. 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:
    - Automated message management
    - Tailored notifications and automatic escalation
    - System-wide control of your IBM i partitions
    - Two-way system notifications from your mobile device
    - Seamless product integration
    Try the Robot Message Management Solution FREE for 30 days.

  • Easiest Way to Save Money? Stop Printing IBM i Reports

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

    - Automated report distribution
    - View online without delay
    - Browser interface to make notes
    - Custom retention capabilities
    - Seamless product integration
    Rerun another report? Never again. Try the Robot Report Management Solution FREE for 30 days.

  • Hassle-Free IBM i Operations around the Clock

    SB HelpSystems SC 5413For over 30 years, Robot has been a leader in systems management for IBM i.
    Manage your job schedule with the Robot Job Scheduling Solution. Key features include:
    - Automated batch, interactive, and cross-platform scheduling
    - Event-driven dependency processing
    - Centralized monitoring and reporting
    - Audit log and ready-to-use reports
    - Seamless product integration
    Scale your software, not your staff. Try the Robot Job Scheduling Solution FREE for 30 days.