Example 2: Program Source code
identification division.
program-id. example.
author. Jacques Levin.
date-written. Nov 23 1995.
*
* This program is adapted grom M.B.khan's textbook on COBOL
* Fig 8.8 page 203
*
* To run this program, compile it with "ccbl calcpay.cbl"
* Then run it with "runcbl"
*
environment division.
*
input-output section.
file-control.
select employee-file-in
assign to input "calcpay.in".
select employee-file-out
assign to output "calcpay.out".
*
data division.
*
file section.
*
* describe the input file
*
fd employee-file-in
label records standard
block contains 5 records
record contains 31 characters
data record is employee-record-in.
01 employee-record-in.
02 employee-name-in pic x(20).
02 employee-rate-in pic 9(3)v99.
02 employee-hours-in pic 9(3)v99.
02 line-feed-in pic x(1).
*
* describe the output file
*
fd employee-file-out
label records omitted
record contains 55 characters
data record is employee-file-out.
01 employee-file-out.
02 employee-name-out pic x(20).
02 filler pic x(5).
02 employee-rate-out pic 9(3).99.
02 filler pic x(5).
02 employee-hours-out pic 9(3).99.
02 filler pic x(5).
02 gross-pay-out pic 9(4).99.
02 line-feed-out pic x(1).
working-storage section.
01 control-fields.
02 end-of-file pic x(1) value 'n'.
01 working-fields.
02 ws-gross-pay pic 9(5)v99 value 0.
02 ws-overtime-pay pic 9(5)v99 value 0.
02 ws-overtime-hours pic 9(5)v99 value 0.
02 ws-overtime-rate pic 9(5)v99 value 0.
procedure division.
*
* main paragraph.
*
a000-control-logic.
perform b100-initialize-processing.
perform b200-process-data
until end-of-file equal to 'y'.
perform b300-terminate-processing.
stop run.
*
* open input/output files.
*
b100-initialize-processing.
open input employee-file-in
output employee-file-out.
perform x100-read-data.
*
* process data.
*
b200-process-data.
perform c100-calc-regular-pay.
if employee-hours-in is greater than 40
perform c200-calc-overtime-pay.
perform x200-write-data.
perform x100-read-data.
*
* close input/output files.
*
b300-terminate-processing.
close employee-file-in
employee-file-out.
*
* calculate regular pay.
*
c100-calc-regular-pay.
if employee-hours-in is greater than 40
multiply employee-rate-in by 40
giving ws-gross-pay
else
multiply employee-rate-in by employee-hours-in
giving ws-gross-pay.
*
* calculate overtime pay.
*
c200-calc-overtime-pay.
subtract 40 from employee-hours-in
giving ws-overtime-hours.
multiply 1.5 by employee-rate-in
giving ws-overtime-rate.
multiply ws-overtime-rate by ws-overtime-hours
giving ws-overtime-pay.
add ws-overtime-pay to ws-gross-pay.
*
* read input file.
*
x100-read-data.
read employee-file-in
at end move 'y' to end-of-file.
*
* write output file.
*
x200-write-data.
move employee-name-in to employee-name-out.
move employee-rate-in to employee-rate-out.
move employee-hours-in to employee-hours-out.
move ws-gross-pay to gross-pay-out.
move line-feed-in to line-feed-out.
write employee-file-out.