HP 3000 Manuals

SUBTRACT Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

SUBTRACT Statement 

The SUBTRACT statement subtracts one or more numeric data items from one
or more numeric data items and stores the result in one or more data
items.

Syntax 

The SUBTRACT statement has three formats:

[]
Parameters identifier-1, elementary numeric data items, or if to the right of the identifier-2, keyword GIVING, may be elementary numeric-edited data and so forth items. The exception is in format 3, where identifier-1 and identifier-2 must be group items. literal-1, numeric literals. literal-2, and so forth CORR abbreviation for CORRESPONDING. Description The compiler always ensures that enough places are carried in order to avoid losing significant digits. The ROUNDED, SIZE ERROR, NOT ON SIZE ERROR, and CORRESPONDING phrases, as well as rules applying to multiple results and overlapping operands are described in Chapter 8 . The composite of operands, a hypothetical data item obtained by the superimposition of data items, must not exceed 18 digits. This composite is determined for each format as follows: Format 1: Composite is determined by using all of the operands in a given statement. Format 2: Composite is determined using all of the operands in a given statement except those following the GIVING phrase. Format 3: Composite is determined using each pair of corresponding data items separately. When format 1 of the SUBTRACT statement is used, all literals or values of identifiers preceding the FROM phrase are added together, and the resulting sum is subtracted from the value of each identifier specified in the FROM phrase. As each subtraction is completed, the result is stored in the identifier of the FROM phrase used as operand. When format 2 is used, all literals or values of identifiers preceding the FROM phrase are added together, and then subtracted from literal-2 or the value of identifier-3. The result of this subtraction is then stored in each identifier following the GIVING keyword. When format 3 is used, data items in identifier-1 are subtracted from and stored in corresponding data items of identifier-2. Examples SUBTRACT FIRST-YR, SECOND-YR FROM THIRD-YR. SUBTRACT HIRE-DATE FROM AGE GIVING YEARS-OF-SERVICE. In the first example above, the value of FIRST-YR is added to the value of SECOND-YR, and this sum is subtracted from, and stored in THIRD-YR. In the second example, the value of AGE is subtracted from the value of HIRE-DATE, and the results are stored in YEARS-OF-SERVICE. In the example below, QTY-1, QTY-2, and QTY-3 of PARTS-OUT are subtracted from QTY-1, QTY-2, and QTY-3 of CURRENT-PARTS, and the results are stored in QTY-1, QTY-2, and QTY-3 of CURRENT-PARTS. FILE SECTION. FD INVFILE. 01 PARTS-INV. 03 PARTS-OUT. 04 PARTS-NUM-1 PIC X(10). 04 QUANTITY PIC 9(6). 04 SUB-PARTS-OUT. 05 QTY-1 PIC 9(6). 05 QTY-2 PIC 9(6). 05 QTY-3 PIC 9(6). 03 CURRENT-PARTS. 04 PART-NUM-1 PIC X(10). 04 QUANTITY PIC 9(6). 04 CURRENT-SUB-PARTS. 05 QTY-1 PIC 9(5). 05 QTY-2 PIC 9(5). 05 QTY-3 PIC 9(5). : PROCEDURE DIVISION. : SUBTRACT CORRESPONDING SUB-PARTS-OUT FROM CURRENT-SUB-PARTS.


MPE/iX 5.0 Documentation