Example 1: Program Source code
identification division.
program-id. payroll.
author. Jacques Levin.
date-written. Nov 23 1995.
*
* This program is adapted grom M.B.khan's textbook on COBOL
* Fig 5-107 page 114.
*
* To run this program, compile it with "ccbl payroll.cbl"
* Then run it with "runcbl"
*
*
environment division.
input-output section.
file-control.
select employee-file-in
assign to input "payroll.in".
select employee-file-out
assign to output "payroll.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 43 characters
data record is employee-record-out.
01 employee-record-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 line-feed-out pic x(1).
*
working-storage section.
*
01 end-of-file pic x value 'n'.
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.
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 line-feed-in to line-feed-out.
write employee-record-out.
perform x100-read-data.
*
* close input/output files.
*
b300-terminate-processing.
close employee-file-in
employee-file-out.
*
* read input file.
*
x100-read-data.
read employee-file-in
at end move 'y' to end-of-file.