HP 3000 Manuals

Modifying the product_key_read Function [ HP ALLBASE/4GL Developer Self-Paced Training Guide ] MPE/iX 5.0 Documentation


HP ALLBASE/4GL Developer Self-Paced Training Guide

Modifying the product_key_read Function 

This function was previously called as an after function on the
product_no field on the product_scrn screen.  When you updated the screen
field details, you specified that this function is now called both prior
to and after data entry in the product_no field.

Seven steps have been added to the start of the function.  These steps
are executed before the user enters data into the field.  They test the
current record type, and perform some initialization tasks.

The other part of the function is the "after" function.  This part of the
function reads the product file to retrieve a record matching the product
number entered by the user.  This part of the function has only altered
slightly.

For KSAM based applications, the altered function, and a description of
the changes, is listed below.  Alter the function and then generate it.

For HP ALLBASE/SQL based applications, turn to HP ALLBASE/SQL Based
Applications for details of the function and a description of it.

For HP TurboIMAGE/iX based applications, turn to HP TurboIMAGE/iX Based
Applications for details of the function and a description of it.

To alter the KSAM Based Application Logic: 

   1.  Insert the first seven steps at the start of the product_key_read 
       function.

   2.  Then insert step 11, and alter step 17.

   3.  Finally, generate the function.

The details of the new steps in the function are explained after the
listing.

Function - product_key_read 

 1 IF *ENTERED *ON THEN ENTER 8
 2 IF V-current_record = C-product
     THEN WINDOW prod_wnd; EXIT 
 3 SHOW *REFRESH S-product_no S-lead_time
 4 MATH F-option_no.option + 1 = F-option_no.option
 5 SHOW *REFRESH S-option_no
 6 MOVE "5" *FIELDNO
 7 EXIT 
 8 FILE *READ product *KEY= * ; ENTER 13
 9 SHOW *REFRESH S-product_no S-lead_time
10 MOVE C-record V-product_status
11 ON 1
12 EXIT 
13 IF *IOSTATUS <> N-record_not_found
     THEN MESSAGE file_error ; SERIES 14 16 ; EXIT 
14 FILE *BUFFER product
15 CLEAR *MAP S-description S-lead_time
16 MOVE C-no_record V-product_status
17 IF V-mode <> C-add THEN MESSAGE no_product ELSE
     MESSAGE add_prod; VISIT new_option; TIE 2
18 EXIT 

The operation of this function is described below.

Lines 1 to 7 of the function form the before part of the function.  The
following notes describe the operation of these steps.

Line 1                This step tests the current state of the switch
                      *ENTERED. This indicates whether the function is
                      being executed before or after data entry to the
                      field.  If the function is being performed after
                      data entry, control passes to step 8.  Steps 2 to 7
                      are only executed when the function is called
                      before data entry in the field.

Line 2                This step tests the current record type.  If it is
                      a product record, the current window area is
                      cleared by overlaying the prod_wnd window on the
                      current screen.  Then the function exits allowing
                      normal input processing of the field to continue.

                      This is always done the very first time the screen
                      is displayed.  The prod_wnd window completes the
                      line drawing character framing around the product
                      fields and displays the heading lines for the
                      scroll area.  To the user, the screen and the
                      window appear to be a single screen.

Line 3                This step, and the next four, are only executed if
                      the current record type is an option.  In this step
                      the product screen fields are redisplayed from the
                      current product record buffer.  Since the user can
                      only access an option when a current record exists,
                      the current product record must contain valid data.

                      If the current record type is an option record, the
                      option window must already be displayed on the
                      current screen, since the user has accessed an
                      option.

Line 4                This step increments the current option number by
                      1.

Line 5                This step refreshes the option number field on the
                      option window.

Line 6                This step moves the number of the Option Number 
                      field to the communications area field *FIELDNO.
                      When this function exits, the screen processor
                      immediately passes control to that field.  Refer to
                      the screen processing rules in Chapter 7 if you
                      want to review this.

                      The Option Number field is field number 1 of the
                      window on which it was painted.  However, when HP
                      ALLBASE/4GL displays a window, the window field
                      numbering is adjusted to start after the number of
                      the last field on the original data screen.  In
                      this case field number 1 on the window becomes
                      field number 5 on the base screen.

Line 7                The function exits at this point, completing the
                      before function processing.  Processing of the
                      current field finishes, and the cursor moves to the
                      Option Number field on the window.

                      Control passes to the second part of the function
                      when the function is executed after data entry in
                      the field.  Refer to page 9-39 to look back at this
                      part of the function.

Line 11               User switch 1 is set on.  This switch is used by
                      the scrolling system to determine if any scrolling
                      has already been done for this product.

Line 17               This step contains an extra step:  VISIT 
                      new_option.  This function displays the new_option 
                      window to allow the user to enter the details of
                      option 000 for a new product.

Now turn to Function - new_option, to continue developing the
application.

To modify the HP ALLBASE/SQL Logic: 

   1.  Insert the first seven steps at the start of the product_key_read 
       function.

   2.  Insert step 12.

   3.  Alter step 18.

   4.  Generate the function.

The details of the new steps in the function are explained after the
listing.

 1 IF *ENTERED *ON THEN ENTER 8
 2 IF V-current_record = C-product
     THEN WINDOW prod_wnd ; EXIT 
 3 SHOW *REFRESH S-product_no S-lead_time
 4 MATH F-option_no.option + 1 = F-option_no.option
 5 SHOW *REFRESH S-option_no
 6 MOVE "5" *FIELDNO
 7 EXIT 
 8 SQL find_prod
 9 FILE *NEXT product ; ENTER 14
10 SHOW *REFRESH S-product_no S-lead_time
11 MOVE C-record V-product_status
12 ON 1
13 EXIT 
14 IF *IOSTATUS <> N-end_of_file
     THEN MESSAGE file_error ; SERIES 15 17 ; EXIT 
15 FILE *BUFFER product
16 CLEAR *MAP S-description S-lead_time
17 MOVE C-no_record V-product_status
18 IF V-mode <> C-add THEN MESSAGE no_product
     ELSE MESSAGE add_prod; VISIT new_option; TIE 2
19 EXIT 

Lines 1 to 7 of the function form the before part of the function.  The
following notes describe the operation of these steps.

Line 1                This step tests the current state of the switch
                      *ENTERED. This indicates whether the function is
                      being executed before or after data entry to the
                      field.  If the function is being performed after
                      data entry, control passes to step 8.  Steps 2 to 7
                      are only executed when the function is called
                      before data entry in the field.

Line 2                This step tests the current record type.  If it is
                      a product record, the current window area is
                      cleared by overlaying the prod_wnd window on the
                      current screen.  Then the function exits allowing
                      normal input processing of the field to continue.

                      This is always done the very first time the screen
                      is displayed.  The prod_wnd window completes the
                      line drawing character framing around the product
                      fields and displays the heading lines for the
                      scroll area.  To the user, the screen and the
                      window appear to be a single screen.

Line 3                This step, and the next four, are only executed if
                      the current record type is an option.  In this step
                      the product screen fields are redisplayed from the
                      current product record buffer.  Since the user can
                      only access an option when a current record exists,
                      the current product record must contain valid data.

                      If the current record type is an option record, the
                      option window must already be displayed on the
                      current screen, since the user has accessed an
                      option.

Line 4                This step increments the current option number by
                      1.

Line 5                This step refreshes the option number field on the
                      option window.

Line 6                This step moves the number of the Option Number 
                      field to the communications area field *FIELDNO.
                      When this function exits, the screen processor
                      immediately passes control to that field.  Refer to
                      the screen processing rules in Chapter 7 if you
                      want to review this.

                      The Option Number field is field number 1 of the
                      window on which it was painted.  However, when HP
                      ALLBASE/4GL displays a window, the window field
                      numbering is adjusted to start after the number of
                      the last field on the original data screen.  In
                      this case field number 1 on the window becomes
                      field number 5 on the base screen.

Line 8                The function exits at this point, completing the
                      before function processing.  Processing of the
                      current field finishes, and the cursor moves to the
                      Option Number field on the window.

Control passes to the second part of the function when the function is
executed after data entry in the field.  Refer to chapter 7 to look back
at this part of the function.

Line 12               User switch 1 is set on.  This switch is used by
                      the scrolling system to determine if any scrolling
                      has already been done for this product.

Line 18               This step contains an extra step:  VISIT 
                      new_option.  This function displays the new_option 
                      window to allow the user to enter the details of
                      option 000 for a new product.

Now turn to Function - new_option, to continue developing the
application.

To modify HP TurboIMAGE/iX logic: 

   1.  Insert the first seven steps at the start of the product_key_read 
       function.

   2.  Insert step 12.

   3.  Alter step 18.

   4.  Generate the function.

The details of the new steps in the function are explained after the
listing.

Function - product_key_read 

 1 IF *ENTERED *ON THEN ENTER 8
 2 IF V-current_record = C-product
     THEN WINDOW prod_wnd ; EXIT 
 3 SHOW *REFRESH S-product_no S-lead_time
 4 MATH F-option_no.option + 1 = F-option_no.option
 5 SHOW *REFRESH S-option_no
 6 MOVE "5" *FIELDNO
 7 EXIT 
 8 DM IMAGE *LOCK :D-traindb :R-product
 9 FILE *READ product *KEY= * ; ENTER 14
10 SHOW *REFRESH S-product_no S-lead_time
11 MOVE C-record V-product_status
12 ON 1
13 EXIT 
14 IF *IOSTATUS <> N-record_not_found
     THEN MESSAGE file_error ; SERIES 15 17 ; EXIT 
15 FILE *BUFFER product
16 CLEAR *MAP S-description S-lead_time
17 MOVE C-no_record V-product_status
18 IF V-mode <> C-add THEN MESSAGE no_product
     ELSE MESSAGE add_prod; VISIT new_option; TIE 2
19 EXIT 

Lines 1 to 7 of the function form the before part of the function.  The
following notes describe the operation of these steps.

Line 1                This step tests the current state of the switch
                      *ENTERED. This indicates whether the function is
                      being executed before or after data entry to the
                      field.  If the function is being performed after
                      data entry, control passes to step 8.  Steps 2 to 7
                      are only executed when the function is called
                      before data entry in the field.

Line 2                This step tests the current record type.  If it is
                      a product record, the current window area is
                      cleared by overlaying the prod_wnd window on the
                      current screen.  Then the function exits allowing
                      normal input processing of the field to continue.

                      This is always done the very first time the screen
                      is displayed.  The prod_wnd window completes the
                      line drawing character framing around the product
                      fields and displays the heading lines for the
                      scroll area.  To the user, the screen and the
                      window appear to be a single screen.

Line 3                This step, and the next four, are only executed if
                      the current record type is an option.  In this step
                      the product screen fields are redisplayed from the
                      current product record buffer.  Since the user can
                      only access an option when a current record exists,
                      the current product record must contain valid data.

                      If the current record type is an option record, the
                      option window must already be displayed on the
                      current screen, since the user has accessed an
                      option.

Line 4                This step increments the current option number by
                      1.

Line 5                This step refreshes the option number field on the
                      option window.

Line 6                This step moves the number of the Option Number 
                      field to the communications area field *FIELDNO.
                      When this function exits, the screen processor
                      immediately passes control to that field.  Refer to
                      the screen processing rules in Chapter 7 if you
                      want to review this.

                      The Option Number field is field number 1 of the
                      window on which it was painted.  However, when HP
                      ALLBASE/4GL displays a window, the window field
                      numbering is adjusted to start after the number of
                      the last field on the original data screen.  In
                      this case field number 1 on the window becomes
                      field number 5 on the base screen.

Line 7                The function exits at this point, completing the
                      before function processing.  Processing of the
                      current field finishes, and the cursor moves to the
                      Option Number field on the window.

                      Control passes to the second part of the function
                      when the function is executed after data entry in
                      the field.  Refer to page 9-39 to look back at this
                      part of the function.

Line 8                User switch 1 is set on.  This switch is used by
                      the scrolling system to determine if any scrolling
                      has already been done for this product.

Line 9                This step contains an extra step:  VISIT 
                      new_option.  This function displays the new_option 
                      window to allow the user to enter the details of
                      option 000 for a new product.

                      This function is executed by a VISIT command in the
                      product_key_read function.  It is called when the
                      user is adding a new product.  It displays the
                      window new_option to allow the user to enter the
                      details of option 000 for a new product.  Since the
                      new_option window contains required fields, the
                      user cannot commit the current screen without
                      completing the option details.

To create the new_option function: 

   1.  Create this function using the following commands. 

   2.  Generate the function.

1 MOVE C-no_record V-option_status
2 FILE *BUFFER option
3 WINDOW new_option
4 EXIT 

The new_option function is described below.

Line 1                This step sets the variable V-option_status to
                      indicate that there is no current record.

Line 2                The FILE *BUFFER command clears the option file
                      record buffer.

Line 3                This step displays the new_option window on the
                      product screen.

Line 4                The function exits.

Creating the option_key_read Function 

The option_key_read function is called as an after function on the
option_no field on the option window.  The function performs some
preliminary checking and initialization, and then reads the option file
or table for a record matching the option number entered by the user.

If you are creating the KSAM based application, continue reading below.

If you are creating the HP ALLBASE/SQL based application, turn to "To
create the HP ALLBASE/SQL function".

If you are creating the HP TurboIMAGE/iX based application, turn to "To
create the HP TurboIMAGE/iX function".

To create the KSAM function: 

   1.  Create this function now, using the description below.

   2.  When finished, generate the function.

 1 IF V-current_record = C-product THEN EXIT 
 2 IF V-mode = C-delete & * = N-zero
     THEN MESSAGE del_prod_opt; EXIT 
 3 LINK 2 *S01 * F-option_key.option
 4 FILE *READ option ; ENTER 8
 5 SHOW *REFRESH S-option_no S-unit_measure
 6 MOVE C-record V-option_status
 7 EXIT 
 8 IF *IOSTATUS <> N-record_not_found
     THEN MESSAGE file_error ; SERIES 9 11 ; EXIT 
 9 FILE *BUFFER option
10 CLEAR *S 6 9
11 MOVE C-no_record V-option_status
12 IF V-mode <> C-add THEN MESSAGE opt_not_exist
     ELSE MESSAGE add_option
13 EXIT 

The function operates as described below.

Line 1                This ensures that the function is not performed if
                      the current record being handled is a product 
                      record.  There is only one situation where this may
                      occur.  This situation was described when you
                      defined the functions associated with the function
                      keys.

Line 2                This step tests the current mode, and the contents
                      of the option_no field.  If the mode is delete and
                      the option number is 000, the user is attempting to
                      delete option number zero.  This is not permitted,
                      so this step displays an error message.

Line 3                This step introduces a number of new items.  The
                      LINK command concatenates a number of fields into
                      another field.  In this example, the LINK command
                      concatenates the fields *S01 and * into the
                      option_key field on the option file buffer.  This
                      step builds a unique primary key to access the
                      option file.

                      In this command, * is a reference to the contents
                      of the current screen field.

                      Similarly, *S01 is a reference to the contents of
                      the first field on the current screen.  On this
                      particular screen it is the product_no field.

                      The window for the LINK command does not prompt you
                      for the number of items to be linked together.  HP
                      ALLBASE/4GL calculates the number of link fields
                      you enter, and then automatically inserts the
                      correct link count value.  The LINK command also
                      has an optional joiner character which is inserted
                      between each field as it is linked.  This example
                      does not need a joiner character so you can leave
                      the field blank.

Line 4                This step reads the option file.  Since the
                      previous step moved the key value to the
                      appropriate field in the file buffer, there is no
                      need to specify the key for this file read
                      operation.  In all other respects this command is
                      identical to the file read statements that you have
                      already used.

Line 5                If the specified record is found, the SHOW command
                      displays the record buffer contents in the
                      appropriate fields on the screen.

Line 6                An option record has been found, so the
                      option_status variable is set to reflect this.

Line 7                The function exits.

Line 8                This step starts the file read error section of the
                      function.  If the file error is caused by any
                      condition other than a record not found condition,
                      it displays an error message, clears the screen and
                      file buffers, sets the status variable, and then
                      exits.

Line 9                This step clears the option file buffer.

Line 10               This step clears the option window fields.

Line 11               The option_status variable is set to show that a
                      record was not successfully read.

Line 12               The mode is checked and an appropriate message is
                      displayed.

Line 13               The function exits.

Now turn to "Creating Messages for the Logic Blocks" to continue
developing your application.

To create the HP ALLBASE/SQL function: 

   1.  Create this function using the description below.

   2.  When finished, generate the function.

 1 IF V-current_record = C-product THEN EXIT 
 2 IF V-mode = C-delete & * = N-zero THEN
    MESSAGE del_prod_opt ; EXIT 
 3 MOVE * V-option_no
 4 SQL option_key_sel
 5 FILE *NEXT option ; ENTER 9
 6 SHOW *REFRESH S-option_no S-unit_measure
 7 MOVE C-record V-option_status
 8 EXIT 
 9 IF *IOSTATUS <> N-end_of_file THEN MESSAGE file_error ;
     SERIES 10 12 ; EXIT 
10 FILE *BUFFER option
11 CLEAR *S 6 9
12 MOVE C-no_record V-option_status
13 IF V-mode <> C-add THEN MESSAGE opt_not_exist
     ELSE MESSAGE add_option
14 EXIT 

Line 1                This ensures that the function is not performed if
                      the current record being handled is a product 
                      record.

                      There is only one situation where this may occur.
                      When a user presses the  Product  function key,
                      this action causes a field commit for the current
                      field.  In this case, the function called from the
                      function key sets V-current_record to C-product so
                      that the option_key_read function is not fully
                      completed.

Line 2                This step tests the current mode, and the contents
                      of the option_no field.  If the mode is delete and
                      the option number is 000, the user is attempting to
                      delete option number zero.  This is not permitted,
                      so this step displays an error message.

Line 3                This step moves the value in the current field (the
                      option_no field on the option window) to the
                      variable V-option_no.  The SQL logic block
                      option_key_sel that is called by step 4 uses this
                      variable.

Line 4                This step calls the SQL logic block option_key_sel.
                      You will define this SQL logic block after
                      completing the option_key_read function.

Line 5                This step reads the next record in the option file.

Line 6                If the specified record is found, the SHOW command
                      displays the record buffer contents in the
                      appropriate fields on the screen.

Line 7                An option record has been found, so the
                      option_status variable is set to reflect this.

Line 8                The function exits.

Line 9                This step starts the file read error section of the
                      function.  If the file error is caused by any
                      condition other than an end of file condition, it
                      displays an error message, clears the screen and
                      file buffers, sets the status variable, and then
                      exits.

Line 10               This step clears the option file buffer.

Line 11               This step clears the option window fields.

Line 12               The option_status variable is set to show that a
                      record was not successfully read.

Line 13               The mode is checked and an appropriate message is
                      displayed.

Line 14               The function exits.

This application does not require a unique key for the option table since
the opt_key_sel SQL logic block uses a combined search condition to find
the required record in the option table.

To create the option_key_sel logic block: 

   1.  Create this SQL logic block as shown below.

   2.  Then generate the logic block.

SELECT :option FROM sqlgrp.option
   WHERE product_no = :F-product_no.product
   AND option_no = :V-option_no
FOR UPDATE OF product_no, option_no, description, cost,
   quantity, unit_measure;

This SQL logic block declares and opens a cursor on the option table.
The SQL logic block also shows the use of an AND clause to specify a
compound search condition.  In this case, the SELECT command locates a
row in the table with the product_no field equal to the current value in
the product_no field on the product file buffer, and the option_no field
equal to the value in the variable V-option_no.  The FILE *NEXT command
at step 5 of the option_key_read function retrieves the first record in
the active set for the cursor.

This example demonstrates the host variable referencing technique for SQL
logic blocks.  In this SQL logic block, the term :F-product_no.product is
a reference to the field product_no on the file record buffer product,
and the term :V-option_no is a reference to the variable option_no.  Note
that you must use the full reference for the data item, and prefix the
reference with a colon (:).

Now turn to "Creating Messages for the Logic Block," to continue
developing your application.

To create the HP TurboIMAGE/iX function: 

   1.  Create the function using the description shown below.

   2.  Then generate the function.

 1 IF V-current_record = C-product THEN EXIT 
 2 IF V-mode = C-delete & * = N-zero
     THEN MESSAGE del_prod_opt; EXIT 
 3 DM IMAGE *LOCK :D-traindb :R-option
 4 LINK 2 *S01 * F-option_key.option
 5 FILE *READ option ; ENTER 9
 6 SHOW *REFRESH S-option_no S-unit_measure
 7 MOVE C-record V-option_status
 8 EXIT 
 9 IF *IOSTATUS <> N-record_not_found
     THEN MESSAGE file_error ; SERIES 10 12 ; EXIT 
10 FILE *BUFFER option
11 CLEAR *S 6 9
12 MOVE C-no_record V-option_status
13 IF V-mode <> C-add THEN MESSAGE opt_not_exist
     ELSE MESSAGE add_option
14 EXIT 

The function operates as described below.

Line 1                This ensures that the function is not performed if
                      the current record being handled is a product 
                      record.  There is only one situation where this may
                      occur.  This situation was described when you
                      defined the functions associated with the function
                      keys.

Line 2                This step places an HP TurboIMAGE/iX logical lock
                      on the option data set.  This lock is released in
                      the product_proc process.

Line 3                This step tests the current mode, and the contents
                      of the option_no field.  If the mode is delete and
                      the option number is 000, the user is attempting to
                      delete option number zero.  This is not permitted,
                      so this step displays an error message.

Line 4                This step introduces a number of new items.  The
                      LINK command concatenates a number of fields into
                      another field.  In this example, the LINK command
                      concatenates the fields *S01 and * into the
                      option_key field on the option file buffer.  This
                      step builds a unique primary key to access the
                      option file.

                      In this command, * is a reference to the contents
                      of the current screen field.

                      Similarly, *S01 is a reference to the contents of
                      the first field on the current screen.  On this
                      particular screen it is the product_no field.

                      The window for the LINK command does not prompt you
                      for the number of items to be linked together.  HP
                      ALLBASE/4GL calculates the number of link fields
                      you enter, and then automatically inserts the
                      correct link count value.  The LINK command also
                      has an optional joiner character which is inserted
                      between each field as it is linked.  This example
                      does not need a joiner character so you can leave
                      the field blank.

Line 5                This step reads the option data set.  Since the
                      previous step moved the key value to the
                      appropriate field in the file buffer, there is no
                      need to specify the key for this file read
                      operation.  In all other respects this command is
                      identical to the file read statements that you have
                      already used.

Line 6                If the specified record is found, the SHOW command
                      displays the record buffer contents in the
                      appropriate fields on the screen.

Line 7                An option record has been found, so the
                      option_status variable is set to reflect this.

Line 8                The function exits.

Line 9                This step starts the file read error section of the
                      function.  If the file error is caused by any
                      condition other than a record not found condition,
                      it displays an error message, clears the screen and
                      file buffers, sets the status variable, and then
                      exits.

Line 10               This step clears the option file buffer.

Line 11               This step clears the option window fields.

Line 12               The option_status variable is set to show that a
                      record was not successfully read.

Line 13               The mode variable is checked and an appropriate
                      message is displayed.

Line 14               The function exits.

You have now completed the screen field functions.



MPE/iX 5.0 Documentation