Defining the Add Functions [ HP ALLBASE/4GL Developer Self-Paced Training Guide ] MPE/iX 5.0 Documentation
HP ALLBASE/4GL Developer Self-Paced Training Guide
Defining the Add Functions
The functions that add new records to the product and option files are
called by the prod_opt_update decision table, which you have just
completed.
Function - add_product
The add_product function already exists, but requires some modification.
To modify the add-product function:
1. Insert the following step at step 5 of the add_product function:
VISIT add_option
This step calls the add_option function, which is described below.
2. Then regenerate the function.
Function - add_option
If you are developing the KSAM based application or the HP TurboIMAGE/iX
based application, read on below.
If you are developing the HP ALLBASE/SQL based application, turn to HP
ALLBASE/SQL Based Applications.
KSAM Based and HP TurboIMAGE/iX Based Applications
The add_option function contains the following steps:
1 IF V-option_status = C-record THEN
MESSAGE option_warn ; EXIT
2 MOVE S-product_no F-product_no.option
3 LINKLOOP 2 F-product_no.option 1 F-option_key.option
4 FILE *INSERT option; ENTER 8
5 MESSAGE opt_add_ok
6 IF F-option_no.option = N-zero THEN MOVE C-option V-current_record;
WINDOW option; MOVE "1" *NEWTIE
7 EXIT
8 MESSAGE file_error
9 EXIT
The add_option function operates as follows:
Line 1 Like the first step of the add_product function,
this step makes sure that the option does not
already exist. If the option does exist, this step
displays a warning message and the function exits.
Line 2 This step moves the current product number into the
product_no field on the option file buffer. This
is necessary because the buffer was cleared before
the new data was entered.
Line 3 This step builds the unique option file key. There
are several ways that this could have been
achieved. This particular method uses the LINKLOOP
command to build the key.
Each ... LOOP command performs a repeated
operation on successive fields in a file record,
screen, or the scratch pad. You must specify the
number of times the command is performed, the field
that the operation starts on, and the step factor
to indicate the next field or fields to be operated
on.
In this step, the LINKLOOP command is performed
twice, as shown by the first number after
the LINKLOOP command. The first field is
F-product_no.option. The step factor of 1
indicates that the next field is the next
operand. The result is placed in the field
F-option_key.option.
The same result could also be achieved with the
command:
LINKLOOP 2 *S01 4 F-option_key.option
This command takes the first screen field as the
first operand and links it to a screen field four
fields further on. On this particular screen, this
is the option number field.
Line 4 The new option is added to the option file. If a
file access error is detected, control passes to
step 8.
Line 5 If the file insert operation in step 4 is
successful, the user is informed that the file was
updated.
Line 6 If the option number written to the file was 000,
the user has just added a new product. The current
record type is set to option. This step then
displays the option window and sets the value in
the communication area field *NEWTIE to 1. This is
equivalent to the command TIE 1, and passes control
to field number 1 on the product screen when it is
next displayed.
Line 7 The function exits.
Line 8 If a file access error was detected in step 4, the
user is informed by a message.
Line 9 The function exits.
Now turn to The Option_Number Function to continue developing the
application.
HP ALLBASE/SQL Based Applications
1 IF V-option_status = C-record
THEN MESSAGE option_warn ; EXIT
2 MOVE S-product_no F-product_no.option
3 FILE *INSERT option ; ENTER 7
4 MESSAGE opt_add_ok
5 IF F-option_no.option = N-zero THEN
MOVE C-option V-current_record ;
WINDOW option ; MOVE "1" *NEWTIE
6 EXIT
7 MESSAGE file_error
8 EXIT
The add_option function operates as follows:
Line 1 Like the first step of the add_product function,
this step makes sure that the record does not
already exist. If the record does exist, this step
displays a warning message and the function exits.
Line 2 This step moves the current product number into the
product_no field on the option file buffer. This
is necessary because the buffer was cleared before
the new data was entered.
Line 3 The new option is inserted into the option file.
If a file access error is detected, control passes
to step 7.
The FILE *INSERT command in this function inserts
the current buffer contents into the option table
as a new row. The FILE *INSERT command is
equivalent to the following SQL command:
INSERT INTO sqlgrp.option
VALUES (:F-product_no.option,
:F-option_no.option,
:F-description.option,
:F-cost.option,
:F-quantity.option),
:F-unit_measure.option);
Line 4 If the file insert operation in step 3 is
successful, the user is informed that the file was
updated.
Line 5 If the option number written to the file was 000,
then the user has just added a new product. The
current record type is set to option. This step
then displays the option window and sets the value
in the communication area field *NEWTIE to 1. This
is equivalent to the command TIE 1, and passes
control to field number 1 on the product screen
when it is next displayed.
Line 6 The function exits.
Line 7 If a file access error was detected in step 3, the
user is informed by a message.
Line 8 The function exits.
Modifying the option_number Function
The option_number function is called as a prior function from the
option_no field on a new_option window. This window is executed when the
user enters the details for option number 000 for a new product. The
option_no function contains the following commands.
If you are developing the KSAM based application or the HP ALLBASE/SQL
based application, continue reading below.
If you are developing the HP TurboIMAGE/iX based application, turn to HP
TurboIMAGE/iX Based Applicationsfor instructions.
To modify the option-number function for KSAM and HP ALLBASE/SQL
Applications:
1. Create the option_number function, using the logic block listed
below.
2. Generate the completed function.
1 FILE *BUFFER option
2 CLEAR *S 6 8
3 MOVE N-zero F-option_no.option
The option_no function operates like this:
Line 1 This step clears the option file buffer of
any data from a previous update.
Line 2 This step clears the screen fields from the
description field to the qty_on_hand field.
Line 3 *This step moves the value 000 to the
option_no field on the option file buffer.
3. Turn to "Creating the Appropriate Messages" to continue developing
your application.
To modify the option-number function for HP TurboIMAGE/iX
Applications:
1. Create and generate this function now.
1 FILE *BUFFER option
2 CLEAR *S 6 8
3 MOVE N-zero F-option_no.option
4 DM IMAGE *LOCK :D-traindb :R-option
The option_no function operates like this:
Line 1 This step clears the option file buffer of
any data from a previous update.
Line 2 This step clears the screen fields from the
description field to the qty_on_hand field.
Line 3 This step moves the value 000 to the
option_no field on the option file buffer.
Line 4 This step places an HP TurboIMAGE/iX logical
lock on the option data set. This lock is
released by the product_proc process.
The option_key_read function normally places
a lock on this data set before adding an
option record, but that function is not
executed for the first option for each
product. This function is always executed
before the first option for a product is
added.
2. Create the messages that accompany this logic.
Creating the Appropriate Messages
The add_option function needs the following messages.
1. Create these messages.
a. Message - option_warn
Name option_warn
Type WARN
Contents "This option already exists."
"It cannot be added."
b. Message - opt_add_ok
Name opt_add_ok
Type MESS
Contents "New option, number"
F-option_no.option
", has been created."
MPE/iX 5.0 Documentation