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:
- 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.
- Change the title of the design
window to Select Customer or something equivalent.
- Name the design window CUSTLIST.
- Select the Subfile
part on the Parts Palette and click on the design window. Position and size the subfile as
required.
- Change the name of the subfile to SFL1.
- Now, add fields to the subfile.
There are three ways to add fields to a subfile part:
- Select entry fields from the Parts
Palette and click on the subfile part.
- Open the subfile part's Settings
notebook and go to the Field List page.
- Select fields from a reference
file and click on the subfile part.
- 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.
- 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:
You may need to resize the CUSTNO
or CUSTNA fields so they look like the design window above. If yes, follow these steps:
- In the Subfile Part Properties
notebook select the Field list page.
- Select a Subfile field part from
the list, then click Change.
- 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.
- 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.
- Close the Define Reference Fields
- VisualAge for RPG window.
- 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.
- When the template action
subroutine displays, add the following statements between the BEGACT and ENDACT statements
to fill the subfile:
*...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.