24
Wed, Apr
0 New Articles

Converting to Page-at-a-time Subfiles

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

Since you were a little child, you’ve been taught that more is better: a message that has been tacit, implicit, and direct. However, if you take a minute to think about it, more is not always better. Fewer taxes would obviously be better, fewer hours in a workweek would be great, and fewer people in front of you at your favorite ride at Disneyland would be more fun. Well, fewer records in a “load all” subfile would be better, too.

Programs are often written as “load all” subfiles because the database begins with a limited number of records. As the database grows, though, writing all the records to a subfile becomes impractical and unwieldy. When that happens, you need to convert your
“load all” subroutines to process your data one page at a time.

Less-on Learned

Back when the number of locations your business dealt with grew from five to 18, you might have written a subfile to present location records to your operators and become a hero! Your operators no longer needed to remember all those location numbers. Your subfile gave them a list from which they could select correct locations without having to memorize codes. The accuracy of their data entry was immediately improved. You could do no wrong!

However, somewhere in the back of your head, you knew that it was not always going to be like that. Memories are short; compliments are few. Today’s corporate mantra is “Yeah, but what have you done for me lately?” It’s been a couple of years since your heroic deed, and your business now deals with hundreds of locations. Operators now take a long time to find correct locations. They sometimes need to look through page after page of locations before they find the records they’re looking for, and the subfile takes longer to load than it should. The system seems to be slowing down. What are you going to do to get back your hero status (at least for a while, anyway)?

Paginate!

We suggest that you convert your “load all” subfile into one that processes data one page at a time. While you’re at it, add the ability to position records by location name. Yes, we are going to help you regain what was once yours.

Look at the “before” and “after” pictures of your program. Figure 1 is a “before” picture of a “load all” subfile. It writes every single record from the database file into the

subfile before it is presented to the operator. Loading of the subfile can be slow, depending on how many records are in the database file, but, once the subfile is loaded, it runs pretty fast because all the database records are in memory. However, the only way to navigate through the records is to use the Page keys.

Now look at the “after” subfile in Figure 2. You will notice a Position to field that allows the operator to search for the location name. Operators simply key in all or part of a location name and press Enter to reposition database records to the records they are looking for.

What are the advantages of this methodology? Well, you can see two principal advantages right off the bat. First, operators can get to the records they are looking for by keying in a couple characters of the location names and pressing Enter. However, an even bigger advantage from a system standpoint is that they see only the database records that they need. If this program were used frequently, you could save thousands of database I/O requests per day. This is the type of change that could improve your overall system throughput and restore your heroic stature to what it once was.

Getting It Done

The “before” picture in Figure 1 is represented by the code in Figures 3 and 4. Figure 3 shows the DDS for the “load all” subfile, and Figure 4 shows the supporting RPG IV code. Figures 5 and 6 (page 92) contain the display file DDS and RPG IV source code, respectively, for the “after” version in Figure 2.

We will begin by discussing what we did with the display file. Look at the DDS in Figures 3 and 5; you will notice very few differences between the two. In Figure 5, we added the PageUp and PageDown keywords, which are coded to trip indicators 27 and 28, respectively, when pressed. The Page keys are not coded in Figure 3, because all subfile paging is handled by the system at the controller level. The controller can do this because all the database records are always written to the subfile. That is not the case with the page- at-a-time subfile; you write only the records that you can see. Each paging operation causes the program to rebuild the subfile with the records required. In Figure 5, you may also notice that the PageDown keyword has been conditioned on indicator 24, the end-of-file indicator. This is done so the system does not produce an error when an operator tries to page past the end of the database file. In addition, we added a literal for the Position to field and an input field that we named SEARCH.

As you can see in Figures 4 and 6, a few more changes were required for the RPG IV program. First, in Figure 6, we defined a field named Iterate, which you use to control

when it is time to leave the program. The “before” version of the program (Figure 4) has no such field because all you care about there is whether or not the selection criteria are valid. The “after” version (Figure 6) had to have different considerations because of the new Position to features. Whereas the code in Figure 4 is designed to leave the processing loop when no errors are encountered, the program in Figure 6 does not leave the processing loop until you decide not to turn on the Iterate indicator. (You will notice that we turn it off each time we perform Execute Format [EXFMT] on the subfile.)

The next difference is where you check to see whether the Page keys have been pressed or whether the operator has keyed something into the Position to search field. If either of these events has occurred, you execute the corresponding subroutine. The Page Down and Position to functions have been built into the original LoadSfl subroutine.

The PageBack subroutine begins by setting the database pointer to the correct position. Since the database pointer probably points to the record following the last record currently appearing in the subfile, you need to read roughly two subfile pages of data before loading the subfile again. Rather than perform that unnecessary processing, chain to the first subfile record on the screen and set the database pointer accordingly. Then, read backward through the file, using the Read Prior (READP) operation, until you have enough records to fill one page of the subfile instead of two.

Next, perform the LoadSfl subroutine to fill a new page of the subfile with data. The LoadSfl subroutine has been changed so that it reads and writes enough database records to fill only a single page of the subfile (instead of the entire file). It also checks the Position to field to see whether or not the operator has keyed in anything. If so, the database pointer is reset to the position nearest the characters keyed in by the operator before the subfile page is filled. Because we changed the LoadSfl subroutine to present the subfile one page at a time, the subfile must be cleared each time the subroutine is run. Failure to perform this important step results in a subfile where records are all mixed up or even duplicated, depending on the options requested.

Kiss, Kiss, Kiss

Our approach, like our advice, is simple. As a matter of fact, the simpler, the better. We’ve taken a “load all” subfile and converted it into a page-at-a-time subfile with very little code or effort. Fewer records are being read, so overall system performance is improved. In addition, operators of this program take fewer steps to find the records they are looking for, improving productivity and reducing errors. Sometimes, less really can be more.

Converting_to_Page-_at-_a-_time_Subfiles03-00.png 400x250

Figure 1: The only way to navigate through a “load all” subfile is to use the Page keys.

Converting_to_Page-_at-_a-_time_Subfiles04-00.png 400x251

Figure 2: With a page-at-a-time subfile, operators see only the records they need to see.

*===============================================================

* To compile:

*

* CRTDSPF FILE(XXX/SFL102DS) SRCMBR(SFL102DS)

*

*===============================================================

A DSPSIZ(24 80 *DS3) CA03

A R SCREEN1

A 23 3'F3=Exit' COLOR(BLU)

A R SFLRCD SFL

A 41 SFLNXTCHG

A SFLOPTION 1A B 9 2DSPATR(UL HI)

A 40 DSPATR(PC)

A SFLLOCNAME 30A O 9 7

A SFLLOCID 10A O 9 39

A*

A R SFLCTL SFLCTL(SFLRCD)

A OVERLAY

A 21 SFLDSP

A 22 SFLDSPCTL

A 23 SFLCLR

A 24 SFLEND(*MORE)

A SFLSIZ(0024) SFLPAG(0012)

A 40 SFLMSG('Invalid option chosen')

A SFLRRN 4S 0H

A SFLRCDNBR 4S 0H SFLRCDNBR

A 1 29'Location Inquiry' DSPATR(HI)

A 4 1'Type options, press Enter.'

A COLOR(BLU)

A 5 4'1=Select' COLOR(BLU)

A 8 1'Opt Location NameA Location ID' DSPATR(HI)

*===============================================================

* To compile:

*

* CRTBNDRPG PGM(XXX/SFL102RG) SRCFILE(XXX/QRPGLESRC)

*

*===============================================================

FSfl102Ds CF E WORKSTN Sfile(SflRcd:SflRRN)

FLocationLFIF E K DISK

* Process subfile until no errors are found

c Dou *in40 = *off

* Display/Read Subfile

c MoveA '10' *IN(22)

c ExFmt SFLCTL

* If F3 Exit program

Figure 3: In a “load all” subfile, all subfile paging is handled by the system at the controller level.

c If *InKC = *On

c Leave

c EndIf

* Turn off error indicator

c Eval *In40 = *Off

* Look for Record Selection Request (40 = Selection error)

c Dou %EOF OR *in40

c ReadC SflRcd

c If NOT %EOF

* Turn off Subfile next change indicator

c Eval *In41 = *Off

c If SflOption ' '

* Validate the selected operator option

c If SflOption '1'

* Error

c Eval *In40 = *On

* Subfile Next Change

c Eval *In41 = *On

* Position subfile to page that contains the error

c Eval SflRcdNbr = SflRrn

c Else

******

****** Call another program here

******

c Clear SflOption

c EndIf

c EndIf

c Update SflRcd

c EndIf

c EndDo

c EndDo

*

c Eval *InLR = *On

*

***** SUBROUTINE: "*INZSR" **************************************

*** PROCESS INITIALIZATION ROUTINE *******************************

cSR *INZSR BEGSR

c *Loval Setll LocRec

c Exsr LoadSfl

cSR ENDSR

*

***** SUBROUTINE: "LoadSfl" **************************************

*** Load Subfile **********************************************

cSR LoadSfl BEGSR

c Eval SflRcdNbr = 1

* Clear subfile

c MoveA '0010' *IN(21)

c Write SFLCTL

c Eval *In23 = *off

c Write Screen1

* Write subfile

c Dou *In24

c Read LocRec 24

* Get out when there are no more records to read

c If NOT %EOF(LocationLF)

c Clear SflOption

c Eval SflRRN = SflRRN + 1

c Eval SflLocName = LocName

c Eval SflLocID = Location#

c Eval *In21 = *ON

c Write SflRcd

c EndIf

c EndDo

cSR ENDSR

*===============================================================

* To compile:

*

* CRTDSPF FILE(XXX/SFL103DS) SRCFILE(XXX/QDDSSRC)

*

*===============================================================

A CA03

A R SCREEN1

A 23 3'F3=Exit' COLOR(BLU)

A R SFLRCD SFL

A 41 SFLNXTCHG

A SFLOPTION 1A B 9 2DSPATR(UL HI)

A 40 DSPATR(PC)

Figure 4: A “load all” subfile is designed to leave the processing loop when no errors are encountered.

A SFLLOCNAME 30A O 9 7

A SFLLOCID 10A O 9 39

A*

A R SFLCTL SFLCTL(SFLRCD)

A OVERLAY

A PAGEUP(27)

A N24 PAGEDOWN(28)

A 21 SFLDSP

A 22 SFLDSPCTL

A 23 SFLCLR

A 24 SFLEND(*MORE)

A SFLSIZ(0024) SFLPAG(0012)

A 40 SFLMSG('Invalid option chosen')

A SFLRRN 4S 0H

A SFLRCDNBR 4S 0H SFLRCDNBR

A 1 29'Location Inquiry' DSPATR(HI)

A 4 1'Type options, press Enter.'

A COLOR(BLU)

A 4 42'Position to....' COLOR(BLU)

A SEARCH 15 B 4 58

A 5 4'1=Select' COLOR(BLU)

A 8 1'Opt Location NameA Location ID' DSPATR(HI)

Figure 5: The DDS for a page-at-a-time subfile is not very different from the DDS for a “load all” subfile, save the PageUp and PageDown keywords and a new search field.

*===============================================================

* To compile:

*

* CRTBNDRPG PGM(XXX/SFL103RG) SRCFILE(XXX/QRPGLESRC)

*

*===============================================================

FSfl103Ds CF E WORKSTN Sfile(SflRcd:SflRRN)

FLocationLFIF E K DISK

d Iterate S 1

* Process subfile until told not to

c Dou Iterate = *off

* Display/Read Subfile

c MoveA '10' *IN(22)

c ExFmt SFLCTL

* If F3 Exit program

c If *InKC = *On

c Leave

c EndIf

* Turn off error indicator

c Eval *In40 = *Off

c Eval Iterate = *Off

* If page up or down was pressed

c *IN27 Caseq *On Pageback

c *IN28 Caseq *On LoadSfl

c Search Casne *blanks LoadSfl

c EndCs

* Look for Record Selection Request

c Dou %EOF

c ReadC SflRcd

c If NOT %EOF

* Turn off Subfile next change indicator

c Eval *In41 = *Off

c If SflOption ' '

* Validate the selected operator option

c If SflOption '1'

* Error

c Eval *In40 = *On

c Eval Iterate = *On

* Subfile Next Change

c Eval *In41 = *On

* Position subfile to page that contains the error

c Eval SflRcdNbr = SflRrn

c Else

****** Your processing goes here

c Clear SflOption

c EndIf

c EndIf

c Update SflRcd

c EndIf

c EndDo

c EndDo

*

c Eval *InLR = *On

*** PROCESS INITIALIZATION ROUTINE *******************************

cSR *INZSR BEGSR

c *Loval Setll LocRec

c Exsr LoadSfl

cSR ENDSR

*** Page backwards through file **********************************

cSR PageBack BEGSR

* Set database pointer to first record in subfile

c 1 chain SflRcd

c Eval LocName = SflLocName

c LocName Setll Locrec

* Read prior 13 database records to position pointer to beginning

* of prior page

c Do 13

c Readp LocRec

c If %Eof(LocationLF)

c *Loval Setll Locrec

c Leave

c EndIf

c EndDo

* Load the subfile

c Exsr LoadSfl

cSR ENDSR

*** Load Subfile **********************************************

cSR LoadSfl BEGSR

c Eval SflRcdNbr = 1

c Eval Iterate = *on

* Clear subfile

c Eval SflRrn = 0

c MoveA '0010' *IN(21)

c Write SFLCTL

c Eval *In23 = *off

* Position database pointer

c If Search *Blanks

c Eval Locname = Search

c LocName Setll Locrec

c Clear Search

c EndIf

c Write Screen1

* Write subfile

c Do 12

c Read LocRec 24

c If NOT %EOF(LocationLF)

c Clear SflOption

c Eval SflRRN = SflRRN + 1

c Eval SflLocName = LocName

c Eval SflLocID = Location#

c Eval *In21 = *ON

c Write SflRcd

c Else

c Leave

c EndIf

c EndDo

cSR ENDSR

Figure 6: A page-at-a-time subfile does not leave the processing loop until you decide not to turn on the Iterate indicator.

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: