If you’re learning COBOL, one of the best beginner exercises is building a payroll program. Payroll programs demonstrate many fundamental COBOL concepts including:

  • Data structures using OCCURS

  • Looping with PERFORM VARYING

  • Mathematical calculations with COMPUTE

  • Running totals using ADD

  • Output formatting for currency

In this article we will walk through a simple COBOL payroll program that processes two employees, calculates their individual totals, and then prints a final company payroll total.

IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROL-3-6-26.
REMARKS. PAYROLL EXAMPLE PROGRAM.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.

DATA DIVISION.
WORKING-STORAGE SECTION.

01 WS-EMPLOYEE-INFO OCCURS 2 TIMES INDEXED BY WS-INDEX.
   05 WS-EMP-ID    PIC 9(4).
   05 WS-PAY-RATE  PIC 9(2).
   05 WS-HOURS     PIC 9(4).
   05 WS-NAME      PIC X(50).

01 WS-TOTALS           PIC 9(8)V99 VALUE 0.
01 WS-TOTALS-ED        PIC $,$$$,$$$.99.
01 WS-GRAND-TOTALS     PIC 9(9)V99 VALUE 0.
01 WS-GRAND-TOTALS-ED  PIC $$,$$$,$$$.99.

PROCEDURE DIVISION.

000-MAIN.
    PERFORM 100-DATA-INIT-1
    PERFORM 200-CALC-TOTALS
    PERFORM 300-CALC-GRAND-TOTALS
    PERFORM 900-TERMINATE.

100-DATA-INIT-1.
    MOVE 1234   TO WS-EMP-ID(1)
    MOVE 52.35  TO WS-PAY-RATE(1)
    MOVE 60     TO WS-HOURS(1)
    MOVE 'JOHN' TO WS-NAME(1)

    MOVE 1235   TO WS-EMP-ID(2)
    MOVE 59.35  TO WS-PAY-RATE(2)
    MOVE 640    TO WS-HOURS(2)
    MOVE 'WOY'  TO WS-NAME(2)
    CONTINUE.

200-CALC-TOTALS.
    PERFORM VARYING WS-INDEX FROM 1 BY 1
        UNTIL WS-INDEX > 2
            COMPUTE WS-TOTALS =
                WS-PAY-RATE(WS-INDEX) * WS-HOURS(WS-INDEX)
            MOVE WS-TOTALS TO WS-TOTALS-ED
            DISPLAY "TOTAL: " WS-TOTALS-ED
            ADD WS-TOTALS TO WS-GRAND-TOTALS
    END-PERFORM.

300-CALC-GRAND-TOTALS.
    MOVE WS-GRAND-TOTALS TO WS-GRAND-TOTALS-ED
    DISPLAY "GRAND TOTAL: " WS-GRAND-TOTALS-ED.

900-TERMINATE.
    STOP RUN.

Understanding the Program Structure

COBOL programs are organized into divisions.

Identification Division

IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROL-3-6-26.

This identifies the program name used when compiling or running the program.


Data Division

The WORKING-STORAGE SECTION defines variables used by the program.

Employee Array

01 WS-EMPLOYEE-INFO OCCURS 2 TIMES INDEXED BY WS-INDEX.

This creates a small table (array) that holds two employees.

Each employee has:

  • Employee ID

  • Pay Rate

  • Hours worked

  • Name


Data Initialization

The program manually loads employee data.

MOVE 1234 TO WS-EMP-ID(1)
MOVE 52.35 TO WS-PAY-RATE(1)
MOVE 60 TO WS-HOURS(1)

In real production systems, this data would come from:

  • VSAM files

  • DB2 databases

  • Input files

See our guide to COBOL WORKING-STORAGE variables here:
Working Storage Section


Calculating Employee Totals

The program loops through employees using PERFORM VARYING.

PERFORM VARYING WS-INDEX FROM 1 BY 1
UNTIL WS-INDEX > 2

This means:

  • Start with employee 1

  • Increase index by 1 each loop

  • Stop after employee 2

Inside the loop we calculate payroll:

COMPUTE WS-TOTALS =
WS-PAY-RATE(WS-INDEX) * WS-HOURS(WS-INDEX)

Example:

52.35 * 60 = 3120

Accumulating the Grand Total

Each employee’s total is added to a running total.

ADD WS-TOTALS TO WS-GRAND-TOTALS

This is called an accumulator pattern, common in financial COBOL programs.


Displaying the Final Payroll Total

After processing all employees, the program prints the final payroll amount.

DISPLAY “GRAND TOTAL: ” WS-GRAND-TOTALS-ED

Example output:

TOTAL: $3,120.00
TOTAL: $37,760.00
GRAND TOTAL: $40,880.00

Why This Program Structure Is Important

This program demonstrates a classic COBOL pattern used in many mainframe applications:

000-MAIN
100-INITIALIZATION
200-PROCESS-DETAIL
300-SUMMARY
900-TERMINATION

This structure makes large COBOL systems easier to maintain.


Final Thoughts

Even though COBOL was created decades ago, programs like this demonstrate why it remains widely used in industries such as:

  • Banking

  • Insurance

  • Government

  • Payroll systems

Understanding these fundamental patterns is the first step toward mastering enterprise COBOL development.