agentleFS
CreativeActtechCreativeActtech/llm-skills/skills/example-skill/cobol-to-java/SKILL.md

cobol-to-java

Skill2 starsChanged 7 months agoMITView on GitHub

Creates a clean, compilable Java class (or set of classes) that mirrors the logic of the supplied COBOL program while preserving business rules and data structures.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 3 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use when the user supplies COBOL modules and asks for Java refactoring, migration, or “convert this COBOL to Java”.

    line 5
  2. Distinctive:

    Do NOT use for simple syntax highlighting, for generating only pseudocode, or when the user explicitly wants to keep the code in COBOL.

    line 6
  3. Very specific:

    IF the text contains IDENTIFICATION DIVISION *or* typical COBOL hierarchy (DATA DIVISION, PROCEDURE DIVISION) → proceed.

    line 33
  4. Distinctive:

    Use a lightweight COBOL AST parser (or regex‑based stage‑wise extraction) to obtain:

    line 37
  5. Very specific:

    IF a COBOL construct has no direct Java equivalent (e.g., EXEC CICS, CALL to external C programs) → add a comment // TODO: Manual migration …

    line 74
  6. Very specific:

    Run javac -Xlint on the generated string (optional, not executed here).

    line 78

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

COBOL → Java Refactor Skill

Creates a clean, compilable Java class (or set of classes) that mirrors the logic of the supplied COBOL program while preserving business rules and data structures.

🎯 When to Use

  • Positive triggers
    • User says “convert this COBOL program to Java”, “refactor COBOL code into a Java class”, or “migrate legacy COBOL to modern Java”.
    • The request includes raw COBOL source (e.g., IDENTIFICATION DIVISION. block) and an expectation of a Java output.
  • Negative triggers
    • The user only wants a line‑by‑line comment translation or a high‑level description without actual code generation.
    • The user asks for a COBOL‑only solution (e.g., “debug this COBOL program”).
    • The request is for a language other than Java (e.g., “convert to C#”).

🧠 Core Workflow

  1. Detect Input Intent
    • IF the text contains IDENTIFICATION DIVISION or typical COBOL hierarchy (DATA DIVISION, PROCEDURE DIVISION) → proceed.
    • ELSE → return an error JSON (see fallback).
  2. Parse COBOL Source
    • Use a lightweight COBOL AST parser (or regex‑based stage‑wise extraction) to obtain:
      • Program name (IDENTIFICATION DIVISION → PROGRAM-ID).
      • Data structures (WORKING-STORAGE SECTION, 01 level items).
      • Procedure paragraphs and PERFORM calls.
    • Record any COPY statements for external includes (note them in the report).
  3. Map COBOL Constructs to Java Equivalents

    COBOL ElementJava MappingRemarks
    01 level data items (numeric, alphanumeric)int, long, double, String (use java.math.BigDecimal for packed decimals)Preserve picture clause semantics.
    TABLEs (OCCURS)List<T> or T[]Size‑constant tables become arrays; variable‑size become ArrayList.
    PERFORM … (inline)Direct method callInline code is in‑lined; separate paragraphs become private methods.
    PERFORM … THRU …Call chain of generated private methods.
    IF … ELSE …if (…) { … } else { … }Preserve condition evaluation order.
    EVALUATEswitch (or nested if)Map literal/value comparisons.
    STOP RUNreturn; or end of main method.
    DISPLAYSystem.out.printlnHandles string conversion.
    ACCEPTScanner or method parameter (depends on context).
    READ/WRITE on filejava.io streams or java.nio (file‑specific handling noted).
    CALL (subprogram)Separate Java class or static method call.
  4. Generate Java Boilerplate

    • Package & Imports (added as needed):
      import java.util.*;
      import java.math.BigDecimal;
      // Additional imports for file I/O, date handling, etc.
    • Class Declaration – name derived from PROGRAM-ID (PascalCase).
    • Fields – one for each COBOL data item, respecting visibility (private).
    • Constructor – initializes fields with default values (derived from VALUE clause).
    • Method(s) – one for each COBOL paragraph; the main paragraph becomes public static void main(String[] args).
  5. Insert TODO / Warning Annotations

    • IF a COBOL construct has no direct Java equivalent (e.g., EXEC CICS, CALL to external C programs) → add a comment // TODO: Manual migration required for <construct>.
  6. Validate Java Syntax (lightweight)

    • Run javac -Xlint on the generated string (optional, not executed here).
    • IF syntax errors are detected → list them in confidence_issues.
  7. Produce Diff‑Ready Report

    • Summarize: number of COBOL paragraphs → Java methods, data items → fields, imports added, and any unmapped constructs.

📋 Output Format

1️⃣ Refactor Report (JSON)

{
  "status": "success",
  "cobol_program_id": "PAYROLLPROC",
  "java_class_name": "PayrollProc",
  "fields_generated": 14,
  "methods_generated": 7,
  "imports_added": ["java.util.*", "java.math.BigDecimal"],
  "unmapped_constructs": ["EXEC CICS SEND MAP"],
  "confidence_issues": [
    "Packed‑decimal (PIC S9(7)V99) mapped to BigDecimal – verify scale handling",
    "File I/O using COBOL SELECT statements requires manual review"
  ]
}

2️⃣ Generated Java Source (truncated for brevity)

package com.example.migration;

import java.util.*;
import java.math.BigDecimal;

public class PayrollProc {

    // === Fields (from COBOL WORKING‑STORAGE) ===
    private String employeeId;
    private BigDecimal grossPay;
    private BigDecimal taxWithheld;
    private int hoursWorked;
    // ... other fields ...

    public PayrollProc() {
        // Default initialization (if VALUE clauses exist)
        this.employeeId = "";
        this.grossPay = BigDecimal.ZERO;
        this.taxWithheld = BigDecimal.ZERO;
        this.hoursWorked = 0;
    }

    public static void main(String[] args) {
        PayrollProc proc = new PayrollProc();
        proc.initialize();
        proc.calculatePay();
        proc.printReport();
    }

    private void initialize() {
        // Equivalent of COBOL INITIALIZE paragraph
        // TODO: Populate fields from input source (e.g., file, DB)
    }

    private void calculatePay() {
        // Translated from COBOL CALC‑PAY paragraph
        this.grossPay = BigDecimal.valueOf(this.hoursWorked)
                         .multiply(BigDecimal.valueOf(20.0));
        // ... other calculations ...
    }

    private void printReport() {
        System.out.println("Employee: " + employeeId);
        System.out.println("Gross Pay: " + grossPay);
        System.out.println("Tax Withheld: " + taxWithheld);
    }

    // === Additional methods generated from other COBOL paragraphs ===
    // TODO: Manual migration required for EXEC CICS SEND MAP
}

3️⃣ Suggested Post‑Processing Commands

# Save the generated source
cat > PayrollProc.java <<'EOF'
<PASTE_JAVA_CODE_ABOVE>
EOF

# Compile to verify syntax
javac PayrollProc.java

# Run (if a main method is present)
java com.example.migration.PayrollProc

⚠️ Fallback Behavior

  • Already Java‑Ready (user mistakenly provides Java code):
{
  "status": "partial",
  "message": "Input appears to be Java code, not COBOL. No transformation performed.",
  "suggestion": "If you need a Java‑to‑Java refactor, use a dedicated Java‑formatter skill."
}
  • Unrecognizable Input (no COBOL structure detected):
{
  "status": "error",
  "message": "Unable to locate COBOL program structure (IDENTIFICATION DIVISION missing). Please provide valid COBOL source."
}
  • Critical Mapping Gaps (e.g., proprietary CICS commands):
{
  "status": "warning",
  "message": "Several COBOL constructs could not be automatically mapped.",
  "unmapped_constructs": ["EXEC CICS SEND MAP", "CALL 'EXTERNAL.CBL'"],
  "next_steps": "Review the generated TODO comments and implement platform‑specific logic manually."
}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.