Understand your legacy COBOL projects with AI-powered documentation. Transform complex, decades-old COBOL code into clear, actionable insights that empower your team to maintain and modernize mission-critical systems.
Discover how DocuWriter.ai helps you understand and document your legacy COBOL projects through advanced AI-driven capabilities.
Our AI engine analyzes complex COBOL code and generates clear, structured documentation that reveals the inner workings of your legacy systems.
Automatically extract and document the core business rules embedded in your COBOL code, making it easier to maintain and modernize your legacy projects.
As your legacy COBOL projects evolve, our platform keeps your documentation accurate and up-to-date, ensuring seamless transitions and continuous clarity.
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL.
AUTHOR. ChatGPT.
DATE-WRITTEN. 2025-02-07.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMP-IN ASSIGN TO 'EMPLOYEE.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT EMP-OUT ASSIGN TO 'PAYROLL.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD EMP-IN.
01 EMP-REC.
05 EMP-ID PIC 9(4).
05 EMP-NAME PIC X(20).
05 GROSS-SALARY PIC 9(6)V99.
FD EMP-OUT.
01 OUT-REC PIC X(80).
WORKING-STORAGE SECTION.
01 WS-END-FILE PIC X VALUE 'N'.
88 END-OF-FILE VALUE 'Y'.
88 NOT-END-FILE VALUE 'N'.
01 NET-SALARY PIC 9(6)V99.
01 TAX-RATE PIC 9V99 VALUE 0.20.
01 WS-TOTAL-GROSS PIC 9(8)V99 VALUE ZERO.
01 WS-TOTAL-NET PIC 9(8)V99 VALUE ZERO.
01 WS-COUNT PIC 9(4) VALUE ZERO.
01 WS-DISPLAY-LINE PIC X(80).
PROCEDURE DIVISION.
MAIN-PROCEDURE.
OPEN INPUT EMP-IN
OPEN OUTPUT EMP-OUT
MOVE " PAYROLL REPORT " TO WS-DISPLAY-LINE
WRITE OUT-REC FROM WS-DISPLAY-LINE
MOVE "----------------------------------" TO WS-DISPLAY-LINE
WRITE OUT-REC FROM WS-DISPLAY-LINE
PERFORM UNTIL END-OF-FILE
READ EMP-IN
AT END MOVE 'Y' TO WS-END-FILE
END-READ
IF NOT-END-FILE
ADD 1 TO WS-COUNT
COMPUTE NET-SALARY = GROSS-SALARY - (GROSS-SALARY * TAX-RATE)
ADD GROSS-SALARY TO WS-TOTAL-GROSS
ADD NET-SALARY TO WS-TOTAL-NET
STRING "ID: " DELIMITED BY SIZE
EMP-ID DELIMITED BY SPACE
" Name: " DELIMITED BY SIZE
EMP-NAME DELIMITED BY SPACE
" Gross: $" DELIMITED BY SIZE
GROSS-SALARY DELIMITED BY SPACE
" Net: $" DELIMITED BY SIZE
NET-SALARY DELIMITED BY SPACE
INTO WS-DISPLAY-LINE
WRITE OUT-REC FROM WS-DISPLAY-LINE
END-IF
END-PERFORM
MOVE "----------------------------------" TO WS-DISPLAY-LINE
WRITE OUT-REC FROM WS-DISPLAY-LINE
STRING "Total Employees: " DELIMITED BY SIZE
WS-COUNT DELIMITED BY SPACE
" Total Gross Salary: $" DELIMITED BY SIZE
WS-TOTAL-GROSS DELIMITED BY SPACE
" Total Net Salary: $" DELIMITED BY SIZE
WS-TOTAL-NET DELIMITED BY SIZE
INTO WS-DISPLAY-LINE
WRITE OUT-REC FROM WS-DISPLAY-LINE
CLOSE EMP-IN
CLOSE EMP-OUT
STOP RUN.
Welcome to the Markdown Documentation of the file example-cobol.cob! In this document, we will explore:
This COBOL program, named PAYROLL, processes employee salary data from an input file and generates a payroll report. It demonstrates typical COBOL constructs such as:
The example-cobol.cob file performs the following tasks:
EMP-IN
): Reads employee data which includes Employee ID, Name, and Gross Salary.EMP-OUT
): Writes lines of text including a header, each employee’s payroll details, and totals at the end.
┌─────────────────────────────┐
│ Start Program │
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Open EMP-IN & EMP-OUT Files │
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Write Report Header Line │
└─────────────────────────────┘
│
▼
┌───────────────────────────────────┐
│ Read │
│ EMP-IN RECORD │
└───────────────────────────────────┘
│
┌─────┴─────────────────┐
│ End of EMP-IN? (Y/N) │
└─────┬─────────────────┘
▼ (No)
┌─────────────────────────────┐
│ Increment Employee Count │
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Compute Net Salary = │
│ Gross - (Gross * TAX-RATE) │
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Accumulate Gross & Net │
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Format and Write Employee │
│ Detail to Output │
└─────────────────────────────┘
│
└───────── (Loop back to Read next record)
│
▼ (Yes, End)
┌─────────────────────────────┐
│ Write Totals to Output File │
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Close EMP-IN & EMP-OUT │
└─────────────────────────────┘
│
▼
┌─────────────────────────────┐
│ Stop Run │
└─────────────────────────────┘
Variable | PIC / Value | Description |
---|---|---|
EMP-ID | 9(4) | Unique identifier for each employee. |
EMP-NAME | X(20) | Employee's name. |
GROSS-SALARY | 9(6)V99 | Employee's gross salary (with decimals). |
WS-END-FILE | X | Flag for end-of-file status. |
NET-SALARY | 9(6)V99 | Calculated net salary after tax deduction. |
TAX-RATE | 9V99 (0.20) | Tax rate (default 20%). |
WS-TOTAL-GROSS | 9(8)V99 | Accumulated total gross salary. |
WS-TOTAL-NET | 9(8)V99 | Accumulated total net salary. |
WS-COUNT | 9(4) | Total number of employee records processed. |
cobc -x example-cobol.cob -o payroll
./payroll
This documentation outlines the core functionality of the PAYROLL COBOL program. It demonstrates how employee data is read, processed, and summarized into a payroll report. Use this guide to better understand how legacy COBOL programs work and how you can extend or modernize them.
🏁 End of Documentation
Enjoy exploring COBOL and let DocuWriter.ai simplify your legacy projects!
Get started