Sie sind auf Seite 1von 23

MC Press Online

Converting to Page-at-a-time Subfiles


Contributed by Doug Pence Friday, 30 June 2000 Last Updated Thursday, 04 October 2007

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
http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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.

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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.

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

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

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

* To compile:

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

* 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*

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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)

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

******

****** Call another program here

******

c Clear SflOption

c EndIf

c EndIf

c Update SflRcd

c EndIf

c EndDo

c EndDo

c Eval *InLR = *On

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

***** 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)

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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)

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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)

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

MC Press Online

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


http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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


http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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
http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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
http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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


http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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


http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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
http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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#


http://www.mcpressonline.com Powered by Joomla! Generated: 28 September, 2008, 23:38

MC Press Online

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.

http://www.mcpressonline.com

Powered by Joomla!

Generated: 28 September, 2008, 23:38

Das könnte Ihnen auch gefallen