Problem solve Get help with specific problems with your technologies, process and projects.

Working with subfile lines

I have a subfile that displays customer's codes and customer's addresses with the command key F11. I would like to display the customer's codes and some financial information. By pressing F11 again, the system should display the previous information (code & address). The second display modes should keep the same page. What's going on?
This is really quite easy. The subfile line must contain a single field to display the variable data (it can contain other, fixed fields like customer code as well, of course), and two hidden fields containing the alternate data (address, and financial info) to display.

Your program will hold a flag that indicates which of the hidden fields is currently copied to the display field.

When you load the subfile, format the data for display in your program. Data structures and BIFs such as %EDITC are useful for this. Then store the address data in hidden field 1 and the financial data in hidden field 2. If the flag is set, you are displaying field 1, so copy that to the display field. Otherwise, copy field 2 to the display field.

When the user presses F11, switch the indicator and execute a subroutine to read all the subfile records. For each one read, copy field 2 to the display field and update the subfile record. Then on your next EXFMT the display will magically change.

Keeping the display on the same page is easy, too. The code after the EXFMT (in ILE RPG) is:

C                Select                                                 Keep RRN       
C                When      not *In14                                    :Empty subfile 
C                Eval      CurrPage    = *Zero                                         
C                When      CRRN        > *Zero                          :Cursor RRN     
C                Eval      CurrPage    = CRRN                                           
C                Other                                                  :No cursor RRN 
C                Eval      CurrPage    = D1DRRN                                         
C                EndSl                                                                 

In the display file, define (on the SFLCTL format): 

A                                       SFLCSRRRN(&CRRN) 
A            D1DRRN         4S 0H       SFLRCDNBR(CURSOR) 
A            CRRN           5S 0H       TEXT('Subfile cursor RRN') 
So now, in your program, if the subfile has been updated as described, set D1DRRN = CurrPage before the next EXFMT and the same page will be displayed.


The Best Web Links: tips, tutorials and more.

Visit the ITKnowledge Exchange and get answers to your developing questions fast.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.

Dig Deeper on iSeries programming commands