HP 3000 Manuals

Functions [ HP ALLBASE/BRW Reference Manual ] MPE/iX 5.0 Documentation


HP ALLBASE/BRW Reference Manual

Functions 

A function is like a program procedure or subroutine.  You can use a
function to avoid typing complicated formulas.  Functions can be used in
formulas or conditions; however, functions cannot be used as items.  Each
function must have at least one argument, and can have up to nine.  An
argument is a value that can be passed to the function when it is run.
Function arguments can (optionally) be used in the function formula.

When you call a function, HP ALLBASE/BRW assigns the values you supply in
place of the arguments in the function calculation, performs the
calculation, and returns a value as the result of the function.  This
result is then used in your calculation in place of the function name.
The value returned can be of any HP ALLBASE/BRW type (Real, Integer,
Numeric, String, Date, or Time).

Table Functions 

Table functions are functions that you define for use in table calculated
items, relation conditions, and other table functions.  The Table
Function screen and the Table Function Formula screen are used to define
table functions.

Characteristics 

Table functions have these characteristics:   

   *   They are only used in other calculation formulas in the same table
       (that is, table calculated items, other table function, and
       relation conditions defined in the same table).

   *   They can be calculated from function arguments, source table
       items, calculated items or other functions defined in the same
       table, parameters, or constants.

   *   They can return results of any one of the HP ALLBASE/BRW types:

              N - fixed-point numeric

              R - floating-point real

              I - integer

              S - string

              D - date

              T - time

Restrictions 

Table Functions have these restrictions: 

   *   They cannot be used in any formulas except for table calculated
       items, relation conditions, and other table functions defined for
       the same table.

Example 

Here is an example of a table function, AMOUNT-IN-WORDS:

[]
This is the Table Function screen for item AMOUNT-IN-WORDS. It has one Numeric argument, AMOUNT, and returns a String-type result. It has been defined from the table FINAL. Therefore it can only be used in table calculated items, relation conditions, and other table functions for table FINAL.
[]
In this example, the formula for AMOUNT-IN-WORDS is defined on the Table Function Formula screen. This formula can use any of the arguments and operators allowed in the Calculation Language, and must obey its syntax rules. See the Syntax Diagram and Syntax Rules sections for more details. With this formula, you can call AMOUNT-IN-WORDS from any formula defined for the table FINAL. You must supply an Integer for AMOUNT, and HP ALLBASE/BRW returns the string depending on the value of AMOUNT. Layout Functions Layout functions are similar to table functions but are defined for the report layout. The Layout Function screen and the Layout Function Formula screen are used to define layout functions. Characteristics Layout functions have these characteristics: * They can only be used in the report layout inside other calculation formulas for layout calculated items, other layout functions, suppress lineset, and suppress line conditions. * They are the same types as table functions. * They are calculated from function arguments, items, layout calculated items, other layout functions, parameters, or constants. Global Functions Global functions are similar to table and layout functions but are defined for more than one report. The Global Function screen and the Global Function Formula screen are used to define Global Functions in the BRWSETUP program. Characteristics Global functions have these characteristics: * They may be used in any calculation formula or condition in a report. * They can return results of any one of the HP ALLBASE/BRW types. * They are calculated from function arguments, other global functions, or constants.
NOTE For better performance: You can improve calculation performance by using calculated items instead of functions if the functions are always used with the same arguments. Consider these points: * Calculated items have a single value per record, and so are calculated once per record regardless of how many times they are used. * Functions are calculated each time the function is used because results depend on the values of the function arguments.
Functions as Arguments You can use a function as an argument in a calculation. Such functions can be user-defined table functions, layout functions, global functions, or HP ALLBASE/BRW standard functions. User-defined functions are described in the "Formulas and Conditions" section of this chapter, and Standard Functions are described in the "Standard Functions" section of this chapter. You reference (or call) a function in a calculation by the function name, followed by a value for each function argument. The values must be in parentheses and separated by commas. When calling a function, you must supply a value for every function argument. In the example below, VARIANCE-% has two arguments and AMOUNT-IN-WORDS one. VARIANCE-% (ACTUAL-AMOUNT, BUDGET-AMOUNT) AMOUNT-IN-000'S (AMOUNT) HP ALLBASE/BRW calls the function, assigns the value(s) to the function argument(s), performs the function's formula, and returns the result of the formula to your calculation. This resulting value is then used in your calculation in place of the function name. The value returned can be of any HP ALLBASE/BRW type (Real, Integer, Numeric, String, Date, or Time). Function Arguments in Calculations Every function has at least one argument. Function arguments can be used in the function formula. Example In this example, the function AMOUNT-IN-000'S is defined: AMOUNT-IN-000'S (AMOUNT) (AMOUNT) is the function argument and is of the Numeric type. You substitute a value for it when you call the function. Within the function, the value is referred to by the function argument name. That is, the formula for AMOUNT-IN-000'S can be something like this example: If AMOUNT > 1000 Then "OVER ONE THOUSAND" Else "LESS THAN ONE THOUSAND" You can call AMOUNT-IN-000'S in many ways, as shown here: AMOUNT-IN-000'S (2500) AMOUNT-IN-000'S (PRICE * QUANTITY) This example works as long as you substitute a value for AMOUNT. The value must be a number. A value of another number type such as Real or Integer is automatically coverted to Numeric. (See "Type Conversion" under the "Types" section of this chapter.) The function argument AMOUNT can be used in the formula for the function where it is defined. Related Sections * Arguments * Numbers * Standard Functions * Types


MPE/iX 5.0 Documentation