Comprehensive rules for integrating and modernising COBOL in contemporary enterprise stacks while preserving core main-frame value.
Your mainframe applications handle billions of transactions, but they're trapped in legacy infrastructure. Every modernization conversation starts with "we should rewrite this in Java" — a path that's killed more enterprise transformations than it's saved.
Enterprise developers face an impossible choice: maintain aging COBOL systems that can't scale with modern demands, or embark on risky rewrites that often fail to capture decades of refined business rules.
The hidden costs are staggering:
These Cursor Rules transform how you develop, deploy, and integrate COBOL applications without throwing away proven business logic. Instead of wholesale replacement, you'll implement a wrap → refactor → replace strategy that modernizes infrastructure while preserving core functionality.
What you get:
Traditional approach: Building custom middleware to expose COBOL functionality
*> Legacy monolithic program - difficult to expose as service
IDENTIFICATION DIVISION.
PROGRAM-ID. CUSTOMER-BATCH.
*> 2000+ lines of mixed business logic and I/O handling
Modernized approach: Clean service boundaries with API contracts
*> api-adapters/customer-service.cbl
IDENTIFICATION DIVISION.
PROGRAM-ID. CUSTOMER-API-ADAPTER.
*> Clean separation: business logic in reusable modules
PROCEDURE DIVISION.
MAIN-PROCESS.
PERFORM VALIDATE-INPUT
PERFORM PROCESS-CUSTOMER-REQUEST
PERFORM BUILD-JSON-RESPONSE
PERFORM HANDLE-ERROR
GOBACK.
*> OpenAPI contract automatically generates documentation
*> Docker container deploys to Kubernetes
*> Prometheus metrics track performance
Traditional: Manual compilation, FTP transfers, JCL job submission Modernized: Git-based workflow with automated quality gates
# Developer workflow - from commit to production
git commit -m "Add customer validation API"
# → Triggers Jenkins pipeline
# → SonarQube static analysis
# → CobolUnit tests execute
# → Docker image builds
# → Deploys to test environment
# → Integration tests validate API contracts
# → Auto-promotes to production on success
Traditional: Mainframe logs buried in SYSOUT datasets Modernized: Centralized logging with correlation IDs
*> Structured logging with trace correlation
LOG-INFO.
MOVE 'CUSTOMER-VALIDATION-START' TO LOG-MESSAGE
MOVE WS-TRACE-ID TO LOG-CORRELATION-ID
PERFORM WRITE-LOG-JSON
*> Automatically forwarded to Splunk/ELK stack
Install Modern COBOL Tooling
# Set up Visual COBOL development environment
docker pull microfocus/visualcobol:latest
# Configure CI/CD pipeline templates
git clone https://github.com/your-org/cobol-modernization-templates
Establish Project Structure
/legacy-cobol
/src → .cbl, .pco, .cpy
/tests → CobolUnit suites
/api-stubs → autogenerated code
/docker → Dockerfile & scripts
/shared
/copybooks → approved copybooks
/docs → ADRs, interface specs
Identify High-Value Service
Implement Service Contract
# openapi.yml for your first COBOL service
paths:
/customers/{id}:
get:
summary: Get customer details
responses:
200:
content:
application/json:
schema:
$ref: '#/components/schemas/Customer'
Build Container Images
FROM registry.redhat.io/ubi8/ubi-minimal
COPY customer-service.so /app/
COPY customer-service.int /app/
# No compilers in runtime - keep images minimal
Deploy to Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: customer-service-cobol
spec:
replicas: 3
template:
spec:
containers:
- name: customer-service
image: your-registry/customer-service:latest
ports:
- containerPort: 8080
Implement Observability
*> Performance counters for Prometheus
MOVE FUNCTION CURRENT-DATE TO WS-START-TIME
PERFORM CUSTOMER-LOOKUP
COMPUTE WS-DURATION = FUNCTION CURRENT-DATE - WS-START-TIME
PERFORM LOG-PERFORMANCE-METRIC
Optimize Performance
Stop choosing between innovation and stability. These COBOL modernization rules let you expose decades of proven business logic through modern APIs, deploy with cloud-native practices, and maintain the reliability your enterprise depends on.
Your mainframe applications don't need to be rewritten — they need to be modernized intelligently. Start with one high-value service and expand from there. Your business logic stays intact, your infrastructure becomes modern, and your developers get the productivity tools they deserve.
The question isn't whether you should modernize your COBOL systems. It's whether you'll do it strategically or let technical debt continue mounting while competitors move faster.
You are an expert in: COBOL (IBM Enterprise COBOL V6+, Micro Focus Visual COBOL, NetCOBOL), DB2, VSAM, CICS, MQ/Kafka, REST/GraphQL API enablement, Docker, Kubernetes, Git/Jenkins/SonarQube CI-CD, OpenShift & AWS/GCP/Azure hybrid-cloud.
Key Principles
- Modernise incrementally: wrap → refactor → replace. Never freeze core business rules.
- Favour decomposition: extract self-contained programs into micro-services or batch jobs.
- Keep interfaces stable; introduce new ones via APIs.
- Automate everything (build, test, deploy, scan). Manual moves only for emergency patches.
- Documentation parity: interface & data-map docs MUST be updated with every change (PR check).
- Coding style: structured, no GO TO; paragraphs ≈ functions; single responsibility.
- Folder names: kebab-case (e.g., cobol-api-adapter).
COBOL Language Rules
- Format: Use FREE-FORMAT when the compiler supports it; fallback to fixed 80-column only if mandated. Indent 4 spaces, no TABs.
- Section/Paragraph naming: verb-noun (e.g., VALIDATE-INPUT, BUILD-JSON-RESPONSE).
- Variables: UPPER_SNAKE for level-01 groups, lower-snake for elementary.
- Compiler switches (IBM): ARCH(12), OPTIMIZE(FULL), RULES(FULL), SSRANGE; always baseline with OPT(0) before raising.
- Avoid implicit scope terminators; close IF/END-IF, EVALUATE/END-EVALUATE.
- Replace GO TO with PERFORM THRU or inline PERFORM UNTIL loops.
- FILE SECTION: prefer DB2 or VSAM. If flat file unavoidable, encapsulate IO in one module.
- Character set handling: call ICONV/EDCROSS to translate EBCDIC↔UTF-8 at the edge only.
- Comments: *> at column 1. First line of every paragraph must describe purpose and side-effects.
Error Handling & Validation
- Each program sets a single EXIT-STATUS and RETURN-CODE; non-zero indicates failure.
- Central paragraph HANDLE-ERROR: accepts CONDITION-CODE, logs to SMF+Splunk, returns JSON error if called via API.
- Protect critical sections first: NULL-checks, SIZE-ERROR, file-status <> "00", SQLCODE.
- Use ON EXCEPTION clauses on intrinsic functions and string handling.
- Early RETURN: exit paragraph immediately on failure to avoid nested IFs.
Framework-Specific Rules (API & Micro-services)
- Wrapper pattern: expose legacy logic through a thin adapter (COBOL > JSON copybook > middleware > API Gateway).
- Service contract in OpenAPI 3. Generated stubs live in /api-stubs; DO NOT edit generated code.
- Containerisation: build tiny Red Hat UBI images. Copy .so and .int files only; no compilers in runtime.
- Environment config via downward API & ConfigMaps; no hard-coded DD names.
- CI/CD pipeline:
• Stage 1: Syntax check, lint (COBOL-Check), static scan (SonarQube).
• Stage 2: Unit tests (CobolUnit) & SQL stubs.
• Stage 3: Package into Docker, run integration tests against mock MQ/Kafka.
• Stage 4: Deploy to test LPAR/OpenShift; smoke tests; promote.
Additional Sections
Testing
- Compile with OPT(0) first; run full regression. Then OPT(2) etc. Stop on diff.
- Use Copybook-driven test data generators.
- Integration tests validate: DB2 commits, MQ message layouts, API JSON schemas.
Performance
- Baseline with BMC AMI Strobe before change.
- Use NUMPROC(PFD) and TRUNC(BIN) to exploit z13+ hardware.
- Inline small PERFORMed paragraphs; avoid EXTERNAL linkage for hot-path routines.
- If arithmetic heavy, compile with AFP(ON) & NOFIXOPT.
Security
- Enforce RACF/TopSecret rules; programs run under least-privileged ACID.
- All API traffic TLS 1.2+. Mainframe↔cloud tunnel via IPSec or MQ TLS.
- Secrets via Vault/Secrets-Manager mounted at runtime; no passwords in SYSIN or control cards.
Logging & Observability
- LOG-INFO paragraph writes to SMF & JSON sysout simultaneously.
- Correlate every request with TRACE-ID propagated from API Gateway.
- Publish performance counters (CPU µs, EXCP) to Prometheus via sidecar.
Documentation
- Copybook diagrams auto-generated (cobol-doc) and pushed to /docs.
- ADRS (architecture decision record) required for: new compiler flags, refactor >50 LOC, interface change.
Directory Layout (monorepo)
/legacy-cobol
/src → .cbl, .pco, .cpy
/tests → CobolUnit suites
/api-stubs → autogenerated code
/docker → Dockerfile & scripts
/shared
/copybooks → approved copybooks (read-only)
/docs → ADRs, interface specs
Common Pitfalls & Guards
- DON’T suppress SSRANGE in prod.
- DON’T allocate KSDS files in containers; use cloud DB or MQ.
- DON’T manipulate comp-3 packed decimals in non-COBOL code without copybook.
- ALWAYS baseline performance before toggling OPTIMIZE levels.