With subfiles you can create a display file with lists of items. Let's see how that's done.
利用子文件我們可以創(chuàng)建帶有列表項(xiàng)目的顯示文件,現(xiàn)在我們就看看是如何創(chuàng)建的
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.
子文件是一個(gè)顯示文件,它能夠幫助你顯示列表和在列表上作相應(yīng)的處理,你在PDM上能看到的列表成員就是你的一個(gè)子文件
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:
在這一章,我們將要?jiǎng)?chuàng)建一個(gè)子文件,它用于根據(jù)特定的ID顯示所有的卡,為了更好地維護(hù)幾張表,我們創(chuàng)建一個(gè)表包含多個(gè)我們將要用在子文件的字段,在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:
打開(kāi)SDA創(chuàng)建一個(gè)新的成員
Create a BOTTOM record that should look like this:
創(chuàng)建一個(gè)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:
現(xiàn)在我們開(kāi)始創(chuàng)建子文件了,創(chuàng)建一個(gè)新的記錄,名字為L(zhǎng)IST,記錄的類(lèi)型是SFL
When you press Enter a new record appears. Write SFLCTL on it:
現(xiàn)在我們按下回車(chē),一個(gè)新的記錄出現(xiàn)如下,在上面寫(xiě)下SFLCTL如圖
This field creates a subfile control record, which works like the heading on the list.
這個(gè)字段用來(lái)創(chuàng)建子文件控制記錄,就像列表的頭部
You have to activate some options now: 現(xiàn)在你需要激活下面的選項(xiàng)
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代碼維護(hù)控制控制子文件的狀態(tài),輸入回車(chē)我們會(huì)返回之前的屏幕界面,現(xiàn)在選擇子文件的顯示布局
On subfile maximum size type 9999 and on the number of records for page type 9:
在子文件的最大值輸入9999和頁(yè)面的最大記錄數(shù)輸入9
Press enter to go back. Select the option Select Record Keyword:
輸入回車(chē)返回,然后選擇字段關(guān)鍵字選項(xiàng)
Choose Overlay keywords: 選擇覆蓋關(guān)鍵字
Select Overlay without erasing: 選擇覆蓋但不擦除選項(xiàng)
Press Enter until you're back on this screen: 輸入回車(chē),然后返回如下
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).
打開(kāi)SFLCTL記錄,默認(rèn)是這個(gè)記錄顯示在設(shè)計(jì)界面上,選擇To和Bottom進(jìn)行可視化(按下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:
返回設(shè)計(jì)界面,在上面寫(xiě)上“Client Nr.”,在CLICARD試圖中選擇字段ID_CLI作為輸入和輸出,
Type the titles of the subfile's columns and a separating line:
輸入分割線(xiàn)和子文件的字段標(biāo)題
Let's add some proprieties to the Client ID field. Place an * before to the left of the field.
現(xiàn)在我們添加一些新的屬性給與Client ID字段,在這個(gè)字段的左邊輸入一個(gè)*
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:
現(xiàn)在我們需要為這個(gè)字段添加一個(gè)指示器,當(dāng)值一個(gè)指定的ID沒(méi)有找到記錄(這個(gè)ID并不存在或者根據(jù)這個(gè)ID找不到記錄)的時(shí)候,這個(gè)指示器將被激活,在錯(cuò)誤描述選項(xiàng)的地方輸入Y
Insert the following information:
輸入下面的信息
Close this record and open the LIST record. Select the TOP and BOTTOM records for display (F9):
選擇這個(gè)記錄并且同時(shí)打開(kāi)這個(gè)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.
創(chuàng)建一個(gè)輸入字段,用戶(hù)我在這里輸入選項(xiàng),我們?cè)谌缦聢D的位置輸入‘+i’然后按下回車(chē)
Notice how the field spread across the 9 line you previously defined as the subfile page size.
注意你之前是如何定義子文件的每頁(yè)大小為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.
這些字段大概會(huì)本顯示兩次,因?yàn)镾DA會(huì)把之前加載的字段也被顯示出來(lái),因此選擇字段的時(shí)候需要小心一點(diǎn),盡量選擇那些比較靠右的字段,因?yàn)樗麄兪亲詈蟊患虞d的,
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.
假如有很多的字段,消息行顯示不完,在行尾會(huì)顯示一個(gè)+號(hào),按下翻頁(yè)鍵就可以看到剩下的那些沒(méi)有顯示的字段。
Place the fields on their positions: 將字段放在相關(guān)的位置
The final result: 最后的結(jié)果
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”生效,同時(shí)添加關(guān)鍵字INDARA到代碼中去,假如你忘記了怎么做的話(huà),回頭看看第八章的顯示文件創(chuàng)建。
You must add the red line to the SFLCTL record:
你必須為SFLCTL記錄添加紅線(xiàn)
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記錄中,你必須修改默認(rèn)的輸入字段的名字,因?yàn)槟J(rèn)是FLD001,或者像如下
A R LIST SFL
A OPTION 1A I 9 5
(...)
Executing the subfile 執(zhí)行子文件
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.
要運(yùn)行子文件,你必須創(chuàng)建一個(gè)RPGLE的成員,檢出文件QRPGLESRC.SHW_SFL 查看一下細(xì)節(jié),看看是如何寫(xiě)這個(gè)文件
When you run the RPGLE code: 當(dāng)你運(yùn)行RPGLE代碼后可以看到下面的結(jié)果