Form Independence
Now let's see how to implement generic transaction code that can handle
multiple form formats. This will be illustrated by modifying the program
above. Keep in mind that we could have written the program this way to
start with. It is not a program modification that we must make every
time we want to add another form.
The following program provides generic update customer capability and is
form independent. That is, the program has no idea of which data
elements exist on a form, nor does it know how many possible different
forms may be used to update a customer.
____________________________________________________________________________________
| |
| 1 system custup,base=orders |
| 2 ,vpls=formfile |
| 3 ,file=formxref; |
| 4 define(item) menuname x(16): |
| 5 fkey 9(2): |
| 6 screen x(16): |
| 7 lastkey i(4); |
| 8 list menuname: |
| 9 lastkey; |
| 10 |
| 11 data menuname; <<to simulate transfer of control to this subroutine>>|
| 12 |
| 13 << |
| 14 ************************************************************* |
| 15 Subroutine: to update customer information |
| 16 |
| 17 input: menuname - contains the name of the screen to be displayed |
| 18 |
| 19 output: none |
| 20 ************************************************************* |
| 21 >> |
| 22 level; |
| 23 list fkey: |
| 24 screen; |
| 25 list(auto) customer; |
| 26 get(form) (menuname),init |
| 27 ,window=(" ") |
| 28 ,fkey=lastkey |
| 29 ,autoread; |
| 30 if (lastkey) = 0 |
| 31 then perform modify |
| 32 else |
| 33 do |
| 34 set(match) list (menuname); |
| 35 let (fkey) = (lastkey); |
| 36 set(match) list (fkey); |
| 37 get(serial) formxref,list=(menuname,fkey,screen); |
| 38 reset(option) match; |
| 39 perform modify; |
| 40 doend; |
| 41 end; |
____________________________________________________________________________________
Figure 9-6. Screen independence via indirect referencing
_______________________________________________________________________
| |
| 43 modify: |
| 44 |
| 45 set(key) list (cust-no); |
| 46 get customer,list=(@); |
| 47 put(form) (screen),window=("update? - f1=yes, f2=no");|
| 48 get(form) (screen),f1(autoread)=modify-f1 |
| 49 ,f2=modify-f2; |
| 50 |
| 51 modify-f1: |
| 52 |
| 53 update customer,list=(@); |
| 54 |
| 55 modify-f2: |
| 56 |
| 57 end; |
_______________________________________________________________________
Figure 9-6. Screen independence via indirect referencing (c
This program uses Transact's indirect referencing capability for forms.
Notice that all verbs which reference a form name do not actually specify
the form name. Each verb specifies the name of an element which contains
the name of the form to be referenced.
The program sets up a menu-driven customer update capability such as the
following series of forms depict.
________________________________________________________________________________________
| |
| custupdatemm customer update main menu |
| |
| |
| enter customer number [1 ] |
| |
| |
| f1 - marketing (custupdate1) |
| |
| f2 - finance (custupdate2) |
| |
| f3 - accounts payable (custupdate3) |
| |
| *********************************************** |
| or |
| |
| enter screen name [ ] |
| |
| |
| |
| market- finance accounts exit |
| ing payable |
________________________________________________________________________________________
Figure 9-7. Screen independence, customer main menu
______________________________________________________________________
| |
| custupdate1 marketing customer update |
| |
| |
| |
| customer number [1 ] |
| |
| name [name of customer 1 ]|
| |
| |
| update? - f1=yes, f2=no |
______________________________________________________________________
Figure 9-8. Screen independence, marketing customer update
____________________________________________________________
| |
| custupdate2 finance customer update |
| |
| |
| customer number [1 ] |
| |
| zip code [12345 ]|
| |
| |
| update? - f1=yes, f2=no |
____________________________________________________________
Figure 9-9. Screen independence, finance customer update
_________________________________________________________________________
| |
| custupdate3 accounts payable customer update |
| |
| customer number [1 ] |
| |
| name [name of customer 1 ]|
| |
| address [108 Lincoln Ave. ]|
| |
| city,state [So. Bend, Ind. ]|
| |
| zipcode [12345 ] |
| |
| |
| update? - f1=yes, f2=no |
_________________________________________________________________________
Figure 9-10. Screen independence, accounts payable customer update
There are many ways to implement a form-independent program. The above
is just one illustration. The key to this implementation is the MPE file
called FORMXREF which provides the indirection we need to establish form
independence.
The content of FORMXREF is as follows:
___________________________________________
| |
| MENUNAME: FKEY: SCREEN: |
| ----------------------------------|
| CUSTUPDATEMM 1 CUSTUPDATE1|
| CUSTUPDATEMM 2 CUSTUPDATE2|
| CUSTUPDATEMM 3 CUSTUPDATE3|
___________________________________________
Figure 9-11. Screen independence, form cross reference file
MENUNAME and FKEY are the index into the file specifying the menu that
the user is currently working with and the function key just pressed by
the user to indicate the next form to go to. SCREEN contains the name of
the next data entry form to use.
When this program begins, the element menuname contains the name of the
menu that controls its functionality. Line 11 simulates this by
prompting for the menu name. When prompted for the menu name, we typed
in CUSTUPDATEMM.
The menu we have set up allows the user to specify the next form in
either of two ways. The name of the form can be entered in the box
titled enter screen name. The [[ENTER]] enters this data and lines 30
and 31 detect this and perform the update routine. Or, the form can be
indicated via a function key. If this way is chosen, the file formxref
is accessed to determine the form name to be used by the modify routine.
Lines 34 through 39 accomplish this.
The cross reference file has a record for each function key of each form
that defines the name of the form to use when that function key is
pressed. In our example, if the user presses [[ F1 ]], then form
custupdate1 is used.
Another form for updating a customer could now be designed and used by
this program merely by recompiling the program. Of course, the form
would have to be designed in FORMSPEC and defined in the data dictionary
first.