Handling Numeric Data
2.7 Using the Arithmetic Statements
The SIZE ERROR phrase cannot be used with numeric MOVE statements. Thus,
if a program moves a numeric quantity to a smaller numeric item, it can lose
high-order digits. For example, consider the following move of an item to a
smaller item:
01 AMOUNT-A PIC S9(8)V99.
01 AMOUNT-B PIC S9(4)V99.
.
.
.
MOVE AMOUNT-A TO AMOUNT-B.
This MOVE operation always loses four of AMOUNT-A’s high-order digits.
The statement can be tailored in one of three ways, as shown in the following
example, to determine whether these digits are zero or nonzero:
1.
IF AMOUNT-A NOT > 9999.99
MOVE AMOUNT-A TO AMOUNT-B
ELSE ...
2.
ADD ZERO AMOUNT-A GIVING AMOUNT-B
ON SIZE ERROR ...
3.
COMPUTE AMOUNT-B = AMOUNT-A
ON SIZE ERROR ...
All three alternatives allow the MOVE operation to occur only if AMOUNT-A
loses no significant digits. If the value in AMOUNT-A is too large, all three avoid
altering AMOUNT-B and take the alternate execution path.
You can also use a NOT ON SIZE ERROR phrase to branch to, or perform,
sections of code only when no size error occurs.
2.7.6 Using the GIVING Phrase
The GIVING phrase moves the intermediate result of an arithmetic operation
to a receiving item. The phrase acts exactly like a MOVE statement in which
the intermediate result serves as the sending item, and the data item following
the word GIVING serves as the receiving item. When a statement contains a
GIVING phrase, you can have a numeric-edited receiving item.
The receiving item can also have the ROUNDED phrase. If the receiving item is
also numeric-edited, rounding takes place before the editing.
The GIVING phrase can be used with the ADD, SUBTRACT, MULTIPLY, and
DIVIDE statements. For example:
ADD A,B GIVING C.
2.7.7 Multiple Operands in ADD and SUBTRACT Statements
Both the ADD and SUBTRACT statements can contain a series of operands
preceding the word TO, FROM, or GIVING.
If there are multiple operands in either of these statements, the operands are
added together. The intermediate result of that operation becomes a single
operand to be added to or subtracted from the receiving item. In the following
examples, TEMP is an intermediate result item:
1.
Statement:
ADD A,B,C,D, TO E,F,G,H.
2–14 Handling Numeric Data
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......