Write COBOL logic using COMPUTE for your project

COBOL with COMPUTE
COBOL program with COMPUTE

The below is the COBOL program example. Here you will get clear idea on how to write COMPUTE in COBOL program.

100-MAIN-PROGRAM.
OPEN INPUT SALES-FILE
     OUTPUT CHECK-FILE
MOVE 'Y' TO ARE-THERE-MORE-RECS
MOVE SPACES TO CHECK-REC
PERFORM UNTIL ARE-THERE-MORE-RECS = 'N'
      READ SALES-FILE
      AT END
           MOVE 'N' TO ARE-THERE-MORE-RECS
      NOT AT END
          PERFORM 200-PROCESS-PARA
      END-READ
END-PERFORM
CLOSE SALES-FILE
      CHECK-FILE
STOP RUN.

200-PROCESS-PARA.
 IF SALES-IN > 100
    MULTIPLY .10 BY SALES-IN GIVING WS-COMMISSION
ELSE
    MULTIPLY .05 BY SALES-IN GIVING WS-COMMISSION
END-IF

COMPUTE AMT-OUT = SALES-IN + WS-COMMISSION
MOVE SALES-IN TO NAME-OUT
WRITE CHECK-REC.
Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.