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?

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts including news, tips, and advice to help you do your job more efficiently and effectively. Stay informed on the hottest topics and biggest challenges faced by IT professionals working with iSeries products and services.

    By submitting your registration information to Search400.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of Search400.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

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.

This was first published in February 2005