Getting Started with TRANSACT (32247-90007)
Chapter 2 47
Using Character Mode I/O
Adding Data to a Dataset
Figure 2-13. Program to Change Key Values Using REPLACE
5 The KEY option automatically sets up the IMAGE key, preparing us to
retrieve the customer record. When the KEY option can be used, the DATA
verb performs the input of data and also sets the IMAGE key for database
retrieval. Note that we are also supplying our own prompt.
8 DATA(UPDATE) tells Transact that we really do want to change a key
field in the record. CHECKNOT verifies that the new customer number
does not already exist in the dataset.
9 REPLACE causes the new customer record to be added before the old
customer record is deleted.
In this example, we did not allow any other fields to be updated. We could have, by
prompting with DATA(UPDATE) for each of the fields. In other words, when you use the
REPLACE verb, you must give Transact the new values, using DATA(UPDATE) or its
equivalent. Any data items not specified this way, retain the values from the original
record.
Figure 2-11 used the DELETE verb to change a key value. Figure 2-14 is an example of a
program that uses the DELETE verb to simply delete records.
1 system ex14,base=orders(";")
2 set(delimiter) "/";
3 list(auto) customer;
4 level;
5 data(key) cust-no ("enter old cust-no");
6 get customer;
7 display;
8 data(update) cust-no ("enter new cust-no")
,checknot=customer;
9 replace customer;
10 end;