One of the hardest tasks for a database system is to create a true transaction processing application. A database system contains at least one “one to many” relationships. A “one to many” relationship means that one record on a file can have many records on another file that “belong” to it. The file that has the “one" record is called the “MASTER” file; the file that contains the “many” records that belong to the master file records is called the “DETAIL”, “LINE-ITEM” or “TRANSACTION” file.
filePro Plus can handle this relationship easily, just by assuring that each record on the master file contains a unique value (key) and by keeping a copy of that key on the transaction file’s records that belong to it. In the worst case, you can even use the record number of the master record as the key, if no other unique key exists.
The most difficult Part of implementing a good system is the user interface piece. How do you give the user the ability to view all the transaction records belonging to a particular master? How does the user add, update or delete transactions? Well, filePro Plus has a Browse Lookup feature provides a simple but elegant method to create this user interface with a minimum amount of programming code.
Here is what we might wish the end-user to be able to do:
. Display all transaction records for the current master record
. Scroll up and down through the transaction records to find or select a particular record
. Make changes to the selected transaction item
. Delete a particular transaction record
. Add new records, belonging to the current master record, to the transaction file
This general list should be familiar to you. It is the nucleus of just about every complex application ever written. Obviously, you may not want all users to have unrestricted access to all these functions. That is a fine point that you can address on a case by case basis.
Let’s use the following example to illustrate how filePro Plus uses the browse lookup helps us create this “one to many” relationship.
First, we define an invoice file that can contain any number of fields but includes (Figure 29-1):
Next, we want to define a transaction file that looks like (Figure 29-2):

Figure 29—1: Invoice File “xinv”
Figure 29—2: Invoice File “xtran”
For this discussion, we will call the invoice file XINV and the transaction file XTRAN. For your convenience, both these files have been included in your filePro Plus software. If you are defining the files, use different names. In addition, you must have filePro Plus create a Screen 0 for at least the XTRAN file.
Figures 29-3 and 29-4 are the input screens needed to run the processing.
Figure 29-3. 'xinv" file, Screen 0
Figure 29-4. "xtran" file, Screen 1
Input Processing Table
Jun 19, 2000 15:25 File Name: XINV Page 1
Processing: Input
1 ------- - - - - - - - - - - - - - - - -
If:
Then: tm(8,.2)
2 ------- - - - - - - - - - - - - - - - -
If:
Then: end
3 ------- - - - - - - - - - - - - - - - -
@entsel If:
Then: show "\r T \r-Transactions"
4 ------- - - - - - - - - - - - - - - - -
If:
Then: end
5 ------- - - - - - - - - - - - - - - - -
@wlf1 If: 2 eq ""
Then: 2=@rn; display
6 ------- - - - - - - - - - - - - - - - -
If:
Then: end
7 ------- - - - - - - - - - - - - - - - -
@wlf2 If:
Then: show ""; display "0"
8 ------- - - - - - - - - - - - - - - - -
If:
Then: show("20","19") "\r A \r-ADD \r U \r-UPDATE \r D \r-DELETE \r
X \r-EXIT"
9 ------- - - - - - - - - - - - - - - - -
If:
Then: lookup xtran k=2 i=b -nxm b="(brw=8,10,12 xkey=adux show=pkeep
pop=0 fill=asc,top)[ Date Description
10 ------- - - - - - - - - - - - - - - - -
If:
Then: Amount]*3 *4
*5"
11 ------- - - - - - - - - - - - - - - - -
If:
Then: show("20","1") "
"
12 ------- - - - - - - - - - - - - - - - -
If: @sk eq "SAVE"
Then: clearb; escape; end
13 ------- - - - - - - - - - - - - - - - -
If: @bk eq "" or @bk eq "x"
Then: clearb; end
14 ------- - - - - - - - - - - - - - - - -
If: not xtran and @bk ne "a"
Then: beep; show("20","15") "@There Are No Transactions for Invoice:"<2;
goto @wlf2
15 ------- - - - - - - - - - - - - - - - -
If: @bk eq "d"
Then: 3=3-xtran(5); delete xtran; 4=4-"1"; goto @wlf2
16 ------- - - - - - - - - - - - - - - - -
If: @bk eq "u"
Then: tm=xtran(5); goto upxtran
17 ------- - - - - - - - - - - - - - - - -
addnew If: @bk eq "a"
Then: lookup xtran r=free -e
18 ------- - - - - - - - - - - - - - - - -
If:
Then: xtran(1)=1; xtran(2)=2; xtran(3)=@td; tm=""
Jun 19, 2000 15:25 File Name: XINV Page 2
Processing: Input
19 ------- - - - - - - - - - - - - - - - -
upxtran If:
Then: popup("11","16") update xtran,1,4
20 ------- - - - - - - - - - - - - - - - -
If: @sk eq "SAVE"
Then: 3=3+xtran(5)-tm; tm=""; clearp
21 ------- - - - - - - - - - - - - - - - -
If: @sk eq "SAVE" and @bk eq "a"
Then: 4=4+"1"; display; goto addnew
22 ------- - - - - - - - - - - - - - - - -
If: @sk eq "BRKY" and @bk eq "a"
Then: delete xtran
23 ------- - - - - - - - - - - - - - - - -
If:
Then: clearp; goto @wlf2
24 ------- - - - - - - - - - - - - - - - -
@keyd If: 3 ne "" and 3 ne "0"
Then: beep; show"@ CAN NOT DELETE A RECORD WITH NON-ZERO BALANCE"; end
25 ------- - - - - - - - - - - - - - - - -
If:
Then: delete; end
26 ------- - - - - - - - - - - - - - - - -
@keyt If:
Then: goto @wlf2
Step by step description of the “xinv” input processing table.
Elements 1-2 These lines are performed when the user saves the record by pressing the <ESC> key.
Element 1 Tells filePro Plus the attributes for field “tin”. Variable “tin” is given a length of 8 and is a true number with 2 places after the decimal point.
Element 2 The work has been completed and the processing simply ENDs.
@entsel
Lines 3—4 These lines are performed after the record is displayed, but before the prompts at the bottom of the screen are displayed.
Element 3 SHOWs the message, and displays the letter “T” in reverse video using the code \r. Since there is no row or column defined in the show statement the message defaults to line 23 and the message is centered.
Element 4 ENDs the @entsel processing.
@wlfl
Elements5—6 These lines are performed when the user leaves field 1, the customer number field.
Element 5 If field 2, the invoice number, is blank then set it equal to the current master record number (@RN) and DISPLAY
the results.
Element 6 ENDs the @wlf 1 processing.
@wlf2
Elements 7-24 These lines are performed when the user leaves field 2, the invoice number.
Element 7 SHOW clears line 23 (default line), and DISPLAYs screen 0.
Element 8 This SHOW puts the message on at a particular point on the screen, row 20, column 19 and displays the screen options
“A,” “U,~’ “D,” and “X” in reverse video using the code \r.
Element 9 This line contains the LOOKUP statement. This LOOKUP is a “browse” lookup. You can define a browse lookup by using the <F5> key as you would a normal lookup. In this case, the browse lookup is in the pkeep mode, exit keys have been defined as (A,D,U,X), which correspond the show statement on line 8, screen 0 in xtran was selected for the pop-up window, and the index is in ascending mode. What this one statement accomplishes is to pop-up a browse window with as many as 5 transaction re-cords belonging to a particular invoice. The user can cause the transaction records to scroll up and down using the <1>~ <4>, <PGUP> and <PGDN> keys and select a transaction by pressing <RETURN>. See Figure 29—5.
If the user presses “V” the pop-up screen is called up, and it shows the fields and data for the record highlighted in the browse lookup window.
Element 11 This SHOW clears line 20 on the screen by showing blanks.
Elements l2-17 These lines determine what actions should take place de-pending on what key the user pressed while viewing the browse.
Element 12 If the user pressed <ESC>, to save the record, “@sk” will have the value “SAVE”. (“@sk” holds the value of the last special character pressed by the user. Refer to filePro Plus Reference Manual for more information about special key codes.) CLEARB will clear the browse lookup, the ESCAPE command will save the record, and END will end the processing. Remember that when the user saves the current record, filePro Plus begins the processing table at line 1 which in turn will end at line 2.
Element 13 If “@bk” equals “X”, the Browse lookup is CLEARed and the “@w112” processing ENDs. (“@bk” holds the value of the last character key pressed by the user while in a browse lookup. Since this browse lookup has exit keys, “@bk” can ¶ only have the values “A,U,D,X,or null”.)
Element 14 This line determines if the user is trying to delete or change
a transaction record but there are no records selected (not
7
xtran). If true, the user is notified with a BEEP, sent an error
message, and then the processing GOs TO the label
“@wlf2” to perform the browse lookup.
Element 15 If “@bk” is equal to “D” (delete) then the amount from the transaction record is subtracted from the master record balance due field (field 3), the count of the number of transactions (field 4) is decreased by 1, the transaction is deleted, and the processing table GOs TO (the label “@wlf’2” to redraw the screen.
Element 16 If “@bk” is equal to “U” (update) then the amount from the transaction record is assigned to the dummy field “tin” and the processing table GOs TO the label upxtran to update the highlighted transaction record.
addnew
Element 17 If “@bk” eq “A” (adding transactions) then a new record is to be added to the transaction file for this master record. A LOOKUP R = FREE is issued to obtain the next free record on file XTRAN (the transaction file).
Element 18 This line assigns to the new transaction record, customer code, invoice number, and transaction date (using system maintained field @Today’s Date) and assigns null to the dummy field “tin.”
upxtran This routine executes for both adding and changing a transaction record.
Element 19 This POPUP UPDATE command pops up screen 0 from the lookup file (xtran) and puts the user in update mode on the lookup record with the cursor being placed in field 4. The upper left corner of the pop-up screen will be located on row 11, column 16.
Element 20 If the user pressed <ESC> to save the popup screen then in either case (adding or changing a record) this line sub-tracts the old amount (dummy field “tin”) from the balance due (field 3) and adds the new amount (xtran(5)) in the popup window. (Note: “tin” will be null if adding new re-cords.) Dummy field “tin” is assign to null and the popup screen is CLEARed.
Element 21 If the user pressed <ESC> and “@bk” is equal to “a” then we are adding a new transaction record. The count of the number of transactions (field 4) is increased by 1, the screen is DISPLAYed, and the processing GOs TO the label “addnew” to add another transaction. Note that you would not want to add to the transaction count if the change function had been chosen.
Element 22 If the user Breaks/Deletes out of the popup window (“@sk” will be equal to “BRKY”) and “@bk” is equal to “A” (adding transactions) the LOOKUP FREE transaction record is DELETEd (xtran). Note that you would not want to delete the transaction record (xtran) if the change function had been chosen.
Element 23 This simply CLEARs the popup window, and the processing goes to (GOTO) the label @wlf2 to DISPLAY the screen
and perform the browse bcokup.
@keyd
Lines 24 - 25 This routine gets control when the user presses the <D> key to try to delete a master record.
Element 24 This line determines if the balance due (field 3) is blank or has a “0” value. If not, it beeps to notify the user, SHOWs
the error message and ENDs.
Element 25 If line 24 is false then the master record (xinv) is DELETEd and the processing ENDs.
@keyt
Element 26 These routine allows the user to run the lookup browse rou-tine when the user presses the <T> key. The processing GOs TO the label “@wlf2” to start the lookup browse routine.

Figure 29—5. Example of Browse Lookup Window