HP 3000 Manuals

File Manipulation Functions [ HP ALLBASE/4GL Developer Self-Paced Training Guide ] MPE/iX 5.0 Documentation


HP ALLBASE/4GL Developer Self-Paced Training Guide

File Manipulation Functions 

The functions for file manipulation differ according to the type of
application you are developing.

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, refer to "HP
ALLBASE/SQL Based File Manipulation Functions".

KSAM Based and HP TurboIMAGE/iX Based File Manipulation Functions 

You will create three file manipulation functions to let users add,
modify, and delete records in the product file.

The Add Function.   

The function that adds new records to the product file is called by the
product_proc process.

To create the add_product function: 

   1.  Create the add_product function using the lines shown below.

   2.  Generate the function.

Function - add_product 

1 IF V-product_status = C-record THEN
     MESSAGE prod_add_fail ; EXIT 
2 FILE *INSERT product ; ENTER 6
3 MOVE C-record V-product_status
4 MESSAGE prod_add_ok
5 EXIT 
6 MESSAGE file_error
7 EXIT 

What This Function Does 

Line 1                This step checks to see if the record to be added
                      already exists.  If it does exist, a warning
                      message is displayed and the function exits.

Line 2                If the record does not exist, control passes to
                      step 2 to add the record to the file.  Step 2
                      performs an INSERT operation to add a new record.

Lines 3, 4 and 5      Steps 3 to 5 are executed after a successful insert
                      operation.  They set the current status value,
                      display a message to confirm the successful
                      addition of the product record, and then exit the
                      function.

Line 6                If the write operation in step 2 fails, an error
                      message is displayed by step 6 before the function
                      exits.

The Modify Function.   

The function that modifies the product records is similar to the function
that adds records to the files.  The function is quite straightforward,
so the following paragraphs simply list the function.

   1.  Create the modify_product function.

   2.  Generate the function.

Function - modify_product 

1 IF V-product_status = C-no_record THEN
     MESSAGE no_product ; EXIT 
2 FILE *WRITE product ; ENTER 5
3 MESSAGE prod_modify_ok
4 EXIT 
5 MESSAGE file_error
6 EXIT 

The Delete Function.   

   1.  Create the delete_product function.

   2.  Generate the function.

Function - delete_product 

1 IF V-product_status = C-no_record THEN
     MESSAGE no_product ; EXIT 
2 FILE *DELETE product ; ENTER 6
3 MESSAGE prod_delete_ok
4 MOVE C-no_record V-product_status
5 EXIT 
6 MESSAGE prod_delete_fail
7 EXIT 

What This Function Does 

Line 1                Step 1 ensures that a product record is current.
                      If no product record is current, the function exits
                      immediately.  In this case, control returns to the
                      product_proc process.  You may want to look back at
                      the product_proc process to see what occurs next.

Line 2                Step 2 performs a DELETE operation to delete the
                      product record is deleted.  If a file error is
                      detected in this step, control passes to step 6.

Lines 3,4 and 5       Steps 3 to 5 display a confirmation message for the
                      user and set the product_status variable.  The
                      function then exits.

Lines 6 and 7         Control passes to steps 6 and 7 if a file error is
                      detected in step 2.  These steps display a message,
                      and then exit.

The following pages describe the file manipulation logic blocks required
for the HP ALLBASE/SQL based application.  If you are not developing an
ALLBASE/SQL appliction, turn to "The Next Step" to continue developing
your application.

HP ALLBASE/SQL Based File Manipulation Functions 

The Add Function.   

The function that adds new records to the product file is called by the
product_proc process.

   1.  Create the add_product function.

   2.  Generate the function.

Function - add_product 

1 IF V-product_status = C-record THEN
     MESSAGE prod_add_fail ; EXIT 
2 FILE *INSERT product ; ENTER 6
3 MOVE C-record V-product_status
4 MESSAGE prod_add_ok
5 EXIT 
6 MESSAGE file_error
7 EXIT 

What This Function Does 

Line 1                Step 1 checks to see if the record to be added
                      already exists.  If it does exist, a warning
                      message is displayed and the function exits.  If
                      the record does not exist, control passes to step 2
                      to add the record to the file.

Line 2                Step 2 contains a FILE *INSERT command to insert a
                      new record into the product table.  The FILE
                      *INSERT command inserts the current buffer contents
                      into the table as a new row.

                      The FILE *INSERT command is equivalent to the
                      following SQL command:

                      INSERT INTO sqlgrp.product
                          VALUES (:F-product_no.product,
                                  :F-description.product,
                                  :F-supplier_no.product,
                                  :F-lead_time.product);

Lines 3, 4 and 5      Steps 3 to 5 are executed after a successful insert
                      operation.  They set the current status value,
                      display a message to confirm the successful
                      addition of the product record, and then exit the
                      function.

Line 6                If the insert operation in step 2 fails, an error
                      message is displayed by step 6 before the function
                      exits.

The Modify Function.   

The function that modifies the product records is similar to the function
that adds records to the files.  The function is quite straightforward,
so the following paragraphs simply list the function.

   1.  Create the modify_product function.

   2.  Generate the function.

Function - modify_product 

1 IF V-product_status = C-no_record THEN
     MESSAGE no_product; EXIT 
2 SQL modify_product ; ENTER 5
3 MESSAGE prod_modify_ok
4 EXIT 
5 MESSAGE file_error
6 EXIT 

This function calls the SQL logic block modify_product.

SQL Logic Block - modify_product. 

This SQL logic block modifies a row in the product table.

   1.  Create the modify_product logic block.

   2.  Generate the logic block.

UPDATE sqlgrp.product SET
        description = :F-description.product,
        supplier_no = :F-supplier_no.product,
        lead-time   = :F-lead_time.product
WHERE CURRENT OF find_prod;

This SQL logic block uses a cursor to update the product table.  The name
of the cursor is find_prod.  The function product_key_read declares and
opens this cursor by calling the SQL logic block find_prod.  Note that
the cursor name is the name of the SQL logic block containing the SELECT
command that declares and opens the cursor.

The Delete Function.   

   1.  Create the delete_product function.

   2.  Generate the function.

Function - delete_product 

1 IF V-product_status = C-no_record THEN
     MESSAGE no_product ; EXIT 
2 SQL prod_del ; ENTER 6
3 MESSAGE prod_delete_ok
4 MOVE C-no_record V-product_status
5 EXIT 
6 MESSAGE prod_delete_fail
7 EXIT 

What This Function Does 

Line 1                Step 1 ensures that a product record is current.
                      If no product record is current, the function exits
                      immediately.  In this case, control returns to the
                      product_proc process.  You may want to look back at
                      the product_proc process to see what occurs next.

Line 2                Step 2 calls the SQL logic block prod_del.  This
                      SQL logic block deletes the record from the product 
                      table.  If a file error is detected in this step,
                      control passes to step 6.

Lines 3, 4 and 5      Steps 3 to 5 display a confirmation message for the
                      user and set the product_status variable.  The
                      function then exits.

Lines 6 and 7         Control passes to steps 6 and 7 if a file error is
                      detected in step 2.  These steps display a message,
                      and then exit.

SQL Logic Block prod_del 

Step 3 of the delete_product function calls the SQL logic block prod_del.
This SQL logic block deletes the record from the product table.

To delete a record: 

   1.  Create the following logic block.

   2.  Generate the logic block.

DELETE FROM sqlgrp.product
  WHERE product_no = :F-product_no.product;

This SQL logic block demonstrates the technique for deleting a record
without using a cursor.  In this case, the SQL DELETE command uses an
explicit search condition to specify the rows to be deleted.

To delete a record using a cursor: 

You can also delete a record using a cursor.  To delete an existing
record in an HP ALLBASE/SQL table using a cursor, you can use the
following procedure:

   1.  Use a SELECT command in an SQL logic block to declare and open a
       cursor on the table.

   2.  Use a FILE *NEXT command in a function or process to position the
       cursor on the first row of the active set and retrieve the record
       into the file buffer.

   3.  Use a FILE *DELETE command in a function or process to delete the
       record.

The SQL logic block containing the SELECT command, and the subsequent
FILE commands must be executed in the same process.



MPE/iX 5.0 Documentation