HP 3000 Manuals

Updating Data in a Dataset [ Getting Started With TRANSACT V ] MPE/iX 5.0 Documentation


Getting Started With TRANSACT V

Updating Data in a Dataset 

Now that we have added data to the customer dataset, how do we go about
updating this data?  This section shows two approaches.  The only
difference between the two is the way in which we ask for input of the
cust-no.

The first example uses the form vcustomer for both input of the cust-no
and input of the data.  The second example sets up a separate form
vcustno for entering the customer number.  It then uses form vcustomer
for data entry.
___________________________________________________
|                                                 |
|     1     system ex25,base=orders,vpls=formfile;|
|     2     level;                                |
|     3       list(auto) customer;                |
|     4       get(form) vcustomer,init;           |
|     5       set(key) list (cust-no);            |
|     6       get customer;                       |
|     7       put(form) vcustomer;                |
|     8       get(form) vcustomer;                |
|     9       update customer;                    |
___________________________________________________

          Figure 3-8.  Using LEVEL with VPLUS to update data 

4       First, GET(FORM) gets the cust-no for the record that we want to
        update.

5       SET establishes the key or IMAGE path into the customer dataset
        to retrieve the record to be updated.

6       GET retrieves the record from the customer dataset.

7       PUT(FORM) displays the information that currently exists for the
        customer on the screen.  At this point the operator changes the
        field(s) that need to be updated.

8       GET(FORM) accepts the data from the screen.

9       UPDATE puts the record in the dataset customer.

As in previous examples, we can exit the LEVEL repeating loop at any time
merely by pressing [[ F8 ]].

This same program could be coded using the REPEAT construct as follows:
____________________________________________________
|                                                  |
|      1     system ex26,base=orders,vpls=formfile;|
|      2     list(auto) customer;                  |
|      3     repeat                                |
|      4       do                                  |
|      5       get(form) vcustomer,init;           |
|      6       if (cust-no) <> 0                   |
|      7         then                              |
|      8           do                              |
|      9           set(key) list (cust-no);        |
|     10           get customer;                   |
|     11           put(form) vcustomer;            |
|     12           get(form) vcustomer;            |
|     13           update customer;                |
|     14           doend;                          |
|     15       doend                               |
|     16     until (cust-no) = 0;                  |
____________________________________________________

          Figure 3-9.  Using REPEAT with VPLUS to update data 

6       The IF statement instructs Transact to quit if a customer number
        is not input.  If one is input, then the DO/DOEND block of
        statements retrieve the information, display it on the screen,
        accept the changed data, and update the dataset.

As was indicated earlier, another way to get the cust-no is to introduce
a separate form to ask for it first.  Let's assume that we have set up
this second form in the dictionary and in the formsfile.  The dictionary
listing for this form and the format of the form are shown below.
________________________________________________________________________________
|                                                                              |
|     show file                                                                |
|                       FILE vcustno                                           |
|                                                                              |
|     FILE                 TYPE: RESPONSIBILITY:                               |
|      VCUSTNO              FORM                                               |
|                                                                              |
|             ELEMENT(ALIAS):             PROPERTIES:         ELEMENT(PRIMARY):|
|              CUST-NO                     9 (4,0,4)           CUST-NO         |
________________________________________________________________________________

          Figure 3-10.  Dictionary definition of customer number form 
_______________________________________________________________
|                                                             |
|      vcustno                    update customer data        |
|                                                             |
|                                                             |
|                       enter customer number to update [    ]|
|                                                             |
|                                                             |
_______________________________________________________________

          Figure 3-11.  VPLUS form for customer number 

To implement this, we need only change the name of the form in line 5 of
Figure 3-9 above and we now have a program working with two forms.
____________________________________________________
|                                                  |
|      1     system ex27,base=orders,vpls=formfile;|
|      2     list(auto) customer;                  |
|      3     repeat                                |
|      4       do                                  |
|      5       get(form) vcustno,init;             |
|      6       if (cust-no) <> 0                   |
|      7         then                              |
|      8           do                              |
|      9           set(key) list (cust-no);        |
|     10           get customer;                   |
|     11           put(form) vcustomer;            |
|     12           get(form) vcustomer;            |
|     13           update customer;                |
|     14           doend;                          |
|     15       doend                               |
|     16     until (cust-no) = 0;                  |
____________________________________________________

          Figure 3-12.  Program accessing two VPLUS forms 

5       GET(FORM) displays the new form and accepts the cust-no from the
        user.

11      PUT(FORM) replaces the form vcustno with the form vcustomer,
        displays the current customer data, and allows the user to change
        it.


MPE/iX 5.0 Documentation