With subfiles you can create a display file with lists of items. Let's see how that's done.
利用子文件我们可以创建带有列表项目的显示文件,现在我们就看看是如何创建的
A subfile is a display file where you can place a listing of values and process changes on the list. The list of members that you can see in the PDM is an example of a subfile.
子文件是一个显示文件,它能够帮助你显示列表和在列表上作相应的处理,你在PDM上能看到的列表成员就是你的一个子文件
In this chapter we'll create a subfile which will show all the cards from a client given its ID. To make the manipulation of several tables easier, we'll create a view with the fields we'll use on the subfile. In STRSQL insert this code:
在这一章,我们将要创建一个子文件,它用于根据特定的ID显示所有的卡,为了更好地维护几张表,我们创建一个表包含多个我们将要用在子文件的字段,在STRSQL中输入这些代码
CREATE VIEW CLICARD AS SELECT CL.ID_CLI, CR.ID_CRD, SH.NAME_SHP, CR.SHOP_CRD
FROM DEMO/CLIENTS CL, DEMO/SHOP SH, DEMO/CARDS CR
WHERE CL.ID_CLI = CR.CLIENT_CRD AND CR.SHOP_CRD = SH.ID_SHP
Open SDA (STRSDA) and create a new member:
打开SDA创建一个新的成员
Create a BOTTOM record that should look like this:
创建一个Bottom记录像如下
And the TOP record like this: 和Top记录
Let's create the subfile now. Create a new record, name it LIST, the record type is SFL:
现在我们开始创建子文件了,创建一个新的记录,名字为LIST,记录的类型是SFL
When you press Enter a new record appears. Write SFLCTL on it:
现在我们按下回车,一个新的记录出现如下,在上面写下SFLCTL如图
This field creates a subfile control record, which works like the heading on the list.
这个字段用来创建子文件控制记录,就像列表的头部
You have to activate some options now: 现在你需要激活下面的选项
On the General Keywords menu insert the data you see below:
在General Keywords菜单输入输入如下
These indicators allow us to manipulate the status of the subfile from the RPG code. Press Enter to go back to the previous screen. Select Subfile display layout.
这些指示器允许我们利用RPG代码维护控制控制子文件的状态,输入回车我们会返回之前的屏幕界面,现在选择子文件的显示布局
On subfile maximum size type 9999 and on the number of records for page type 9:
在子文件的最大值输入9999和页面的最大记录数输入9
Press enter to go back. Select the option Select Record Keyword:
输入回车返回,然后选择字段关键字选项
Choose Overlay keywords: 选择覆盖关键字
Select Overlay without erasing: 选择覆盖但不擦除选项
Press Enter until you're back on this screen: 输入回车,然后返回如下
Open the SFLCTL record. By default the record list is already visible on the design screen. Select to visualize the other 2 records, TOM and BOTTOM (F9).
打开SFLCTL记录,默认是这个记录显示在设计界面上,选择To和Bottom进行可视化(按下F9)
Back to the design screen, write at the top “Client Nr.”. Select the fields from CLICARD view for input/output (F10) and select the ID_CLI field:
返回设计界面,在上面写上“Client Nr.”,在CLICARD试图中选择字段ID_CLI作为输入和输出,
Type the titles of the subfile's columns and a separating line:
输入分割线和子文件的字段标题
Let's add some proprieties to the Client ID field. Place an * before to the left of the field.
现在我们添加一些新的属性给与Client ID字段,在这个字段的左边输入一个*
We're going to add an indicator to this field, which will be activated when no record is found for an ID inserted (either the ID doesn't exist or it doesn't have any associated cards). Option Error Messages:
现在我们需要为这个字段添加一个指示器,当值一个指定的ID没有找到记录(这个ID并不存在或者根据这个ID找不到记录)的时候,这个指示器将被激活,在错误描述选项的地方输入Y
Insert the following information:
输入下面的信息
Close this record and open the LIST record. Select the TOP and BOTTOM records for display (F9):
选择这个记录并且同时打开这个LIST记录,选择Top和Bottom记录作显示(按下F9)
To create an input field, where the user will type the options, type '+i' on the same position as in the following image and press Enter.
创建一个输入字段,用户我在这里输入选项,我们在如下图的位置输入‘+i’然后按下回车
Notice how the field spread across the 9 line you previously defined as the subfile page size.
注意你之前是如何定义子文件的每页大小为9行
Select the records from CLICARD view for output.
从CLICARD视图中选择记录作为输入
The fields will probably be listed twice, because the SDA will show you the field that had been previously loaded from I/O in the SFLCTL record. You should select the fields further to the right, because they are the last ones loaded. You must be careful selecting the fields.
这些字段大概会本显示两次,因为SDA会把之前加载的字段也被显示出来,因此选择字段的时候需要小心一点,尽量选择那些比较靠右的字段,因为他们是最后被加载的,
If there are more fields than the ones that can fit the message line, a plus (+) sign will appear at the end of the line. Press Page Down to see the remaining fields.
假如有很多的字段,消息行显示不完,在行尾会显示一个+号,按下翻页键就可以看到剩下的那些没有显示的字段。
Place the fields on their positions: 将字段放在相关的位置
The final result: 最后的结果
Don't forget to activate the indicator 03 at file-level so that “F3=Exit” can work and add the keyword INDARA to the code. Check out the Display file chapter if you don't remember how to do this.
不要忘记激活03指示器,在文件的层面,使得“F3=Exit”生效,同时添加关键字INDARA到代码中去,假如你忘记了怎么做的话,回头看看第八章的显示文件创建。
You must add the red line to the SFLCTL record:
你必须为SFLCTL记录添加红线
A R SFLCTL SFLCTL(LIST)
A SFLSIZ(9999)
A SFLPAG(0009)
A OVERLAY
A 30 SFLDSP
A 31 SFLDSPCTL
A 35 SFLCLR
A 33 SFLEND(*MORE)
A 4 8'Client Nr.'
A ID_CLI R B 4 19REFFLD(CLICARD/ID_CLI DEMO/CLICARD)
A 90 ERRMSG('No Data Found')
A 6 4'Op.'
A 6 12'Card Nr.'
A 6 27'Shop Nr.'
A 6 42'Shop Name'
A 7 2'__________________________________-
A ___________________________________-
A __________'
A RRN 4S 0H SFLRCDNBR(CURSOR)
In the LIST record change the name of the input field to OPTION. By default it must be named FLD001, or something like it.
在LIST记录中,你必须修改默认的输入字段的名字,因为默认是FLD001,或者像如下
A R LIST SFL
A OPTION 1A I 9 5
(...)
Executing the subfile 执行子文件
To run the subfile you must create an RPGLE member. Check out the file QRPGLESRC.SHW_SFL for more details on how to write this member.
要运行子文件,你必须创建一个RPGLE的成员,检出文件QRPGLESRC.SHW_SFL 查看一下细节,看看是如何写这个文件
When you run the RPGLE code: 当你运行RPGLE代码后可以看到下面的结果