Calculated Items [ HP ALLBASE/4GL Developer Self-Paced Training Guide ] MPE/iX 5.0 Documentation
HP ALLBASE/4GL Developer Self-Paced Training Guide
Calculated Items
A calculated item is a special type of variable. A calculated item
implicitly refers to a function. When HP ALLBASE/4GL encounters a
reference to a calculated item, it automatically executes the function to
determine the value of the calculated item.
A calculated item can be defined as a single CALC command, or it may be
extended to use as many lines of logic in the function as you require.
Menu Path
To access the calculated items screen:
1. From the main menu, select the Dictionary option.
2. Select the Storage Items option.
3. Choose Calculated Items.
Screen Description
This screen allows you to define a calculated item. You will define the
item's basic characteristics and a single CALC statement to derive the
value of the calculated item. Defining a calculated item automatically
creates a function of the same name. This function is automatically
executed each time the item is accessed.
If the item you are defining requires more than a single CALC statement,
you can subsequently call up the function in the function details screen.
A calculated item defined this way is known as an extended calculated
item.
The screen below shows the completed screen after defining a calculated
item for the KSAM version of the application.
Calculated Items Screen
To enter the field values:
Field Entry Explanation
---------------------------------------------------------------------------------------
Item Name option_cost This is the name of the calculated item
that you are defining. HP ALLBASE/4GL
automatically creates a function with the
same name for the necessary logic that is
needed behind the item. Even if the
calculated item only requires one line of
logic to calculate its value, HP
ALLBASE/4GL still creates the function. A
calculated item cannot have the same name
as an existing function in the same
application.
Length 12 The length of the calculated item can be up
to 99 characters.
Edit Code N This is a standard edit code.
Number of Decimal 2 This specifies the maximum number of
Places decimal places assigned to the item. It is
only relevant for numeric fields.
Pad Character Leave blank. As for variables, alphanumeric calculated
items are left justified and numeric items
are right justified. The pad character
entered here replaces any leading or
trailing spaces remaining as a result of
the justification.
Field Entry Explanation
---------------------------------------------------------------------------------------
The CALC For KSAM based and HP When you leave the pad character field you
command TurboIMAGE/iX based will see that the word CALC is displayed to
applications, enter: the left of the input area occupied by the
cursor. This input area allows you to
F-cost.option x enter the statement to calculate the value
F-quantity.option = of the item. Refer to the HP ALLBASE/4GL
U-option_cost Developer Reference Manual for further
details about the CALC command.
For HP ALLBASE/SQL based
applications, enter: Note that the destination of the CALC
command is the calculated item itself.
F-cost.prod_opt x This is how a value is assigned to a
F-quantity.prod_opt = calculated item.
U-option_cost
Note If you extend a calculated item, you
can use any logic block commands including
a visit to another function. However, the
only function that can assign a value to a
calculated item is the function with the
same name as the calculated item. If you
attempt to assign a value to a calculated
item from any other source, the application
will abort at run-time.
If you don't want to use a CALC statement,
or wish to extend this function you can
leave the CALC statement blank. You can
then define the logic for the item by
calling up the function with the function
details screen.
Description Enter a suitable description.
To complete the entries:
1. Press the Commit Data function key when you have finished
creating the calculated item.
A calculated item automatically creates a function of the same
name. Pressing the Commit Data function key generates the
function automatically. If any errors occur during the generation
operation, they are displayed in the normal way. Correct any
errors using either the calculated item screen or the function
details screen.
You may wish to examine the logic block created by the CALC item
by looking at it using the function details screen.
Generating the Report
Once you have defined the calculated item, generate the prod_opt report.
Now you will need to alter the main menu so that you can execute the
report.
Altering the Main Menu
This is what the main menu will look like when you have repainted it.
Repainted Main Menu
To alter the main menu:
1. Call up the main menu in the screen painter.
2. Add the following action item to the screen.
Where you place it on the screen is up to you. The screen image
above is one suggested format for the menu.
Type Name Text
R (report) prod_opt Stock Report
3. When you have defined this item, exit from the painter.
HP ALLBASE/4GL saves the menu as you exit.
Running the Report
When you have altered the main menu, you may run your application and
test the report. You defined that the report printer destination was
printer 1. Ask your HP ALLBASE/4GL administrator what has been
defined as printer 1 for your system, or, if you have access to the
administ application, you may check for yourself by selecting System
Specifications on the main menu, and then System Definition on the
System-Wide Specifications menu. This displays the System Definition
screen, which lists the printers defined for HP ALLBASE/4GL.
The training application is now functionally complete.
MPE/iX 5.0 Documentation