6.2 Creating a New Component

As the application is now, you must know what a valid customer number is on the Customer Inquiry window. Instead, you can create another component to display, in a subfile, a list of customers with their numbers. When you select a customer from the list, the corresponding number is placed in the CUSTNO Entry field.

The instructions in this section are not as detailed as in earlier exercises since you are expected to have had some experience using the GUI Designer. Remember that on-line help is always available from the Help menu item on the GUI Designer.

You add a subfile part to display records from a logical file on AS/400. This file is named CUSTOML1 and can be found in library ADTSLAB. The record format name is CUSTOM01. The subfile you create displays data from the CUSTNO and CUSTNA fields.

Follow these steps:

  1. To begin, start the GUI Designer if it is not already running. If it is running, choose Project > New > GUI project from the menu bar to open a new project.
  2. Change the title of the design window to Select Customer or something equivalent.
  3. Name the design window CUSTLIST.
  4. Select the Subfile part on the Parts Palette and click on the design window. Position and size the subfile as required.
  5. Change the name of the subfile to SFL1.
  6. Now, add fields to the subfile. There are three ways to add fields to a subfile part:
  7. Use the Define Reference Fields Method. Choose Server > Define reference fields from the menu bar to display the field list for the file CUSTOML1 in library ADTSLAB.
  8. Select the CUSTNO field and click on the subfile part. Then select CUSTNA field and click on the subfile part. Your design window appears as follows:
  9. You may need to resize the CUSTNO or CUSTNA fields so they look like the design window above. If yes, follow these steps:

    1. In the Subfile Part Properties notebook select the Field list page.
    2. Select a Subfile field part from the list, then click Change.
    3. In the Subfile Field Part Properties notebook, select the Style page. Check that the number of pixels in the Column width(pixels) for the subfile field part is 287.
    4. Click OK to save any changes you made. Check and change the other Subfile Field part in the same way, if necessary. Then save and close the Property notebook.

    If you want to change the order of the fields in the subfile, open the Settings notebook for the subfile, go to the Fields tab and use the Move up and Move down push buttons.

  10. Close the Define Reference Fields - VisualAge for RPG window.
  11. Now you need to add code to fill the subfile. You are going to fill the subfile when the window is created. You need to create an action subroutine for the windows CREATE event. To create the action subroutine, use the right mouse button to invoke the pop-up menu for the window. Choose Events > CREATE.
  12. When the template action subroutine displays, add the following statements between the BEGACT and ENDACT statements to fill the subfile:
  13. 
    *...1....+....2....+....3....+....4....+....5....+....6....+....7....+.
    CSRN01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq
          *
     *
     * Read a record from database
    C                   Read      CustomL1                               99
     *
     * Do until end of file
    C     *in99         DowEq     *OFF
     *
     * Add a record to the subfile
    C                   Write     SFL1
     *
     * Read a record from database
    C                   Read      CustomL1                               99
    C                   EndDo
     *
     *
    

Remember to save the source in the Editor.

Click on to indicate that you've done all the steps.