Sample COBOL program using COMPUTE:

 IDENTIFICATION DIVISION.
       PROGRAM-ID.  EINSTEIN.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT In-File ASSIGN TO "EINSTEIN.TXT"
                  ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD  IN-FILE BLOCK CONTAINS 0 RECORDS.
       01  IN-REC.
           02  M                         PIC S9(10).
           02  C                         PIC S9(10).
       WORKING-STORAGE SECTION.
       01  E                             PIC S9(10) PACKED-DECIMAL.
       PROCEDURE DIVISION.
       BEGIN-PROGRAM.
           OPEN INPUT IN-FILE
           READ IN-FILE
           COMPUTE E = M * (C ** 2)
           CLOSE IN-FILE
           GOBACK
           .
       END PROGRAM EINSTEIN.

Advertisements