17
Wed, Apr
5 New Articles

Enhancing the Performance of Interactive Programs

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

If you have time to get a cup of coffee while your interactive programs load, take a look at the techniques presented in this article. We'll offer a few ways to speed up the interactive program initiation and reduce some of the load on your system.

What's the Holdup?

Users often wonder what makes programs take so long to load. Most programmers being asked this question would probably say something about the system not having enough memory or slow processors. If the program uses a lot of files, here are some great ways to reduce program initiation time without expanding your system.

From a performance standpoint, opening and closing files are two of the most overhead-intensive events that take place on the AS/400. If the interactive programs you work with have a large number of files (sometimes this is unavoidable), program initiation can seem to take forever while the program loads and all of the files are opened.

If you can find a way to spread out the work load by opening files at times other than program initiation, it stands to reason that the program would load in a shorter period of time. Two techniques that can allow you to accomplish this are user-controlled file opens and preopening of files. The following material explains how to implement both techniques.

User-controlled File Opens

IBM midrange systems have allowed user-controlled file opens for many years. This file-open capability has grown much more powerful on the AS/400 because of the changes IBM has made to RPG in the past several years.

First of all, you should open a file only if you intend to use it. As you see in 1, by placing a UC (user controlled) in the File Condition section of the F-spec, you can code your program to open files as you need them instead of when the program loads. Be sure to set a flag in the program indicating that the file has already been opened, so you will not attempt to open it again. Failure to include this step could result in a nasty RPG error if you have not included an error indicator on the open.

First of all, you should open a file only if you intend to use it. As you see in Figure 1, by placing a UC (user controlled) in the File Condition section of the F-spec, you can code your program to open files as you need them instead of when the program loads. Be sure to set a flag in the program indicating that the file has already been opened, so you will not attempt to open it again. Failure to include this step could result in a nasty RPG error if you have not included an error indicator on the open.

It is also possible that certain files may never be opened at all. Suppose the program contains multiple screens that are processed conditionally depending upon user responses. The program could be coded to open only those files associated with the screens that are selected. This situation has another advantage: files that are never opened need not be closed either.

Secondly, and perhaps more importantly, user-controlled file opens offer an excellent opportunity to distribute program overhead so that it is less noticeable to the end user. Even though the system performs the same amount of work, it is not as obvious to the end user because the file opens do not all occur at the same time.

The example in 2 illustrates how you can code the program so that the file opens occur while the program waits for a response from the end user.

The example in Figure 2 illustrates how you can code the program so that the file opens occur while the program waits for a response from the end user.

In this example, the WRITE and READ op codes replace EXFMT. Several user- controlled file opens have been placed between the WRITE and the READ statements. When this program executes, the screen panel is displayed and then the files are opened while the operator responds. Coding the program this way creates a condition where the files are opened while the program waits on the end user instead of the other way around.

For the example in 2 to work, you need to ensure that the display file sends the record format to the terminal without waiting until the program does a read. A couple of ways to do this include compiling the display file with DFRWRT(*NO) or using the FRCDTA keyword in the DDS.

For the example in Figure 2 to work, you need to ensure that the display file sends the record format to the terminal without waiting until the program does a read. A couple of ways to do this include compiling the display file with DFRWRT(*NO) or using the FRCDTA keyword in the DDS.

When implementing user-controlled file opens, you may choose to ignore closing the files explicitly and let the program close them automatically at LR. If the delay caused when the program ends creates problems for you, try using the RETRN op code instead of setting on LR. This change has other implications, however, so you may want to research further before making this change.

Preopened Files

The second technique to reduce program initiation overhead enlists a method called preopened files. This method can be very useful when multiple programs use the same data files. If you open the data or display files so that the open data paths can be shared, subsequent high-level language programs will not need to open the files.

In the example in 3, the Open Database File (OPNDBF) command opens the data files and the Override Database File (OVRDBF) command specifies that the open data path is to be shared. Subsequent calls to application programs within this same session will use the existing open data path instead of opening the file again. The term "shared" could be somewhat confusing, because other sessions do not have access to the open data paths.

In the example in Figure 3, the Open Database File (OPNDBF) command opens the data files and the Override Database File (OVRDBF) command specifies that the open data path is to be shared. Subsequent calls to application programs within this same session will use the existing open data path instead of opening the file again. The term "shared" could be somewhat confusing, because other sessions do not have access to the open data paths.

When you use OPNDBF to share the open data path, make sure the file is opened with the correct OPTION level. This controls whether the program opens the data path for input, output, or both. If any program is going to update the file, make sure you use OPTION (*ALL).

If your application uses the same files over and over again, those files may be opened and closed many times within a given day. The preopened-file technique can eliminate big delays in application program initiation and help to improve overall system performance significantly.

Words of Caution

I'd like to offer a word of warning for those who use the library list to manipulate which file on the system is to be used. When a file has been preopened with a shared open data path, an application program uses that file whether it is currently in your library list or not. The program simply uses the open data path of the shared file. If you do not have files with the same name in multiple libraries, this does not present a problem for you.

When using preopened files, keep in mind that the file is always in use as long as the session exists. It does not matter whether a program is actually running or not. This situation can be problematic at times when files are being saved or a job needs dedicated access to a file. Preopened files remain in use until the files are closed or the session is terminated.

You also cannot assume that the file pointer is positioned where you want it when a program is initiated. If you are going to be doing any type of sequential read operation, you should always remember to set your file pointer appropriately.

Other security and operational issues should be considered before trying this particular method. The Database Guide and the CL Reference manual offer more information on using preopened files.

In Conclusion

If end users complain about response time and your application uses a large number of files, you really should give these methods a try. You may be surprised how much difference the way your programs open and close files can make.

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

REFERENCES CL References (SC41-0030, CD-ROM QBKA8202). Database Guide (SC41-9569, CD-ROM QBKA7202).


Enhancing the Performance of Interactive Programs

Figure 1 User-controlled Opens

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 FCUSTOMERIF E K DISK UC C OPNCUS IFNE 'Y' FILE NOT ALREADY C OPEN CUSTOMER OPEN, OPEN IT C MOVE 'Y' OPNCUS 1 C ENDIF C CUSKEY CHAINCUSTOMER 99 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
Enhancing the Performance of Interactive Programs

Figure 2 User-controlled Opens Between Writing and Reading

 *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 FDISPLAY CF E WORKSTN FCUSTOMERIF E K DISK UC FSALESMENIF E K DISK UC C WRITEFORMAT DISPLAY FILE FORMAT C OPNCUS IFNE 'Y' FILE NOT ALREADY C OPEN CUSTOMER OPEN, OPEN IT C MOVE 'Y' OPNCUS 1 C ENDIF C OPNSLS IFNE 'Y' C OPEN SALESMEN C MOVE 'Y' OPNSLS 1 C ENDIF C READ FORMAT 99 WAITS FOR INPUT *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 
Enhancing the Performance of Interactive Programs

Figure 3 Sign-on CL Program to Preopen Files and Display In

 PGM MONMSG MSGID(CPF0000) OVRDBF FILE(CUSTOMER) SHARE(*YES) OVRDBF FILE(SALESMEN) SHARE(*YES) OPNDBF FILE(CUSTOMER) OPTION(*ALL) OPNDBF FILE(SALESMEN) OPTION(*ALL) GO MENU(CUSTMENU) ENDPGM 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

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: