HP 3000 Manuals

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


HP ALLBASE/4GL Developer Reference Manual Vol. 2

MATHLOOP Command 

The MATHLOOP command repeatedly performs a simple arithmetic operation.

Formats 

MATHLOOP loop_count operand_1 step_factor_1 operator 
operand_2 step_factor_2 = result_data_ref step_factor_3 [;command]

Window 

[]
Parameters loop_count A number specifying the number of times the arithmetic operation is performed. operands 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. step_factor_1, step_factor_2, step_factor_3 The step factors are numbers specifying the increments to be applied to the operand names or the result data field to obtain the operands and result field for the next loop of the command. The increments are applied to the operand and and result data field names, not to their values. This enables arithmetic operations to be performed on a series of operands, and the results of the calculations to be stored in a series of result data fields. You can use different values for all three step factors in the MATHLOOP command if required. The step factor may be a positive or negative number, or zero. A zero step factor causes the MATHLOOP command to use the same operand or result data field each time in the arithmetic operation. You must use a zero step factor for the following operands: * Number. * Numeric constant. * Numeric variable or calculated item. command A command to be executed if an error occurs while the MATHLOOP 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 MATHLOOP command repeatedly performs the same type of arithmetic operation on a series of operands. To perform a single arithmetic operation, use the MATH command. The MATHLOOP command operates in a similar manner to the MATH command except that the operation is repeated for each occurrence of the loop-count. In the MATHLOOP command, each operand also incorporates a step factor. The step factors determine the operands for each successive iteration of the loop. If one of the data references for the MATHLOOP command is a file record field reference or a work area field reference, HP ALLBASE/4GL steps through fields in the buffer according to the defined step factor. HP ALLBASE/4GL will step through successive occurrences of fields defined in the dictionary as having more than one occurrence. HP ALLBASE/4GL uses full floating point arithmetic to perform the MATHLOOP 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 each iteration of the MATHLOOP command. Operands for the MATHLOOP command, and values computed by the MATHLOOP command, can contain a maximum of 14 significant digits. Overflow or truncation errors may occur if you attempt to use values with more than 14 significant digits. Example 1 MATHLOOP 16 *TOTALS(1) 1/100 0 = *TOTALS(1) 1 This command is performed 16 times. It causes each of the 16 communication fields *TOTALS(n) to be divided by 100. As 100 is a number, it must have a zero step factor. Example 2 MATHLOOP 5 *S01 2 x P-scale 1= F-amt.rate 1 This command takes the five screen fields *S01, *S03, *S05, *S07 and *S09 on the current screen, and multiplies them by the five scratch-pad fields, starting with the field named scale. The command places the result of each multiplication into the file record buffer rate, starting with the field amt. Example 3 MATHLOOP 7 *S03 2 x V-rate 0 = *S04 2 This command calculates the interest amounts for the principals given in the seven odd numbered screen fields starting with field number 3. The command places the result in the seven even numbered screen fields starting with field number 4. You can then redisplay these fields using the SHOW command.


MPE/iX 5.0 Documentation