16
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Embed Size (px)

Citation preview

Page 1: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Computing in COBOL: The Arithmetic Verbs and Intrinsic

Functions

Chapter 7

Page 2: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Basic Arithmetic Verbs

• ADD, SUBTRACT, MULTIPLY, DIVIDE

• All require fields operated on to– Have numeric PICTURE clauses– Contain numeric data when statements

executed

Page 3: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Add Statement

• ADD {identifier-1 / literal} TO {identifier-2 [ROUNDED] } …

• ADD 1 TO WS-PAGE-COUNT• ADD 2 TO WS-LINE-COUNT• ADD IN-OT-HOURS TO WS-TOTAL-HOURS

Page 4: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Add Statement

• ADD {identifier-1 / literal} TO {identifier-2 / literal-2} GIVING {identifier-3 [ROUNDED] } …

• ADD IN-REG-HOURS TO IN-OT-HOURS GIVING WS-TOTAL-HOURS

Page 5: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Subtract Statement

• SUBTRACT {identifier-1 / literal} FROM {identifier-2 [ROUNDED] } …

• SUBTRACT 1 FROM WS-REC-SUBSCRIPT

Page 6: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Subtract Statement

• SUBTRACT {identifier-1 / literal-1} FROM {identifier-2 / literal-2} GIVING {identifier-3[ROUNDED] } …

• SUBTRACT 10.00, WITH-TAX, FICA, DEDUCTION FROM GROSS-PAY GIVING NET-PAY

• SUBTRACT 1 FROM BONUS-PNTS GIVING CHECK-PNTS, WORK-PNTS

Page 7: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Multiply Statement

• MULTIPLY {identifier-1 / literal-1} BY {identifier-2 [ROUNDED] } …

• MULTIPLE 1.04 BY BUDGET-ITEM• MULTIPLY TAX-RATE BY TAX-WORK-AREA

Page 8: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Multiply Statement

• MULTIPLY {identifier-1 / literal-1} BY {identifier-2 / literal-2} GIVING {identifier-3 [ROUNDED] } …

• MULTIPLY TOTAL-PURCHASES BY TAX-RATE GIVING SALES-TAX-AMOUNT

• MULTIPLY OLD-BUDGET-AMOUNT BY BUDGET-INCREASE GIVING NEW-BUDGET-AMOUNT

Page 9: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Divide Statement

• DIVIDE {identifier-1 / literal-1} INTO {identifier-2 [ROUNDED] } …

• DIVIDE TOTAL-UNITS INTO WORK-POINTS

Page 10: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Divide Statement

• DIVIDE {identifier-1 / literal-1} INTO {identifier-2 / literal-2} GIVING {identifier-3 [ROUNDED] } …

• DIVIDE TOTAL-UNITS INTO WORK-POINTS GIVING GRADE-POINT-AVERAGE ROUNDED

Page 11: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Divide Statement

• DIVIDE {identifier-1 / literal-1} INTO {identifier-2 / literal-2} GIVING identifier-3 REMAINDER identifier-4

• DIVIDE 60 INTO TOTAL-TIME-SPENT GIVING WK-HOURS REMAINDER WK-MINUTES

Page 12: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Divide Statement

• DIVIDE {identifier-1 / literal-1} BY {identifier-2 / literal-2} GIVING {identifier-3 [ROUNDED] } …

• DIVIDE WORK-POINTS BY TOTAL-UNITS GIVING GRADE-POINT-AVERAGE ROUNDED

Page 13: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Divide Statement

• DIVIDE {identifier-1 / literal-1} BY {identifier-2 / literal-2} GIVING identifier-3 REMAINDER identifier-4

• DIVIDE TOTAL-TIME-SPENT BY 60 GIVING WK-HOURS REMAINDER WK-MINUTES

Page 14: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Compute Statement

• COMPUTE {identifier-1 [ROUNDED]} …= arithmetic-expression

• COMPUTE NEW-BALANCE = BALANCE-FORWARD + CURRENT-PURCHASES + SERVICE-CHARGE - TOTAL-PAYMENT

• COMPUTE INTEREST = PRINCIPAL * RATE * YEARS / 100

Page 15: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

Compute Statement

• Operator Symbols Operation

+ Addition - Subtraction * Multiplication / Division ** Exponentiation

• Order of OperationsCOMPUTE X = A – B / C + D * E

(must include the spaces)

Page 16: Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions Chapter 7

ON SIZE ERROR Phrase

Add X To Y Giving ZOn Size Error Display ' Result too large'Not On Size Error Perform Calc-Para

End-Add

• If sum of X and Y too large to store in Z, Display statement executed• If Z large enough for result, Calc-Para is performed

ADD NEW-AMOUNTS TO TOTAL-AMOUNT ON SIZE ERROR PERFORM 999-SIZE-ERROR NOT ON SIZE ERROR PERFORM 200-NORMAL

END-ADD