Handling Numeric Data
2.7 Using the Arithmetic Statements
Table 2–4 shows several ROUNDING examples.
Table 2–4 ROUNDING
PICTURE clause
Initial Value
03 ITEMA PIC S9(5)V9999.
12345.2222
03 ITEMB PIC S9(5)V99.
54321.11
03 ITEMC PIC S9999.
1234
03 ITEMD PIC S9999P.
0
03 ITEME PIC S99V99 VALUE 9.
9.00
03 ITEMF PIC S99V99 VALUE 24.
24.00
Arithmetic Statement
Intermediate
Result
ROUNDED
Result Value
ADD ITEMA TO ITEMB ROUNDED.
066666.3322
66666.33
MULTIPLY ITEMC BY 2
GIVING ITEMD ROUNDED.
02468
02470
1
DIVIDE ITEME INTO ITEMF
ROUNDED.
02.666
02.67
DIVIDE ITEME INTO ITEMF
GIVING ITEMC ROUNDED.
02.666
0003
1
The trailing 0 is implied by the P in the PICTURE clause.
2.7.4.1 ROUNDED with REMAINDER
The remainder computation uses an intermediate field that is truncated, rather
than rounded, when you use the DIVIDE statement with both the ROUNDED
and REMAINDER options.
2.7.5 Using the SIZE ERROR Phrase
The SIZE ERROR phrase detects the loss of high-order nonzero digits in the
results of Compaq COBOL arithmetic operations. It does this by checking the
absolute value of an arithmetic result against the PICTURE character-string
of each resultant identifier. For example, if the absolute value of the result is
100.05, and the PICTURE character-string of the resultant identifier is 99V99,
the SIZE ERROR phrase detects that the high-order digit, 1, will be lost, and the
size error condition will be raised.
You can use the phrase in any Compaq COBOL arithmetic statement.
When the execution of a statement with no ON SIZE ERROR phrase results in
a size error, and native arithmetic is used, the values of all resultant identifiers
are undefined. When standard arithmetic is used, or when the same statement
includes an ON SIZE ERROR phrase, receiving items for which the size error
exists are left unaltered; the result is stored in those receiving items for which no
size error exists. The ON SIZE ERROR imperative phrase is then executed.
If the statement contains both ROUNDED and SIZE ERROR phrases, the result
is rounded before a size error check is made.
Handling Numeric Data 2–13
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......