HP 3000 Manuals

Adding Data to a Dataset [ Getting Started With TRANSACT V ] MPE/iX 5.0 Documentation


Getting Started With TRANSACT V

Adding Data to a Dataset 

The SHOW FILE command in Dictionary/3000 reports the following for our
form called vcustomer and a dataset called customer.  This form and
dataset are used in the following examples.
________________________________________________________________________________
|                                                                              |
|     > show file                                                              |
|                        FILE vcustomer                                        |
|                                                                              |
|     FILE                 TYPE: RESPONSIBILITY:                               |
|      VCUSTOMER            FORM                                               |
|                                                                              |
|             ELEMENT(ALIAS):             PROPERTIES:         ELEMENT(PRIMARY):|
|              CUST-NO                     9 (4,0,4)           CUST-NO         |
|              NAME                        X (20,0,20)         NAME            |
|              STREET-ADDR                 X (20,0,20)         STREET-ADDR     |
|              CITY-STATE                  X (20,0,20)         CITY-STATE      |
|              ZIPCODE                     X (6,0,6)           ZIPCODE         |
|                                                                              |
|     > show file                                                              |
|                       FILE customer                                          |
|                                                                              |
|     FILE                 TYPE: RESPONSIBILITY:                               |
|      CUSTOMER             MAST                                               |
|                                                                              |
|             ELEMENT(ALIAS):             PROPERTIES:         ELEMENT(PRIMARY):|
|              CUST-NO              *      9 (4,0,4)           CUST-NO         |
|              NAME                        X (20,0,20)         NAME            |
|              STREET-ADDR                 X (20,0,20)         STREET-ADDR     |
|              CITY-STATE                  X (20,0,20)         CITY-STATE      |
|              ZIPCODE                     X (6,0,6)           ZIPCODE         |
________________________________________________________________________________

          Figure 3-1.  Dictionary definitions of customer form and dataset` 

The important things to know about the above are that for both form
vcustomer and dataset customer, the valid data items or elements are:
cust-no, name, street-addr, city-state, and zipcode.  These elements
occur in the same order in both the dataset and the form, and the
parallel data items have compatible data types and lengths.

All of the forms in our formsfile are shown in appendix H. The form
vcustomer is also shown below:
_____________________________________________________________
|                                                           |
|      vcustomer                      add a customer        |
|                                                           |
|                                                           |
|                             number  [    ]                |
|                                                           |
|                             name    [                    ]|
|                                                           |
|                             address [                    ]|
|                                                           |
|                        city,state   [                    ]|
|                                                           |
|                             zipcode [      ]              |
|                                                           |
_____________________________________________________________

          Figure 3-2.  VPLUS form for adding customer data 

The program below causes the VPLUS form vcustomer to be displayed on the
terminal.  After the operator fills in the blanks and presses [[ENTER]],
the data is added to the customer dataset.
___________________________________________________
|                                                 |
|     1     system ex20,base=orders,vpls=formfile;|
|     2     list(auto) customer;                  |
|     3     get(form) vcustomer,init;             |
|     4     put customer;                         |
___________________________________________________

          Figure 3-3.  Program accessing a VPLUS form 

1       The option VPLS= on the SYSTEM statement specifies that the name
        of our formsfile is formfile.

3       GET(FORM) displays the form on the terminal, initialize the
        fields, and accepts the data entered by the user.

The example above shows how simple it is to code a program for data
entry.  However, it only allows someone to enter data one time and then
it quits.  As we have seen in previous sections, there are several ways
to get this program to loop until we are done entering data.

First, we can make this a command-driven program.  Figure 3-4 illustrates
this.  If the user enters the command REPEAT ADD instead of just ADD, the
program will execute lines 3-5 forever.  Just as the special key ] is
used to stop processing in character mode, so the function key [[ F8 ]]
is used to stop processing in block mode.  Thus this program will
continue to execute until the user presses [[ F8 ]].
___________________________________________________
|                                                 |
|     1     system ex21,base=orders,vpls=formfile;|
|     2     $$add:                                |
|     3       list(auto) customer;                |
|     4       get(form) vcustomer,init;           |
|     5       put customer;                       |
___________________________________________________

          Figure 3-4.  Using command mode with VPLUS for looping 

Another way to get the program to loop is to build the repeating
structure into the program, using either a LEVEL or a REPEAT statement.
The following programs show these two possibilities.
___________________________________________________
|                                                 |
|     1     system ex22,base=orders,vpls=formfile;|
|     2     level;                                |
|     3       list(auto) customer;                |
|     4       get(form) vcustomer,init;           |
|     5       put customer;                       |
___________________________________________________

          Figure 3-5.  Using LEVEL with VPLUS for looping 

Lines 3-5 of the above program execute until the user presses [[ F8 ]].
___________________________________________________
|                                                 |
|     1     system ex23,base=orders,vpls=formfile;|
|     2     list(auto) customer;                  |
|     3     repeat                                |
|     4       do                                  |
|     5       get(form) vcustomer,init;           |
|     6       put customer;                       |
|     7       doend                               |
|     8     until (cust-no) = 0;                  |
|     9     exit;                                 |
___________________________________________________

          Figure 3-6.  Using REPEAT with VPLUS for looping 

The user can terminate this program either by pressing [[ENTER]] without
entering any data or by pressing [[ F8 ]].  However, [[ENTER]] causes
Transact to create a blank record with a zero customer number.

Since we probably do not want such a record in the dataset, we should
change the above program as shown in Figure 3-7 to make it more
practical.
____________________________________________________
|                                                  |
|      1     system ex24,base=orders,vpls=formfile;|
|      2     list(auto) customer;                  |
|      3     repeat                                |
|      4       do                                  |
|      5       get(form) vcustomer,init;           |
|      6       if (cust-no)                        |
|     0                                            |
|      7         then put customer;                |
|      8       doend                               |
|      9     until (cust-no) = 0;                  |
|     10     exit;                                 |
____________________________________________________

          Figure 3-7.  Preventing a blank record 


MPE/iX 5.0 Documentation