COBOL Modernisation Guide
A comprehensive guide to analysing, transforming, and migrating COBOL mainframe applications to modern platforms using Autohand's AI-powered modernisation tools.
The COBOL challenge
COBOL remains the backbone of critical business systems worldwide. Banks, insurance companies, and government agencies run trillions of dollars in transactions through COBOL programs every day. Yet these systems face mounting pressure: retiring workforce expertise, integration difficulties with modern architectures, and the high cost of mainframe operations.
Autohand provides a systematic approach to COBOL modernisation that preserves business logic while enabling organisations to benefit from modern platforms, languages, and development practices.
- Analyse millions of lines of COBOL with automated dependency mapping
- Extract business rules embedded in procedural code
- Transform COBOL to Java, C#, or cloud-native architectures
- Validate transformations with automated test generation
- Execute phased migrations in isolated git worktrees, with git-based rollback
Assessment and discovery
Every successful COBOL modernisation begins with a thorough understanding of the existing system. Autohand reads your COBOL sources, copybooks, and JCL and writes the inventory you ask for. Use --plan for read-only analysis that needs your approval before anything is executed.
Portfolio scanning
# Scan COBOL source files (read-only plan mode)
autohand --plan -p "Inventory the COBOL programs in ./src/cobol and the copybooks they COPY from ./src/copybooks"
# Include JCL and control cards
autohand --plan --add-dir /path/to/jcl \
-p "Inventory the COBOL programs in ./src/cobol, including the JCL jobs and PROCs in /path/to/jcl that run them"
# Write the inventory to a file
autohand -p "Inventory every COBOL program, copybook, and JCL job in this repository; write it to docs/inventory.json"
Dependency analysis
Understanding program dependencies is critical for planning migration waves. Ask Autohand to map the inter-program relationships:
# Generate dependency graph
autohand -p "Map CALL and COPY dependencies across ./src/cobol; write them as GraphML to docs/deps.graphml"
# Identify program clusters
autohand -p "Group the programs in docs/deps.graphml into loosely coupled clusters that could migrate together; write docs/clusters.md"
# Find critical path programs
autohand -p "Starting from MAINPROG and BATCHRUN, list the programs on the critical call path; write docs/critical-path.md"
The dependency analysis reveals:
- CALL relationships between programs
- COPY statement dependencies on copybooks
- File and database access patterns
- Transaction boundaries and CICS interactions
- Batch job sequences from JCL analysis
Complexity metrics
# Calculate complexity metrics
autohand -p "For each program in ./src/cobol, count lines, paragraphs, data items, copybooks, CALLs, files, and EXEC SQL statements; write reports/metrics.csv"
# Generate complexity report
autohand -p "Using reports/metrics.csv, list the programs with high modernisation difficulty and explain why; write reports/complexity.md"
# Sample metrics summary (the shape you ask for in the prompt)
program_metrics:
CUSTMAINT:
lines_of_code: 4523
cyclomatic_complexity: 89
data_items: 234
paragraphs: 67
copybooks_used: 12
called_programs: 8
files_accessed: 5
db2_statements: 23
modernisation_difficulty: high
ACCTPROC:
lines_of_code: 1234
cyclomatic_complexity: 24
data_items: 56
paragraphs: 18
copybooks_used: 4
called_programs: 2
files_accessed: 2
db2_statements: 0
modernisation_difficulty: medium
Business rule extraction
COBOL programs contain decades of encoded business logic. Extracting these rules into a structured format is essential for both documentation and accurate transformation.
# Extract business rules from COBOL (read-only)
autohand --plan -p "Extract the business rules in CUSTMAINT.cbl, citing paragraph names and line numbers"
# Generate business rules documentation
autohand -p "Document every business rule in CUSTMAINT.cbl with source line references; write docs/rules.md"
# Export to decision table format
autohand -p "Convert the rules in docs/rules.md into DMN decision tables; write docs/decisions.dmn"
Ask Autohand to identify and extract:
- Validation rules: Input validation, range checks, format verification
- Calculation logic: Interest calculations, fee computations, balance updates
- Decision logic: IF-THEN-ELSE branches, EVALUATE statements, condition hierarchies
- Data transformations: Format conversions, data enrichment, aggregations
# Extracted business rule example
rule:
id: BR-CUST-001
name: Customer Credit Limit Validation
source_program: CUSTMAINT
source_lines: 1234-1267
description: |
Validates customer credit limit based on account type
and payment history
conditions:
- if: ACCOUNT-TYPE = 'PREMIUM'
and: PAYMENT-HISTORY-SCORE > 750
then: MAX-CREDIT-LIMIT = 50000
- if: ACCOUNT-TYPE = 'STANDARD'
and: PAYMENT-HISTORY-SCORE > 650
then: MAX-CREDIT-LIMIT = 25000
- else: MAX-CREDIT-LIMIT = 10000
data_elements:
- ACCOUNT-TYPE
- PAYMENT-HISTORY-SCORE
- MAX-CREDIT-LIMIT
Data structure analysis
COBOL data structures often contain complex hierarchies, redefines, and packed decimal fields that require careful handling during modernisation.
# Analyse copybook structures
autohand --plan -p "Analyse the copybooks in ./src/copybooks: REDEFINES, OCCURS, COMP-3 fields, and level-88 conditions"
# Generate data dictionary
autohand -p "Build a field-level data dictionary from ./src/copybooks; write docs/data-dictionary.csv"
# Map to modern data types
autohand -p "Propose a Java type for each copybook field (BigDecimal for COMP-3, java.time for dates); write docs/type-mapping.md"
Handling complex data types
01 CUSTOMER-RECORD.
05 CUST-ID PIC 9(10).
05 CUST-NAME.
10 CUST-FIRST PIC X(20).
10 CUST-LAST PIC X(30).
05 CUST-BALANCE PIC S9(9)V99 COMP-3.
05 CUST-DATE-INFO.
10 CUST-DOB PIC 9(8).
10 CUST-DOB-R REDEFINES CUST-DOB.
15 DOB-YEAR PIC 9(4).
15 DOB-MONTH PIC 9(2).
15 DOB-DAY PIC 9(2).
Autohand transforms this to modern equivalents:
// Generated Java class
public class CustomerRecord {
private long custId;
private CustomerName custName;
private BigDecimal custBalance;
private LocalDate custDob;
public static class CustomerName {
private String firstName; // max 20 chars
private String lastName; // max 30 chars
}
}
Code transformation
Autohand supports multiple transformation strategies depending on your modernisation goals and timeline.
Rehosting (Lift and shift)
Move COBOL to a modern runtime with minimal code changes:
# Prepare for rehosting to Linux
autohand --plan -p "List the z/OS-specific code, JCL, and file handling that must change to run these programs on Linux with Micro Focus COBOL"
# Generate deployment artifacts
autohand --worktree rehost-linux -p "Write build and run scripts to compile ./src/cobol with Micro Focus COBOL on Linux"
Replatforming
Compile COBOL for a different platform while preserving the source:
# Replatform for cloud deployment
autohand --worktree replatform-aws -p "Add an ECS task definition and deployment notes for running the rehosted COBOL batch on AWS"
# Generate container configuration
autohand --worktree replatform-aws -p "Write a Dockerfile based on cobol-runtime:latest that compiles and runs the programs in ./src/cobol"
Refactoring to modern languages
Transform COBOL to Java, C#, or other modern languages:
# Transform to Java (in an isolated git worktree)
autohand --worktree cobol-to-java -p "Convert CUSTMAINT.cbl to Java 17, preserving every business rule"
# Transform with Spring Boot structure, as a reviewable patch
autohand -p "Convert CUSTMAINT.cbl to a Spring Boot service under ./generated/java" \
--patch --output custmaint.patch
git apply --check custmaint.patch
# Transform to C#
autohand --worktree cobol-to-csharp \
-p "Convert CUSTMAINT.cbl to C# on .NET under ./generated/csharp"
# Transformation conventions (example: save as docs/transformation.yaml and pass it
# with --append-sys-prompt docs/transformation.yaml, or summarise it in AGENTS.md)
transformation:
target_language: java
target_framework: spring-boot
# Code style preferences
style:
naming_convention: camelCase
package_structure: domain-driven
use_lombok: true
# Data layer options
data_layer:
database: postgresql
orm: jpa
generate_repositories: true
# Handling COBOL specifics
cobol_options:
preserve_comments: true
handle_goto: restructure # or 'preserve' or 'error'
packed_decimal: BigDecimal
date_handling: java.time
# Generated test coverage
testing:
generate_unit_tests: true
test_framework: junit5
coverage_target: 80%
CICS and transaction modernisation
CICS transactions require special handling to preserve transactional integrity in modern architectures.
# Analyse CICS transactions
autohand --plan -p "List the CICS transactions in ./src/cics, their EXEC CICS commands, COMMAREA layouts, and unit-of-work boundaries"
# Map BMS screens to modern UI
autohand --worktree bms-to-ui -p "Convert the BMS maps in ./src/bms to React components under ./generated/ui"
# Generate REST APIs from CICS programs
autohand -p "Write an OpenAPI spec for the CICS programs in ./src/cics; save it to api-spec.yaml"
# CICS transformation conventions (example; pass with --append-sys-prompt)
cics_transformation:
# Transaction handling
transactions:
model: microservices # or 'monolith'
boundary_detection: automatic
saga_pattern: choreography
# Screen modernisation
screens:
target: react # or 'angular', 'vue'
preserve_layout: true
accessibility: wcag-aa
# Communication patterns
communication:
sync: rest
async: kafka
generate_openapi: true
Batch processing modernisation
COBOL batch jobs often involve complex JCL procedures and sequential file processing that must be carefully modernised.
# Analyse JCL procedures
autohand --plan -p "Analyse the JCL in ./src/jcl: job steps, datasets, COND codes, and restart points"
# Transform batch to Spring Batch (long multi-file loop)
autohand --worktree batch-to-spring --auto-mode "Convert the nightly batch jobs in ./src/jcl to Spring Batch jobs" \
--max-iterations 30 --checkpoint-interval 5 --max-cost 20
# Generate workflow definitions
autohand -p "Write an Airflow DAG that reproduces the job order and dependencies in ./src/jcl/NIGHTLY.jcl"
# Batch transformation conventions (example; pass with --append-sys-prompt)
batch_transformation:
framework: spring-batch
# Job scheduling
scheduler: kubernetes-cronjob # or 'airflow', 'step-functions'
# File handling
file_processing:
input_format: detect # auto-detect fixed-width, CSV, etc.
output_format: preserve
large_file_strategy: streaming
# Restart and recovery
checkpoint:
enabled: true
interval: 1000 # records
storage: database
# Parallel processing
parallelization:
enabled: true
strategy: partition
max_threads: 8
DB2 and data migration
COBOL applications often use DB2 with embedded SQL. Autohand can rewrite these database access patterns, one program at a time, for you to review.
# Analyse DB2 usage
autohand --plan -p "List every EXEC SQL statement in ./src/cobol, the tables it touches, and its host variables"
# Generate database migration scripts (preview first)
autohand -p "Write PostgreSQL DDL equivalent to the DB2 schema in ./db/ddl under ./db/postgres" --dry-run
# Transform embedded SQL
autohand --worktree db2-to-jpa -p "Replace the embedded SQL in the converted Java code with JPA repositories"
# Database migration conventions (example; pass with --append-sys-prompt)
database_migration:
source: db2
target: postgresql
# Schema transformation
schema:
preserve_names: false
naming_convention: snake_case
handle_db2_types: true
# Data migration
data:
method: change-data-capture # or 'bulk-load'
validate_counts: true
preserve_sequences: true
# SQL transformation
sql:
cursor_handling: jdbc-resultset
host_variables: prepared-statements
null_handling: optional
Testing and validation
Ensuring functional equivalence between original COBOL and modernised code is critical. Ask Autohand to generate characterisation tests, then run them with your own test tools.
# Generate test cases from COBOL
autohand -p "Generate characterisation test cases for CUSTMAINT.cbl covering every EVALUATE branch; write them to tests/custmaint-cases.json"
# Create comparison test suite
autohand -p "Write JUnit 5 tests that run tests/custmaint-cases.json against the Java code in ./java and compare with the recorded COBOL output"
mvn test
# Run parallel execution tests in CI (no risky operations)
autohand -p "Compare the COBOL and Java outputs in ./test-output and report any mismatches" \
--restricted --output-format stream-json
Test generation strategies
# Test conventions (example; pass with --append-sys-prompt)
testing:
# Unit test generation
unit_tests:
framework: junit5
coverage_target: 85%
generate_mocks: true
# Integration tests
integration_tests:
database: testcontainers
external_services: wiremock
# Equivalence testing
equivalence:
# Compare COBOL output with transformed output
comparison_method: byte-by-byte # or 'semantic'
tolerance:
numeric: 0.0001
date: exact
# Test data sources
test_data:
production_samples: true
anonymization: required
edge_cases: generated
# Performance benchmarks
performance:
baseline_from: cobol
acceptable_variance: 10%
load_test_scenarios:
- name: peak_load
concurrent_users: 1000
duration: 30m
Migration execution
Execute the migration in controlled phases. Each wave runs in its own git worktree, so rolling back is a git operation.
# Plan migration waves (read-only)
autohand --plan -p "Using docs/deps.graphml, propose incremental strangler-fig migration waves; write docs/migration-plan.yaml"
# Execute migration wave
autohand --worktree wave-1 --auto-mode "Migrate the wave-1 programs in docs/migration-plan.yaml to Java and keep mvn test passing" \
--max-iterations 30 --checkpoint-interval 5 --max-cost 20
# Review migration progress
git log --oneline wave-1
# Rollback if needed
git revert <commit>
# Migration plan (example docs/migration-plan.yaml written in the step above)
migration_plan:
strategy: strangler-fig # or 'big-bang', 'parallel-run'
waves:
- name: wave-1
programs:
- CUSTINQ
- ACCTINQ
timeline: 2024-Q1
rollback_window: 30d
- name: wave-2
programs:
- CUSTMAINT
- ACCTMAINT
dependencies: [wave-1]
timeline: 2024-Q2
- name: wave-3
programs:
- BATCHPROC
- REPORTGEN
dependencies: [wave-2]
timeline: 2024-Q3
# Cutover strategy
cutover:
method: blue-green
traffic_shift: gradual # 10%, 25%, 50%, 100%
monitoring_period: 7d
# Rollback triggers
rollback_triggers:
error_rate: 1%
latency_increase: 50%
data_mismatch: any
Knowledge preservation
Capture institutional knowledge from COBOL experts before and during modernisation.
# Generate system documentation
autohand -p "Document every program in ./src/cobol: purpose, inputs, outputs, and call flow; write it under ./docs"
# Create knowledge base from code analysis
autohand -p "Build a knowledge base from the code and its comments; write docs/knowledge-base.md"
# Export training materials
autohand -p "Write an onboarding guide for developers new to this COBOL system; save it to docs/training-guide.md"
You can ask Autohand to produce:
- Program flow diagrams and data flow documentation
- Business rule catalogues with traceability
- Data dictionaries with field-level documentation
- Integration maps showing system boundaries
- Training materials for onboarding new team members
Best practices
Lessons learned from successful COBOL modernisation projects:
- Start with discovery: Invest time in understanding your portfolio before planning transformation.
- Preserve business logic: Focus on extracting and validating business rules early in the process.
- Test continuously: Build equivalence testing into your pipeline from day one.
- Migrate incrementally: Use strangler fig pattern to reduce risk and demonstrate value early.
- Capture knowledge: Document learnings and involve COBOL experts throughout the process.
- Plan for coexistence: Design for a transition period where COBOL and modern systems run in parallel.
- Measure success: Define clear metrics for modernisation success beyond just code conversion.