Previous Topic: COMPUTE CommandNext Topic: COMPUTE During Report Printing


COMPUTE During Record Selection

(Area 3)

Use this format of the COMPUTE command during record selection to specify one or more arithmetic operations to be performed on the specified numeric fields or constants and to place the result in the specified field.

You do not need to predefine the result field; it can be implicitly defined in the COMPUTE command itself with the result(n1,n2) parameter. However, you should predefine all fields referenced in procedural commands to minimize the margin of error.

Computation during record selection implies that the operation is performed prior to the sort and prior to the printing of reports. Therefore, the system uses fields from both the input buffer and the GSA as component parts of the arithmetic expression. When the computed value is then referenced by a field name in a subsequent report definition group, the system directs the value to the Hit File for processing.

The coding requirements for the COMPUTE during record selection command are:

►►─┬──────────┬─ COMPUTE ─┬─ result ────────┬─ =arithmetic-expression ────────►
   └─ label: ─┘           └─ result(n1.n2) ─┘

 ►─┬───────────────────────────────────────────────┬─┬─────────┬──────────────►◄
   └─┬─ HEADING ─┬─ ' heading1 ' ─┬──────────────┬─┘ └─ ROUND ─┘
     └─ HDG ─────┘                └─ 'heading2' ─┘
label:

Specifies an optional identifying label that allows a GOTO branch to be made to this statement.

result

Specifies the name given a predefined numeric field in which the result of the computation is placed. Predefine the field name as zoned decimal, packed decimal, binary, or unsigned binary.

result(n1.n2)

Specifies a user-supplied field name, coded using standard conventions, where the result of the computation is placed. This parameter implicitly defines the field to contain the result without predefining it. The field is generated in packed decimal format and resides in the GSA.

When the precision clause (n1.n2) does not follow the field name specification, the Reporting Facility automatically calculates the precision of the result based on the individual components of the arithmetic expression. The n1 and n2 indicate that the field will contain n1 integers and n2 decimals. The value of n1+n2 must be greater than 0 and not exceed 15. When the field contains no integers, n1 must be 0. When no decimals are necessary, n2 must be 0.

=arithmetic-expression

Specifies the arithmetic operations to be performed. The terms involved in the expression can be either numeric fields or constants, connected with arithmetic operators.

HEADING

Specifies an optional separator used to denote that the literals to follow are to be interpreted as headings. Heading specifications are valid only when the result field of the computation is being implicitly defined. HDG can be used in place of HEADING in the command.

'heading 1' 'heading 2'

Enables you to assign one or two lines of heading to the result field when the field is implicitly defined in the COMPUTE command. The lines of heading appear as column headings if the field is printed in a report. If the parameter is omitted and the result field is implicitly defined, the Reporting Facility automatically assigns the field name as heading line 1, with no second line of heading.

ROUND

Optionally defines whether the result will be rounded before being placed into the result field. For rounding to occur, the computed value must have more decimal places than the result field. The default is not to round.

Example

 COMPUTE RESULT-FIELD EQ FIELDA + FIELDB
 COMPUTE RESULT-FIELD(7.2) EQ FIELDA + .005 HDG 'AMOUNT'
 COMPUTE FIELDA=((FIELDA+FIELDB)/FIELDC)*2
 COMPUTE INDEX EQ INDEX+1
 COMPUTE INDEX EQ INDEX - 1 ROUND
 COMPUTE FIELDB=(((FIELDA + -2.367)*4) - (3*FIELDC)+.005)

Note: This format of the COMPUTE command cannot be specified in a report definition group.