Guidance for converting COBOL programs to modern languages (Python, Java, etc.) while preserving exact behavior and data format compatibility. This skill should be used when modernizing legacy COBOL applications, converting COBOL business logic to modern languages, or ensuring byte-for-byte output compatibility between COBOL and its replacement.
This skill provides a systematic approach for converting COBOL programs to modern languages while ensuring exact behavioral equivalence. The key challenge in COBOL modernization is not just translating logic, but preserving precise data formats, fixed-width record structures, and byte-level output compatibility.
Before writing any code, thoroughly analyze the COBOL source and data files:
Read the complete COBOL source code - Understand the program structure including:
Document all data formats explicitly - Create a specification for each file:
Resolve format discrepancies before implementation - If input files don't match expected formats (e.g., file is 15 bytes but COBOL expects 22 bytes), investigate and document how the COBOL program actually handles this before proceeding.
Create reusable testing infrastructure before implementing the conversion:
Create a state reset script - Automate restoring original data files:
# Example: reset_state.sh
cp data/ACCOUNTS.DAT.orig data/ACCOUNTS.DAT
cp data/BOOKS.DAT.orig data/BOOKS.DAT
cp data/TRANSACTIONS.DAT.orig data/TRANSACTIONS.DAT
Create a comparison script - Automate output comparison:
# Example: compare_outputs.sh
diff data/ACCOUNTS_PYTHON.DAT data/ACCOUNTS_COBOL.DAT
diff data/BOOKS_PYTHON.DAT data/BOOKS_COBOL.DAT
diff data/TRANSACTIONS_PYTHON.DAT data/TRANSACTIONS_COBOL.DAT
Preserve original COBOL outputs - Run the COBOL program first and save outputs as reference baselines before any conversion work.
When writing the modern language equivalent:
Match COBOL data handling exactly:
Verify file writes immediately - After writing code files, read them back to confirm complete content was saved correctly before testing.
Use consistent naming - Avoid creating excessive temporary files. Use a clear naming scheme:
*_COBOL.DAT for COBOL program outputs*_PYTHON.DAT for Python program outputsTest all code paths, not just the happy path:
Create a test matrix covering all validation scenarios:
Test each scenario independently:
diffDocument test results - Track which scenarios passed and any discrepancies found.
Before declaring the modernization complete:
diff returns no output)