How Registers Work [ HP Transact Reference Manual ] MPE/iX 5.0 Documentation
HP Transact Reference Manual
How Registers Work
This section discusses the use of registers with Transact verbs. It also
explains how registers work using code extracted from a Transact program.
Verbs and Registers
The LIST, DATA, PROMPT, and INPUT verbs cause data to be placed into the
various registers. The following is an overview of how these four verbs
work with the registers.
* LIST causes a data item name to be placed in the list register.
Appropriate space is allocated in the data register.
* DATA places values into space already allocated in the data
register. These values come from user input, because DATA causes
a prompt.
* PROMPT places the data item name in the list register. The value
(supplied by the user) is placed in the data register.
* INPUT places a character string (supplied by the user) into the
input register.
How LIST, DATA, and PROMPT behave is specified by their modifier. In
addition to the verbs listed above, all the database- and file-access
verbs (except PUT) and the assignment verbs LET, SET, and MOVE, update
the data register. The data access verbs get the data from files or
databases. With LET, SET, and MOVE, the data is assigned in the program.
For example, PROMPT affects only the list and data registers, whereas
PROMPT(PATH) affects the list, data, key, and argument registers. If you
only want to add data items to the list register, use LIST with no
modifier; if you only want to add a data item to the key register, use
LIST(KEY). Table 4-1 shows how verbs and modifiers work together to
affect registers.
Table 4-1. Registers Affected by Modifiers on Specific Verbs
-------------------------------------------------------
| | |
| | Register Affected |
| | by the Verb: |
| | |
-------------------------------------------------------
| | |
| Modifier | Prompt List Data Input |
| | |
-------------------------------------------------------
| | |
| none | List List Data Input (1) |
| | Data |
| | |
- - -
| PATH | List List Data - |
| | Data Key Argument |
| | Key Key (2) |
| | Argument |
| | |
- - -
| KEY | Key Key Argument - |
| | Argument Key (2) |
| | |
- - -
| MATCH | List List Data - |
| | Data Match Match |
| | Match |
| | |
- - -
| UPDATE | List List Data - |
| | Data Update Update |
| | Update |
| | |
- - -
| SET | List (1) - Data (1) - |
| | Data (1) |
| | |
- - -
| ITEM | - - Data (3) - |
| | |
-------------------------------------------------------
| |
| (1) Only if the user enters a value. |
| |
| (2) If key register is empty. |
| |
| (3) For the given data item. |
| |
-------------------------------------------------------
Sample of Transact Coding
The following code extracted from a Transact program explains how
registers work. It shows:
* Data set operations and
* Register activity.
The code is shown in total first and is then broken down by statement.
LIST CUST-NAME:
CUST-ADDRESS;
PROMPT(PATH) CUST-NO;
GET CUSTOMERS
LIST=(CUST-NAME:CUST-ADDRESS);
PROMPT(PATH) PART-NO;
PROMPT QTY-ORDERED;
LIST COST;
LIST UNIT-PRICE:
PART-DESC:
QTY-ONHAND;
GET PARTS
LIST=(UNIT-PRICE:QTY-ONHAND);
IF (QTY-ORDERED) > (QTY-ONHAND) THEN
DISPLAY "Only": QTY-ONHAND, NOHEAD: "in stock"
ELSE
DO
LET (QTY-ONHAND)=(QTY-ONHAND) - (QTY-ORDERED);
UPDATE PARTS, LIST=(QTY-ONHAND);
LET (COST) = (UNIT-PRICE) * (QTY-ORDERED);
PUT ORDERS, LIST=(CUST-NO:COST);
DOEND;
The database that is referenced contains the three data sets shown below
(PARTS, CUSTOMERS, and ORDERS). The data items in each data set are also
listed.
PARTS
M
---- PART-NO, UNIT-PRICE, PART-DESC, QTY-ONHAND
\ /
\/
CUSTOMERS
M
---- CUST-NO, CUST-NAME, CUST-ADDRESS
\ /
\/
ORDERS
D
---- PART-NO, QTY-ORDERED, COST, CUST-NO
\ /
\/
The following figures show how specific statements affect specific
registers.
LIST CUST-NAME: CUST-ADDRESS;
CUST-NAME and CUST-ADDRESS are placed in the list register and space is
reserved for their values in the data register.
PROMPT(PATH) CUST-NO;
Transact prompts the user for CUST-NO, and places the item name CUST-NO
in the list and key registers. It places the user's response in the data
and argument registers.
GET CUSTOMERS LIST=(CUST-NAME:CUST-ADDRESS);
When Transact retrieves the appropriate record from the CUSTOMERS data
set using the key and argument values, it places the values for CUST-NAME
and CUST-ADDRESS into the data register.
PROMPT(PATH) PART-NO;
Transact prompts the user for PART-NO and places the item name PART-NO
into the list and key registers overwriting any value already in the key
register. It then places the value entered by the user into the data and
argument registers overwriting the previous values in those registers.
PROMPT QTY-ORDERED;
Transact prompts the user for QTY-ORDERED, and places the item name
QTY-ORDERED in the list register. It places the value entered by the
user into the data register.
LIST COST;
Transact places COST in the list register and reserves space for its
value in the data register.
LIST UNIT-PRICE: PART-DESC: QTY-ONHAND;
UNIT-PRICE, PART-DESC, and QTY-ONHAND are placed in the list register and
space is reserved for their values in the data register.
GET PARTS, LIST=(UNIT-PRICE:QTY-ONHAND);
When the appropriate record is retrieved from the PARTS data set using
the key and argument values, values for UNIT-PRICE, PART-DESC, and
QTY-ONHAND are placed in the data register. Note that it is not
necessary to specify PART-DESC here because it is in the range between
UNIT-PRICE and QTY-ONHAND.
IF (QTY-ORDERED) > (QTY-ONHAND) THEN
DISPLAY "Only": QTY-ONHAND, NOHEAD: "in stock";
ELSE
DO
LET (QTY-ONHAND) = (QTY-ONHAND) - (QTY-ORDERED);
This statement computes a new QTY-ONHAND value and places it in the data
register.
UPDATE PARTS, LIST=(QTY-ONHAND);
Updates the PARTS data set with the new QTY-ONHAND for the part entry
that was the last one accessed by the previous GET statement.
LET (COST) = (UNIT-PRICE) * (QTY-ORDERED);
PUT ORDERS, LIST=(CUST-NO:COST);
DOEND;
Computes the cost and places it in the data register. Updates the ORDERS
data set with the values from CUST-NO through COST.
MPE/iX 5.0 Documentation