COMPUTE VERB

General Form:

COMPUTE  dataname1 ROUNDED = expression. -------constant, variable, or
             |          |                         valid combination of
             |          |                         constants and/or variables
             |          |                         linked by arithmetic symbols
             |          --------------|           and parentheses.
             |                        |
elementary numeric item               |
or                                    |
elementary numeric edited          Optional



Examples:

COMPUTE LINE-CNT = 60.

COMPUTE LINE-CNT = PAGE-LIMIT.

COMPUTE LINE-CNT = LINE-CNT + 2.

COMPUTE AVG ROUNDED = TOTAL/CNT.

RULES of PRECEDENCE

  1. ( ) Expressions within parentheses (innermost to outermost; left to right)
  2. ** Exponentiation
  3. * or / Multiplication and Division (left to right)
  4. + or - Addition or Subtraction (left to right)

01 ANS     PIC   S999.
01 ANS-OUT PIC   -999.


COMPUTE ANS = 4 + 3 * 2 - 3 ** 3 * 2.

+044

COMPUTE ANS = (4 + 3) * 2 - (3 ** (3 * 2)).

-715

COMPUTE  ANS = (4 + 3) * 2 - 3 ** 3 * 2.

-40


Odds and Ends


SIZE ERROR Option


General Format :

ON SIZE ERROR statement......


EXAMPLES:

01  RECORD-CNT     PIC 99   VALUE 0.

ADD 1 to RECORD-CNT ON SIZE ERROR
    DISPLAY "LIMIT 99 EXCEEDED".


01 NUM1     PIC 99V9 VALUE 99.9.
01 NUM2     PIC 99   VALUE 3.
01 NUM3     PIC 9    VALUE 0.



DIVIDE NUM1 BY NUM2 GIVING NUM3 SIZE ERROR       (NOTE: no .)
    DISPLAY "DECIMAL OVERFLOW"
    MOVE 0 to NUM3
    DISPLAY NUM1.

TIME and DATE Stamps

General Format:

ACCEPT dataname FROM DATE.
ACCEPT dataname FROM DAY.
ACCEPT dataname FROM TIME.

DATE = YYMMDD
DAY = YYDDD (Julian date)
TIME = HHMMSSCC    00000000 ----> 23595999

Examples:


01 DATE-IN.
   05 YEAR-IN    PIC 99.
   05 MONTH-IN   PIC 99.
   05 DAY-IN     PIC 99.

ACCEPT DATE-IN FROM DATE.

01 JULIAN-IN.
   05 JYEAR-IN    PIC 99.
   05 JDAY-IN     PIC 99.

ACCEPT JULIAN-IN FROM DAY.

01 TIME-IN.
   05 HOURS-IN      PIC 99.
   05 MINUTES-IN    PIC 99.
   05 SECONDS-IN    PIC 99.
   05 HUNDREDS-IN   PIC 99.

 ACCEPT TIME-IN FROM TIME.


01 DATE-OUT.
   05 MONTH-OUT  PIC 99/.
   05 DAY-OUT    PIC 99/.
   05 YEAR-OUT   PIC 99.

MOVE MONTH-IN TO MONTH-OUT.
MOVE DAY-IN TO DAY-OUT.
MOVE YEAR-IN TO YEAR-OUT.