180 likes | 414 Views
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. Add Statement.
E N D
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
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
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
Subtract Statement • SUBTRACT {identifier-1 / literal} FROM {identifier-2 [ROUNDED] } … • SUBTRACT 1 FROM WS-REC-SUBSCRIPT
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
Multiply Statement • MULTIPLY {identifier-1 / literal-1} BY {identifier-2 [ROUNDED] } … • MULTIPLE 1.04 BY BUDGET-ITEM • MULTIPLY TAX-RATE BY TAX-WORK-AREA
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
Divide Statement • DIVIDE {identifier-1 / literal-1} INTO {identifier-2 [ROUNDED] } … • DIVIDE TOTAL-UNITS INTO WORK-POINTS
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
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
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
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
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
Compute Statement • Operator Symbols Operation + Addition - Subtraction * Multiplication / Division ** Exponentiation • Order of OperationsCOMPUTE X = A – B / C + D * E(must include the spaces)
ON SIZE ERROR Phrase Add X To Y Giving Z On 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