1 / 16

Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions

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.

evers
Download Presentation

Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Basic Arithmetic Verbs • ADD, SUBTRACT, MULTIPLY, DIVIDE • All require fields operated on to • Have numeric PICTURE clauses • Contain numeric data when statements executed

  3. 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

  4. 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

  5. Subtract Statement • SUBTRACT {identifier-1 / literal} FROM {identifier-2 [ROUNDED] } … • SUBTRACT 1 FROM WS-REC-SUBSCRIPT

  6. 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

  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

  8. 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

  9. Divide Statement • DIVIDE {identifier-1 / literal-1} INTO {identifier-2 [ROUNDED] } … • DIVIDE TOTAL-UNITS INTO WORK-POINTS

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. Compute Statement • Operator Symbols Operation + Addition - Subtraction * Multiplication / Division ** Exponentiation • Order of OperationsCOMPUTE X = A – B / C + D * E(must include the spaces)

  16. 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

More Related