HP 3000 Manuals

MATH Command [ HP ALLBASE/4GL Developer Reference Manual Vol. 2 ] MPE/iX 5.0 Documentation


HP ALLBASE/4GL Developer Reference Manual Vol. 2

MATH Command 

The MATH command performs a simple arithmetic operation.

Format 

MATH operand_1 operator operand_2 = result_data_ref [;command]

Window 

[]
Parameters operand_1, operand_2 The items on which the arithmetic operation is performed. The operands can be any of the following: * Whole number. * Numeric constant. * Variable or calculated item. * Screen field reference. * Scratch-pad field reference. * File record field reference. * Work area field reference. * *TOTALS(n) where n = 1 to 16. * *COUNT(n), *CROSS(n): where n = 1 to 5. Certain operands can be treated as absolute values. That is, their value is treated as a fixed positive number. To specify an operand as absolute, enter the character # after the operand name. You cannot specify the result of the calculation as absolute. You can specify the following operands as absolute: * Numeric variables. * Numeric constants. * Screen field names. * Scratch-pad field names. * File record field references. * Work area field references. operator The operation to be performed on the two operands. An operator may be one of the following arithmetic symbols: + Add - Subtract X or x Multiply / Divide M or m Modulus e Raised to the power of result_data_ref This specifies where the result of the arithmetic operation is placed. It can be one of the following: * Numeric variable. * Screen field reference. * Scratch-pad field reference. * File record field reference. * Work area field reference. * *TOTALS(n) where n = 1 to 16. * *COUNT(n), *CROSS(n): where n = 1 to 5. command A command to be executed if an error occurs while the MATH command is being executed. You can use any of the following commands: * ENTER * EXIT * EXTERNAL * MESSAGE * PROCEED * SERIES * TOP * VISIT * ZIP HP ALLBASE/4GL executes the command in the following conditions: * Machine overflow or underflow occurs. * Division by zero occurs. * The result is too large to fit in the result field. * One or more of the operands contains non-numeric data, or one of the operands contains a minus sign and has an N edit code. If you don't specify an optional command, and one of these error conditions occurs, HP ALLBASE/4GL displays a warning message and then executes the next command in the logic block. Description The MATH command performs a simple arithmetic operation. Use the MATHLOOP command to perform a series of simple arithmetic operations. HP ALLBASE/4GL uses full floating point arithmetic to perform the MATH command. The result is rounded off to suit the number of decimal places defined for the result data field. If the result_data_ref is a scratch-pad field, the number of decimal places used for the result of the calculation is the number of decimal places specified for the first operand of the MATH command. Operands for the MATH command, and values computed by the MATH command can contain a maximum of 14 significant digits. Overflow or truncation errors may occur if you use values with more than 14 significant digits. Example 1 MATH *COUNT(2) + 1 = *COUNT(2)} This command increments the value in the communication area field *COUNT(2) by 1 and stores the result back in *COUNT(2). Example 2 MATH V-principal# x P-rate = F-interest.bank This command calculates simple interest. It uses the absolute value of the value in the variable principal and multiplies it by the contents of the scratch-pad field rate. The result is stored in the field interest in the file bank. Example 3 MATH *S01 m 2 = V-remainder This command checks if the value in screen field number 1 is odd or even. By specifying a modulus of 2, the number is divided by 2 and the remainder placed in the variable remainder. If the result of the modulus operation is a zero, the value in screen field number 1 is even; otherwise it is odd.


MPE/iX 5.0 Documentation