COBOL算术运算
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
PIC 9(3)V9.
PIC 9(3).
Actual Result Truncated Result
123.45 123.45
123.4 123
Rounded
123.5 123
SIZE ERROR
Receiving Field PIC 9(3)V9. PIC 9(3)V9. PIC 9(3). PIC 9(3). PIC 9(3)V9 Not Rounded PIC 9(3)V9 Rounded PIC 9(3)V9 Rounded
例子:
DIVIDE NUM1 INTO NUM2.
DIVIDE 语句2
语法2:
DIVIDE identifier-1(or Literals) INTO identifier-2 GIVING identifier-3 [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-DIVIDE]
例子:
ADD NUM1 TO NUM2 GIVING NUM3. ADD NUM1, NUM2 GIVING NUM3. ADD NUM1, 10 TO NUM2 GIVING NUM3.
例子
ADD 语句3
语法3:
ADD CORR identifier-1 TO identifier-2,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-ADD]
例子:
MULTIPLY NUM1 BY NUM2. MULTIPLY 100 by num.
MULTIPLY 语句2
语法2:
MULTIPLY identifier-1 (or Literals),…BY identifier-2 GIVING identifier-3 [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-MULTIPLY]
例子:
MULTIPLY NUM1 BY NUM2 GIVING NUM3.
例子
DIVIDE 语句1
语法1:
DIVIDE identifier-1(or Literals) INTO identifier-2 [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-DIVIDE]
例子:
SUBTRACT NUM1 FROM NUM2 GIVING NUM3.
例子:
SUBTRACT 语句3
语法3:
SUBTRACT CORR identifier-1 FROM identifier-2,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-SUBTRACT]
Actual Result 123.45
1234.5 123
1234 123.45 123.45
1234.56
SIZE ERROR Y Y N Y Y N Y
SUBTRACT 语句1
语法1:
SUBTRACT identifier-1(or Literals), identifier-2,… FROM identifier-n,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-SUBTRACT]
例子:
03 CURRENT-MONTH.
05 PAY
PIC 9(3)V9(2).
05 Twk.baidu.comX
PIC 9(2)V9(2).
03 YTD.
05 PAY
PIC 9(3)V9(2).
05 TAX
PIC 9(2)V9(2).
ADD CORR CURRENT-MONTH TO YTD.
ROUNDED
Receiving Field Result
例子:
SUBTRACT CORR REC1 FROM REC2.
MULTIPLY 语句1
语法1:
MULTIPLY identifier-1(or Literals),… BY identifier-2,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-MULTIPLY]
例子:
ADD NUM1
TO NUM2.
ADD NUM1, 10
TO NUM2,NUM3.
ADD NUM1, NUM2 TO NUM3
ON SIZE ERROR PERFORM 100-ERROR.
ADD 语句2
语法2:
ADD identifier-1(or Literals),identifier-2,… [TO] identifier-n GIVING identifier-m [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-ADD]
COBOL for Mainframe Fundamentals
Ch4 COBOL算术运算
算术运算语句
ADD SUBTRACT MULTIPLY DIVIDE COMPUTE
ADD 语句1
语法1:
ADD identifier-1(or Literals),identifier-2,… TO identifier-n,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-ADD]
例子:
SUBTRACT NUM1 FROM NUM2.
SUBTRACT 语句2
语法2:
SUBTRACT identifier-1(or Literals), identifier-2,… FROM identifier-n GIVING identifier-m [ROUNDED] [ON SIZE ERROR 语句-1] [NOT ON SIZE ERROR 语句-2] [END-SUBTRACT]
PIC 9(3).
Actual Result Truncated Result
123.45 123.45
123.4 123
Rounded
123.5 123
SIZE ERROR
Receiving Field PIC 9(3)V9. PIC 9(3)V9. PIC 9(3). PIC 9(3). PIC 9(3)V9 Not Rounded PIC 9(3)V9 Rounded PIC 9(3)V9 Rounded
例子:
DIVIDE NUM1 INTO NUM2.
DIVIDE 语句2
语法2:
DIVIDE identifier-1(or Literals) INTO identifier-2 GIVING identifier-3 [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-DIVIDE]
例子:
ADD NUM1 TO NUM2 GIVING NUM3. ADD NUM1, NUM2 GIVING NUM3. ADD NUM1, 10 TO NUM2 GIVING NUM3.
例子
ADD 语句3
语法3:
ADD CORR identifier-1 TO identifier-2,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-ADD]
例子:
MULTIPLY NUM1 BY NUM2. MULTIPLY 100 by num.
MULTIPLY 语句2
语法2:
MULTIPLY identifier-1 (or Literals),…BY identifier-2 GIVING identifier-3 [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-MULTIPLY]
例子:
MULTIPLY NUM1 BY NUM2 GIVING NUM3.
例子
DIVIDE 语句1
语法1:
DIVIDE identifier-1(or Literals) INTO identifier-2 [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-DIVIDE]
例子:
SUBTRACT NUM1 FROM NUM2 GIVING NUM3.
例子:
SUBTRACT 语句3
语法3:
SUBTRACT CORR identifier-1 FROM identifier-2,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-SUBTRACT]
Actual Result 123.45
1234.5 123
1234 123.45 123.45
1234.56
SIZE ERROR Y Y N Y Y N Y
SUBTRACT 语句1
语法1:
SUBTRACT identifier-1(or Literals), identifier-2,… FROM identifier-n,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-SUBTRACT]
例子:
03 CURRENT-MONTH.
05 PAY
PIC 9(3)V9(2).
05 Twk.baidu.comX
PIC 9(2)V9(2).
03 YTD.
05 PAY
PIC 9(3)V9(2).
05 TAX
PIC 9(2)V9(2).
ADD CORR CURRENT-MONTH TO YTD.
ROUNDED
Receiving Field Result
例子:
SUBTRACT CORR REC1 FROM REC2.
MULTIPLY 语句1
语法1:
MULTIPLY identifier-1(or Literals),… BY identifier-2,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-MULTIPLY]
例子:
ADD NUM1
TO NUM2.
ADD NUM1, 10
TO NUM2,NUM3.
ADD NUM1, NUM2 TO NUM3
ON SIZE ERROR PERFORM 100-ERROR.
ADD 语句2
语法2:
ADD identifier-1(or Literals),identifier-2,… [TO] identifier-n GIVING identifier-m [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-ADD]
COBOL for Mainframe Fundamentals
Ch4 COBOL算术运算
算术运算语句
ADD SUBTRACT MULTIPLY DIVIDE COMPUTE
ADD 语句1
语法1:
ADD identifier-1(or Literals),identifier-2,… TO identifier-n,… [ROUNDED] [ON SIZE ERROR statement -1] [NOT ON SIZE ERROR statement -2] [END-ADD]
例子:
SUBTRACT NUM1 FROM NUM2.
SUBTRACT 语句2
语法2:
SUBTRACT identifier-1(or Literals), identifier-2,… FROM identifier-n GIVING identifier-m [ROUNDED] [ON SIZE ERROR 语句-1] [NOT ON SIZE ERROR 语句-2] [END-SUBTRACT]