Creating the Delete Functions [ HP ALLBASE/4GL Developer Self-Paced Training Guide ] MPE/iX 5.0 Documentation
HP ALLBASE/4GL Developer Self-Paced Training Guide
Creating the Delete Functions
The delete functions are different for each data manager.
If you are developing the KSAM based application, read on below.
If you are developing the HP ALLBASE/SQL based applications, turn to HP
ALLBASE/SQL Based Applications.
If you are developing the HP TurboIMAGE/iX based application, turn to HP
TurboIMAGE/iX Based Applications.
Creating the Delete Functions for KSAM Based Applications
You must create four functions to delete product and option records. The
processing for this operation is a little different from earlier parts of
the application. The delete functions require the user to verify that
the selected option or product is the correct item to be deleted. You
will use a query message to do this.
When the user selects a product for deletion, the application first
checks to see if there are any options other than option number 000
associated with the product. If options do exist, the user is alerted
and asked to confirm the deletion of the options.
The user must delete the options before the product can be deleted. When
a product is deleted, option number 000 for the product is also deleted.
If option number 000 for a product does not exist when it is first
accessed, the user is alerted and given the option of deleting the
product.
Modifying the delete_product function.
To modify the function:
1. Modify the delete_product function, using the logic commands shown
below.
2. Regenerate the function.
Function - delete_product.
1 DEFINE %PROD% .product
2 IF V-product_status = C-no_record THEN
MESSAGE no_product ; EXIT
3 LINK 2 F-product_no%PROD% "000" F-option_key.option
4 FILE *READ option ; ENTER 17
5 VISIT del_all_options
6 IF 8 *ON THEN ENTER 15
7 MESSAGE delete_prod
8 IF V-confirm <> "Y" THEN ENTER 15
9 SERIES 3 3
10 FILE *DELETE option ; EXIT
11 FILE *DELETE product ; EXIT
12 MESSAGE prod_delete_ok
13 MOVE C-no_record V-product_status
14 EXIT
15 MESSAGE prod_delete_fail
16 EXIT
17 VISIT del_corrupt_prod
18 EXIT
The modified delete_product function operates as follows:
Line 1 This defines an identifier for the product
file.
Line 2 This step ensures that a product record is
current.
Line 3 This step links the current product number
and the number 000 into the key field on the
option file record buffer.
Line 4 This step reads the option file for a record
with the key value set up in step 3. If the
record is not found, the file may be
corrupted. Every product must have an
option number 000. Control passes to step
17 if an error is detected.
Line 5 The del_all_options function deletes all of
the options for the current product. The
del_all_options uses switch number 8 to
indicate its exit status. If switch number
8 is off when the function exits, all
options other than option number 000 for the
current product have been deleted
successfully.
Line 6 This step tests the status of switch number
8. If this switch is on, the options for
the product have not been deleted. Control
passes to step 15 to display a message to
the user.
Line 7 The message delete_prod will be created
soon. This message asks the user to confirm
the deletion of the product. The user's
response is returned to the variable
confirm.
Line 8 If the user's response to the query message
is "Y", control passes to step 9. If the
user's response is anything else, control
passes to step 15.
Line 9 This step uses the SERIES command to execute
step 3 again to rebuild the key for option
number 000 for the current product. This is
necessary since the del_all_options function
may change the option file buffer contents.
Line 10 The record for option 000 is deleted.
Line 11 The product record is deleted.
If a file error is detected in either of
these steps, the function exits immediately.
In this case, control returns to the product
process, and the error condition processing
is executed. You may want to look back at
the product process to see how this is done.
Lines 12, 13 and 14 These steps display a confirmation message
for the user and set the product_status
variable. The function then exits.
Lines 15 and 16 Control passes to these steps if the user
does not confirm the deletion of the
product, or the options for the product are
not deleted successfully. These steps
display a message, and then exit.
Lines 17 Control passes to this step if the first
read of the option file does not succeed.
This can only occur if option number 000 for
the current product does not exist,
indicating corruption of the option file or
the product file. This step visits the
function del_corrupt_prod to delete the
current product record, and any option
records for the product.
Lines 18 The function exits.
3. Add following message, which is required by the delete_product
function:
Message - delete_prod
Name delete_prod
Type QUERY
Response Item V-confirm
Contents "Enter 'Y' to confirm "
"deletion of this product."
Modifying the del_all_options function.
The del_all_options function deletes all options for a product except
option number 000. It is called from the delete_product function.
The del_all_options function uses switch number 8 to indicate its exit
status. If the options for a product are deleted successfully, switch
number 8 is set off when the function exits. Otherwise, switch number 8
is set on.
To modify the del_all_options function:
1. Create the del_all_options function using the following commands.
2. Generate the function.
1 ON 8
2 FILE *NEXT option ; ENTER 10
3 IF F-product_no.option <> F-product_no.product
THEN OFF 8 ; EXIT
4 MESSAGE delete_options
5 IF V-confirm <> "Y" THEN EXIT
6 SCROLL 6 F-option_no.option 4 F-description.option 8 "deleted"
7 FILE *DELETE option
8 FILE *NEXT option ; ENTER 10
9 IF F-product_no.option <> F-product_no.product THEN
ENTER 12 ELSE ENTER 6
10 IF *IOSTATUS <> N-end_of_file THEN MESSAGE file_error ; EXIT
11 SCROLL 9 "***** All Options Deleted for Product # " & F-product_no.product" *****"
12 OFF 8
13 EXIT
The delete_all_options function operates as follows:
Line 1 This step turns switch number 8 on. If the
function deletes the option records
successfully, this switch is set off before
the function exits.
Line 2 The FILE *NEXT command reads the next record
from the option file. Since this function
is called after the FILE *READ command in
the delete_product function, the FILE *NEXT
command attempts to retrieve the record for
option number 001. If the FILE *NEXT
command encounters an error, control passes
to step 10.
Line 3 s step tests the value in the product_no
field on the record just read. If this
value is not equal to the product number of
the current product, the record just read is
an option record for a different product.
In this case, the current product does not
have any options other than option number
000, so no options require deletion. In
this case, switch number 8 is set off and
the function exits.
If the record just read is an option record
for the current product (that is, the value
in the product_no field matches the current
product number), the product must have at
least one option other than option number
000.
Line 4 This step displays a query message that asks
the user to confirm the deletion of the
options for this product.
Line 5 If the user enters "Y" in response to the
message, control passes to step 6.
Otherwise, the function exits.
Lines 6 to 9 These steps form a loop that deletes all the
option records for the current product.
This command displays a line of data
containing six spaces, the current option
number, four further spaces, the description
of the option, eight further spaces, and the
word "deleted".
Line 10 This step deletes the current option file
record.
Line 11 This step reads the next record in the
option file. If an error is encountered,
control passes to step 10.
Line 12 If the value in the product_no field in the
record just read does not match the number
for the current product, the record just
read is an option record for a different
product. This means all options for the
current product have been deleted. In this
case, control passes to step 11. Otherwise,
control returns to step 6 to continue the
option deletion loop.
The option deletion loop continues until
there are no options for the current product
left in the option data file. Control
passes to step 12 when the last option
record for the current product has been
deleted.
Line 13 Control passes to this step if an error
occurs in either of the FILE *NEXT commands.
This step tests the value in *IOSTATUS. If
this value is not equal to 19110 (the value
of the constant end_of_file), indicating the
FILE *NEXT command encountered an end of
file condition, control passes to step 12.
An end of file condition may occur after the
last record in the file has been deleted.
This situation does not indicate an
incorrect condition.
If the file error is caused by any condition
other than encountering an end of file
condition, then a message is displayed and
the function exits.
Line 14 The user is informed that all of the options
for the current product have been deleted.
Line 15 This step sets switch number 8 off to
indicate that all options for the current
product have been deleted successfully.
Line 16 The function exits.
3. The delete_all_options function requires one message. Create this
message now.
Message - delete_options
Name delete_options
Type QUERY
Response Item V-confirm
Contents "This product has options. "
"Enter 'Y' to confirm their deletion."
Creating the del_corrupt_prod function.
The del_corrupt_prod function is called from the delete_product function
if the first read of the option file fails. This can only occur if the
record for option number 000 does not exist, indicating that the record
for the product or option is corrupted.
The del_corrupt_prod function deletes the product and option records for
a corrupted product record.
To create the del_corrupt_prod function:
1. Create this function as shown below.
2. Generate the function.
1 MESSAGE corrupt_prod_del
2 IF V-confirm <> "Y" THEN MESSAGE prod_delete_fail ; EXIT
3 FILE *FIND option *KEY= F-product_no.product ; ENTER 14
4 FILE *NEXT option ; ENTER 14
5 IF F-product_no.option <> F-product_no.product
THEN ENTER 9
6 SCROLL 2 F-option_no.option 4 F-description.option
8 "deleted"
7 FILE *DELETE option
8 ENTER 4
9 FILE *DELETE product ; ENTER 12
10 MOVE C-no_record V-product_status
11 EXIT
12 MESSAGE file_error
13 EXIT
14 IF *IOSTATUS = N-record_not_found | *IOSTATUS = N-end_of_file
THEN ENTER 9 ELSE MESSAGE file_error ; EXIT
The del_corrupt_prod function operates as follows.
Line 1 This step displays a query message asking
the user to confirm the deletion of the
product and options.
Line 2 If the user enters "Y" in response to the
message, control passes to step 3.
Otherwise, the prod_delete_fail message is
displayed and the function exits.
Line 3 This step uses the FILE *FIND command to
search the file for a record with a key
value equal to or greater than the key
specified. In this case, the command uses
the current product number as the key for
the search. This command finds the first
existing option record for the current
product since the option key is a
concatenation of the product number and the
option number.
If the FILE *FIND command does not find a
record, control passes to step 14.
Line 4 The FILE *NEXT command in this step
retrieves the record into the file buffer.
Control passes to step 14 if the record is
not retrieved successfully. Steps 5 to 9
form a loop that deletes all the existing
options for the current product.
Line 5 This step tests the value in the product_no
field for the record just read. If the
record just read is an option record for a
different product, no option records exist
for the current product or all option
records for the product have been deleted.
In this case, control passes to step 9 to
delete the product record.
Line 6 This step scrolls the current option
details, then the word "deleted" in the
scroll area of the current screen.
Line 7 This step deletes the current record from
the option file.
Line 8 Control is passed to step 5 to continue the
option deletion loop.
Line 9 Control passes to this step after the last
option record for the current product has
been deleted. This step deletes the current
product record from the product file. If an
error occurs during this operation, control
passes to step 13.
Line 10 This step sets the value of the variable
product_status to indicate that there is no
current product record.
Line 11 The function exits at this point.
Line 12 Control passes to this step if a file access
error is detected in step 10. This step
displays the file error message.
Line 13 The function exits.
Line 14 Control passes to this step if a file access
error is detected in step 4 or step 5. If
the file error is caused by failure to find
a record or reaching the end of the file,
control passes to step 10 to delete the
current product record. This situation can
occur if the first FILE *FIND command fails
to find any options for the current product,
or the FILE *NEXT command in step 5 reaches
the end of file after the last record in the
file has been deleted.
If the file access has failed for any other
reason, the file_error message is displayed
and the function exits.
3. You must now create the corrupt_prod_del message. This message is
displayed by the del_corrupt_prod function.
Message - corrupt_prod_del
Name corrupt_prod_del
Type QUERY
Response Item V-confirm
Contents "Product/option records corrupted. "
"Enter 'Y' to confirm their deletion."
This completes the items for the product deletion part of this
application. Now the option deletion function must be created.
Deleting Options.
Function - delete_option
The option deletion operation is more straightforward and should not
require any explanation.
To create the delete_option function:
1. Enter the following steps:
1 IF V-option_status = C-no_record THEN
MESSAGE no_option_warn ; EXIT
2 MESSAGE delete_option
3 IF V-confirm <> "Y" THEN MESSAGE opt_delete_fail ; EXIT
4 FILE *DELETE option
5 MESSAGE opt_delete_ok
6 MOVE C-no_record V-option_status
7 EXIT
2. Create the messages needed for this function.
a. Message - delete_option
The delete_option function requires the following messages:
Name delete_option
Type QUERY
Response Item V-confirm
Contents "Enter 'Y' to confirm "
"deletion of this option."
b. Message - opt_delete_ok
Name opt_delete_ok
Type MESS
Contents "Option has been deleted."
c. Message - opt_delete_fail
Name opt_delete_fail
Type WARN
Contents "Option has NOT been deleted."
The next section contains instructions for readers creating the HP
ALLBASE/SQL based application. Turn to the Summary to continue with this
training guide.
Creating Functions for HP ALLBASE/SQL Based Applications
Deleting a Product.
The delete_product function is an existing function that will be modified
to check for the existence of option records other than option number 000
for the current product. If they exist, it displays a message requesting
the user to confirm their deletion. The function then requests the user
to confirm the deletion of the product. If the user chooses to delete
the product, the function deletes the record for option 000 and deletes
the product record.
The function is called from the prod_opt_update decision table.
This function calls three SQL logic blocks. They are opt_sel, opt_del,
and prod_del. The operation of the function and these SQL logic blocks
is explained below.
This function also requires some new messages, and the delete_prod
message must be modified.
To modify the delete_product function:
1. Modify and regenerate the function and the SQL logic blocks as
shown below.
1 IF V-product_status = C-no_record THEN
MESSAGE no_product ; EXIT
2 SQL opt_sel ; ENTER 15
3 FILE *NEXT option ; ENTER 14
4 MESSAGE delete_options
5 IF V-confirm <> "Y" THEN ENTER 16
6 SQL opt_del ; ENTER 15
7 MESSAGE all_opt_deleted
8 MESSAGE delete_prod
9 IF V-confirm <> "Y" THEN ENTER 16
10 SQL prod_del ; ENTER 15
11 MESSAGE prod_delete_ok
12 MOVE C-no_record V-product_status
13 EXIT
14 IF *IOSTATUS = N-end_of_file THEN ENTER 8
15 MESSAGE file_error
16 MESSAGE prod_delete_fail
17 EXIT
The delete_product function operates as follows:
Line 1 This step ensures that a product record is
current.
Line 2 This step calls the SQL logic block opt_sel,
which declares and opens a cursor for the
option table. If an error occurs, control
passes to step 15.
Line 3 This step retrieves the first record for the
cursor. Control passes to step 14 if an
error is detected.
Lines 4 and 5 If options do exist for the product, the
user is requested to confirm their deletion.
If the user confirms the deletion of the
options, the function passes control to step
6. Otherwise, control passes to step 16.
Lines 6 and 7 The opt_del SQL logic block deletes all of
the options for the current product, and the
ALL_opt_deleted message is displayed.
Line 8 The message delete_prod will be added soon.
This message asks the user to confirm the
deletion of the product. The user's
response is returned to the variable
confirm.
Line 9 If the user's response to the query message
is "Y", control passes to step 10. If the
user's response is anything else, control
passes to step 16.
Line 10 The product record is deleted when this
function calls the prod_del SQL logic block.
Lines 11, 12 and 13 These steps display a confirmation message
for the user and set the product_status
variable. The function then exits.
Line 14 Control passes to this step if no option
records are found for the product. If HP
ALLBASE/SQL reaches the start or the end of
the file, the function passes control to
step 8 to delete a product.
Lines 15 and 16 Control passes to these steps if the user
does not confirm the deletion of the
product, or the options or the product are
not deleted successfully. These steps
display a message.
Line 17 The function exits.
2. The delete_product function requires you to add the following
QUERY type message. Create this message now.
Message - delete_prod
Name delete_prod
Type QUERY
Response Item V-confirm
Contents "Enter 'Y' to confirm "
"deletion of this product."
3. Now create the following messages:
a. Message - delete_options
Name delete_options
Type QUERY
Response Item V-confirm
Contents "This product has options. "
"Enter 'Y' to confirm their deletion."
b. Message - all_opt_deleted
Name all_opt_deleted
Type MESS
Contents "Number of options deleted for product
"
F-product_no.product
" is " *ROWCOUNT
Modifying SQL Logic Blocks.
The ALL_opt_deleted message introduces a new communication area field.
After any operation that modifies a table, HP ALLBASE/SQL returns a value
to *ROWCOUNT to indicate the number of rows that are affected by the
command. In this example, the value in *ROWCOUNT is the number of rows
deleted from the option table.
To modify the SQL logic blocks:
1. Modify the blocks as indicated below:
a. SQL Logic Block - opt_sel
The SQL command in step 2 executes the SQL logic block
opt_sel. This SQL logic block contains the following
command:
SELECT :option FROM sqlgrp.option
WHERE product_no = :F-product_no.product
AND option_no > :N-zero;
This SQL logic block declares and opens a cursor on the
option table. The active set for this cursor is the set of
records for the current product that have an option number
that is strictly greater than zero. Note that this select
command does not find option number zero for a product. If
a product has no options other than the base option (number
000), the active set for this cursor is empty.
The FILE *NEXT command in step 3 of the delete_product
function retrieves the first record for the cursor. If
this command is successful, steps 4 to 7 of the function
display a message, and then delete the options if the user
enters "Y" in response to the message.
If the FILE *NEXT command encounters an end-of-file
condition without retrieving a record, the SELECT command
has not found any option records for the product. In this
case, control passes to step 14 and then to step 8, to
allow the user to delete the product. If the file error is
due to any condition other than encountering the end of
file, control passes to step 15.
b. SQL Logic Block - opt_del
The SQL logic block called by step 6 of the function
deletes records from the option table. The opt_del SQL
logic block contains the following command:
DELETE FROM sqlgrp.option
WHERE product_no = :F-product_no.product
AND option_no > 000;
This SQL block demonstrates the technique for deleting
records without using a cursor. In this case, the SQL
DELETE command uses an explicit search condition to specify
the rows to be deleted.
c. SQL Logic Block prod_del
Step 10 of the delete_product function calls the SQL logic
block prod_del. This SQL logic block deletes the record
for option number 000 from the option table, and then
deletes the product record from the product table. The
second part of this SQL logic block already exists.
Modify the prod_del SQL logic block so that it contains the
following commands:
DELETE FROM sqlgrp.option
WHERE product_no = :F-product_no.product;
DELETE FROM sqlgrp.product
WHERE product_no = :F-product_no.product;
This SQL logic block demonstrates the use of more than one command in an
SQL logic block. An SQL logic block can contain up to eight SQL commands
if it does not contain a SELECT command. Note that you must terminate
each command with a semicolon.
Deleting Options
The technique for deleting option records is much simpler than the method
for deleting a product.
To enter the delete_option function:
The delete_option function is called by the prod_opt_update decision
table.
Function - delete_option
The option deletion operation is more straightforward and should not
require any explanation.
1. Enter the following steps:
1 IF V-option_status = C-no_record THEN
MESSAGE no_option_warn ; EXIT
2 MESSAGE delete_option
3 IF V-confirm <> "Y" THEN MESSAGE opt_delete_fail ; EXIT
4 FILE *DELETE option ; ENTER 8
5 MESSAGE opt_delete_ok
6 MOVE C-no_record V-option_status
7 EXIT
8 MESSAGE file_error
9 EXIT
This function uses a FILE *DELETE command to delete a record from
the option table. This command is equivalent to the following SQL
command:
DELETE FROM sqlgrp.option
WHERE CURRENT OF option_key_sel;
The cursor is declared and opened by the SQL logic block
option_key_sel called by the function option_key_read. Note that
the cursor name is the same as the name of the SQL logic block
that declares and opens the cursor.
2. Create the following messages:
a. Message - delete_option
Name delete_option
Type QUERY
Response Item V-confirm
Contents "Enter 'Y' to confirm "
"deletion of this option."
b. Message - opt_delete_ok
Name opt_delete_ok
Type MESS
Contents "Option has been deleted."
c. Message - opt_delete_fail
Name opt_delete_fail
Type WARN
Contents "Option has NOT been deleted."
The next section contains instructions for readers creating the HP
TurboIMAGE/iX based application. Turn to the Summary to continue with
this training guide.
Creating the Functions for HP TurboIMAGE/iX Based Applications
You must create four functions to delete product and option records. The
processing for this operation is a little different from earlier parts of
the application. The delete functions require the user to verify that
the selected option or product is the correct item to be deleted. You
will use a query message to do this.
When the user selects a product for deletion, the application first
checks to see if there are any options other than option number 000
associated with the product. If options do exist, the user is alerted
and asked to confirm the deletion of the options.
The user must delete the options before the product can be deleted. When
a product is deleted, option number 000 for the product is also deleted.
If option number 000 for a product does not exist when it is first
accessed, the user is alerted and given the option of deleting the
product.
To modify the delete_product function:
1. Modify the delete_product function so that it contains the
following steps
2. Then regenerate the function.
1 DEFINE %PROD% .product
2 IF V-product_status = C-no_record THEN
MESSAGE no_product ; EXIT
3 LINK 2 F-product_no%PROD% "000" F-option_key.option
4 DM IMAGE *LOCK :D-traindb :R-option
5 FILE *READ option *INDEX = product_no
*KEY = S-product_no.product_scrn ; ENTER 18
6 VISIT del_all_options
7 IF 8 *ON THEN ENTER 16
8 MESSAGE delete_prod
9 IF V-confirm <> "Y" THEN ENTER 16
10 SERIES 5 5
11 FILE *DELETE option ; EXIT
12 FILE *DELETE product ; EXIT
13 MESSAGE prod_delete_ok
14 MOVE C-no_record V-product_status
15 EXIT
16 MESSAGE prod_delete_fail
17 EXIT
18 VISIT del_corrupt_prod
19 EXIT
The modified delete_product function operates as follows:
Line 1 This defines an identifier for the product
file.
Line 2 This step ensures that a product record is
current.
Line 3 This step links the current product number
and the number 000 into the key field on the
option file record buffer.
Line 4 This step locks the option file before it is
read.
Line 5 This step reads the option file for a record
with the key value set up in step 3. If the
record is not found, the file may be
corrupted. Every product must have an
option number 000. Control passes to step
18 if an error is detected.
Line 6 The del_all_options function deletes all of
the options for the current product. The
del_all_options uses switch number 8 to
indicate its exit status. If switch number
8 is off when the function exits, all
options other than option number 000 for the
current product have been deleted
successfully.
Line 7 This step tests the status of switch number
8. If this switch is on, the options for
the product have not been deleted. Control
passes to step 16 to display a message to
the user.
Line 8 The message delete_prod will be created
soon. This message asks the user to confirm
the deletion of the product. The user's
response is returned to the variable
confirm.
Line 9 If the user's response to the query message
is "Y", control passes to step 10. If the
user's response is anything else, control
passes to step 16.
Line 10 This step uses the SERIES command to execute
step 4 again to place a record in the file
record buffer. This is necessary since the
del_all_options function ends with no record
in the file record buffer.
Line 11 The record for option 000 is deleted.
Line 12 The product record is deleted.
If a file error is detected in either of
these steps, the function exits immediately.
In this case, control returns to the product
process, and the error condition processing
is executed. You may want to look back at
the product process to see how this is done.
Lines 13, 14 and 15 These steps display a confirmation message
for the user and set the product_status
variable. The function then exits.
16 and 17 Control passes to these steps if the user
does not confirm the deletion of the
product, or the options for the product are
not deleted successfully. These steps
display a message, and then exit.
Line 18 Control passes to this step if the first
read of the option file does not succeed.
This can only occur if option number 000 for
the current product does not exist,
indicating corruption of the option file or
the product file. This step visits the
function del_corrupt_prod to delete the
current product record, and any option
records for the product.
Line 19 The function exits.
3. Add the following message, which is required by the delete_product
function:
Message - delete_prod
Name delete_prod
Type QUERY
Response Item V-confirm
Contents "Enter 'Y' to confirm "
"deletion of this product."
To modify the del_all_options function:
The del_all_options function deletes all options for a product except
option number 000. It is called from the delete_product function.
The del_all_options function uses switch number 8 to indicate its exit
status. If the options for a product are deleted successfully, switch
number 8 is set off when the function exits. Otherwise, switch number 8
is set on.
The del_all_options function contains the following commands.
1. Create and generate this function now.
1 ON 8
2 FILE *NEXT option ; ENTER 10
3 MESSAGE delete_options
4 IF V-confirm <> "Y" THEN EXIT
5 DM IMAGE *LOCK :D-traindb :R-option
6 IF F-option_no.option <> "000" THEN FILE *DELETE option
7 SCROLL 6 F-option_no.option 4 F-description.option 8 "deleted"
8 FILE *NEXT option ; ENTER 10
9 ENTER 6
10 IF *IOSTATUS <> N-end_of_file & *IOSTATUS <> N-end_of_chain
THEN MESSAGE file_error ; EXIT
11 SCROLL 9 "***** All Options Deleted for Product # "
F-product_no.product "*****"
12 OFF 8
13 EXIT
The delete_all_options function operates as follows:
Line 1 This step turns switch number 8 on. If the
function deletes the option records
successfully, this switch is set off before
the function exits.
Line 2 The FILE *NEXT command reads the next record
from the option file. Since this function
is called after the FILE *READ command in
the delete_product function, the FILE *NEXT
command attempts to retrieve the record for
option number 001. If the FILE *NEXT
command encounters an error, control passes
to step 10.
Line 3 This step displays a query message that asks
the user to confirm the deletion of the
options for this product.
Line 4 If the user enters "Y" in response to the
message, control passes to step 5.
Otherwise, the function exits.
Line 5 This step places an HP TurboIMAGE/iX logical
lock on the option data set. This lock is
released by the product_proc process.
Line 6 Steps 7 to 9 form a loop that deletes all
the option records for the current product.
This command tests to ensure that the option
number does not equal "000". If it does not
equal "000", then the option is deleted.
Line 7 This step displays a line of data containing
six spaces, the current option number, four
further spaces, the description of the
option, eight further spaces, and the word
"deleted".
Line 8 This step reads the next record in the
option file. If an error is encountered,
control passes to step 10.
Line 9 If no errors are encountered in the previous
step, there are more option records for this
product. Control returns to step 6 to
continue the option deletion loop.
The option deletion loop continues until
there are no options for the current product
left in the option data file. Control
passes to step 10 when the last option
record for the current product has been
deleted.
Line 10 Control passes to this step if an error
occurs in the FILE *NEXT command. This step
tests the value in *IOSTATUS. If this value
is not equal to 19110 (the value of the
constant end_of_file) or 19115 (the value of
the constant end_of_chain), control passes
to step 11. An end of file condition may
occur after the last record in the file has
been deleted, and an end of chain condition
may occur after the last record in a chain
of linked detail data set records has been
deleted. This situation does not indicate
an incorrect condition.
If the file error is caused by any other
condition, then a message is displayed and
the function exits.
Line 11 The user is informed that all of the options
for the current product have been deleted.
Line 12 This step sets switch number 8 off to
indicate that all options for the current
product have been deleted successfully.
Line 13 The function exits.
2. This function requires one message. Create this message.
Message - delete_options
Name delete_options
Type QUERY
Response Item V-confirm
Contents "This product has options. "
"Enter 'Y' to confirm their deletion."
To create the del_corrupt_prod function:
The del_corrupt_prod function is called from the delete_product function
if the first read of the option file fails. This can only occur if the
record for option number 000 does not exist, indicating that the record
for the product or option is corrupted.
The del_corrupt_prod function deletes the product and option records for
a corrupted product record.
The del_corrupt_prod function contains the following commands.
1. Create and generate the function as shown below.
1 MESSAGE corrupt_prod_del
2 IF V-confirm <> "Y" THEN MESSAGE prod_delete_fail ; EXIT
3 DM IMAGE *LOCK :D-traindb :R-option
4 FILE *FIND option *KEY= F-product_no.product ; ENTER 15
5 FILE *NEXT option ; ENTER 15
6 IF F-product_no.option <> F-product_no.product
THEN ENTER 10
7 SCROLL 2 F-option_no.option 4 F-description.option
8 "deleted"
8 FILE *DELETE option
9 ENTER 5
10 FILE *DELETE product ; ENTER 13
11 MOVE C-no_record V-product_status
12 EXIT
13 MESSAGE file_error
14 EXIT
15 IF *IOSTATUS = N-record_not_found | *IOSTATUS = N-end_of_file
THEN ENTER 10 ELSE MESSAGE file_error ; EXIT
The del_corrupt_prod function operates as follows.
Line 1 This step displays a query message asking
the user to confirm the deletion of the
product and options.
Line 2 If the user enters "Y" in response to the
message, control passes to step 3.
Otherwise, the prod_delete_fail message is
displayed and the function exits.
Line 3 This step places an HP TurboIMAGE/iX logical
lock on the option file. This lock is
released by the product_proc process.
Line 4 This step uses the FILE *FIND command to
search the file for a record with a key
value equal to or greater than the key
specified. In this case, the command uses
the current product number as the key for
the search. This command finds the first
existing option record for the current
product since the option key is a
concatenation of the product number and the
option number.
If the FILE *FIND command does not find a
record, control passes to step 15.
Line 5 The FILE *NEXT command in this step
retrieves the record into the file buffer.
Control passes to step 15 if the record is
not retrieved successfully. Steps 5 to 9
form a loop that deletes all the existing
options for the current product.
Line 6 This step tests the value in the product_no
field for the record just read. If the
record just read is an option record for a
different product, no option records exist
for the current product or all option
records for the product have been deleted.
In this case, control passes to step 9 to
delete the product record.
Line 7 This step scrolls the current option
details, then the word "deleted" in the
scroll area of the current screen.
Line 8 This step deletes the current record from
the option file.
Line 9 Control is passed to step 5 to continue the
option deletion loop.
Line 10 Control passes to this step after the last
option record for the current product has
been deleted. This step deletes the current
product record from the product file. If an
error occurs during this operation, control
passes to step 13.
Line 11 This step sets the value of the variable
product_status to indicate that there is no
current product record.
Line 12 The function exits at this point.
Line 13 Control passes to this step if a file access
error is detected in step 10. This step
displays the file error message.
Line 14 The function exits.
Line 15 Control passes to this step if a file access
error is detected in step 4 or step 5. If
the file error is caused by failure to find
a record or reaching the end of the file,
control passes to step 10 to delete the
current product record. This situation can
occur if the first FILE *FIND command fails
to find any options for the current product,
or the FILE *NEXT command in step 5 reaches
the end of file after the last record in the
file has been deleted.
If the file access has failed for any other
reason, the file_error message is displayed
and the function exits.
2. Create the corrupt_prod_del message. This message is displayed by
the del_corrupt_prod function.
Message - corrupt_prod_del
Name corrupt_prod_del
Type QUERY
Response Item V-confirm
Contents "Product/option records corrupted. "
"Enter 'Y' to confirm their deletion."
This completes the items for the product deletion part of this
application. Now the option deletion function must be created.
Deleting Options.
Function - delete_option
The option deletion operation is more straightforward and should not
require any explanation.
1. Create the delete_option function. It contains the following
steps:
1 IF V-option_status = C-no_record THEN
MESSAGE no_option_warn ; EXIT
2 MESSAGE delete_option
3 IF V-confirm <> "Y" THEN MESSAGE opt_delete_fail ; EXIT
4 FILE *DELETE option
5 MESSAGE opt_delete_ok
6 MOVE C-no_record V-option_status
7 EXIT
2. Create the delete_option function messages as shown below.
a. Message - delete_option
Name delete_option
Type QUERY
Response Item V-confirm
Contents "Enter 'Y' to confirm "
"deletion of this option."
b. Message - opt_delete_ok
Name opt_delete_ok
Type MESS
Contents "Option has been deleted."
c. Message - opt_delete_fail
Name opt_delete_fail
Type WARN
Contents "Option has NOT been deleted."
MPE/iX 5.0 Documentation