Program-to-Spec — Reverse Engineering
This skill reads existing ABAP code and produces a structured specification document — either a Functional Specification (what it does from a business perspective) or a Technical Specification (how it works from a developer perspective). The output is client-ready, not a code comment dump.
Iron Laws
NEVER PRODUCE A CODE WALKTHROUGH DISGUISED AS A SPEC. A spec explains business logic, data flows, and decisions — not line-by-line code commentary. If your output reads like "Line 42 calls BAPI_SALESORDER_CREATEFROMDAT2", you are producing a walkthrough, not a spec.
ALWAYS IDENTIFY THE BUSINESS PROCESS. Every program exists to support a business process. Identify it. Name it. Map the program's logic to process steps. If you cannot identify the business process, state the gap — do not invent one.
ALWAYS DOCUMENT ASSUMPTIONS AND GAPS. Reverse-engineered specs have blind spots — hardcoded values without explanation, dead code paths, unclear business rules. Document these explicitly as "Assumptions" and "Gaps for Clarification."
ALWAYS PRODUCE BOTH VIEWS. Generate both the functional spec (for business stakeholders) and the technical spec (for developers). They serve different audiences and neither is complete alone.
NEVER FABRICATE BUSINESS JUSTIFICATIONS. If the code does something without clear business reason, say "Business justification unclear — clarify with process owner." Do not invent justifications.
Rationalization Table
| Agent Will Try To... |
Why It Seems Reasonable |
Why It Fails |
Counter |
| Describe code instead of business logic |
"The code IS the specification" |
Code is implementation, not specification. Specs describe WHAT and WHY. Code describes HOW. |
Iron Law 1. Translate code into business terms. |
| Skip dead code analysis |
"Dead code doesn't matter" |
Dead code in SAP is often conditionally active (different plants, company codes, or periods). Document it. |
Analyze all code paths. Flag potentially dead code as "Conditional — verify activation criteria." |
| Invent business reasons for hardcoded values |
"This must be for tax calculation" |
Guessing business logic from hardcoded values is how wrong specs get written. |
Iron Law 5. Document as: "Hardcoded value [X] — business justification needed." |
| Produce one combined document |
"One document is simpler" |
Business users won't read technical details. Developers don't need business context. |
Iron Law 4. Two separate docs. |
Analysis Process
Step 1 — Code Inventory
Read the complete program and produce an inventory:
- Program type and technical name
- All includes with purposes
- All classes/methods with signatures
- All function module calls
- All database access (tables/views/CDS entities)
- All external interfaces (RFC, HTTP, file I/O)
- All screen elements (Dynpros, ALV, selection screen)
- All text elements and message classes
Step 2 — Business Process Mapping
Map the code logic to business process steps:
- Identify the trigger (user action, batch job, event)
- Trace the main execution path
- Identify branching logic and its business meaning
- Map database operations to business entities
- Identify output (reports, documents, updates, messages)
Step 3 — Data Flow Analysis
Document how data moves through the program:
- Input sources (selection screen, file, API, database)
- Transformations (calculations, validations, enrichments)
- Output destinations (database updates, files, APIs, UI)
- Error handling paths
Step 4 — Produce Functional Specification
# Functional Specification: [Program Name]
## Overview
**Program:** [Technical name]
**Business Process:** [Process name]
**Module:** [SAP module]
**Purpose:** [1-2 sentence business description]
## Business Context
[Why this program exists, what business need it serves]
## Scope
### In Scope
- [Business function 1]
- [Business function 2]
### Out of Scope
- [Explicitly excluded functions]
## Process Flow
1. [Business step 1] — [What happens]
2. [Business step 2] — [What happens]
3. ...
## Business Rules
| Rule | Description | Implementation |
|------|-------------|----------------|
| BR-01 | [Rule description] | [How it's enforced] |
## Input/Output
### Inputs
| Input | Source | Format | Validation |
|-------|--------|--------|------------|
### Outputs
| Output | Destination | Format | Trigger |
|--------|------------|--------|---------|
## Authorization
| Auth Object | Field | Values | Business Role |
|-------------|-------|--------|--------------|
## Assumptions & Gaps
| # | Item | Type | Status |
|---|------|------|--------|
| 1 | [Item] | Assumption/Gap | Needs clarification |
Step 5 — Produce Technical Specification
# Technical Specification: [Program Name]
## Technical Overview
**Program:** [Name] | **Type:** [Report/Module Pool/Class]
**Package:** [Package] | **Transport:** [If known]
**ABAP Release:** [Minimum required]
## Architecture
[Class diagram or structure overview]
## Object Inventory
| Object | Type | Purpose |
|--------|------|---------|
| [Name] | Class/FM/Include | [Purpose] |
## Data Model
### Tables/Views Accessed
| Table/CDS | Access Type | Purpose |
|-----------|------------|---------|
### Internal Data Structures
| Structure | Fields | Purpose |
|-----------|--------|---------|
## Method/Function Documentation
### [Method Name]
- **Purpose:** [What it does]
- **Parameters:** [In/Out/Changing/Returning]
- **Exceptions:** [What can go wrong]
- **Dependencies:** [What it calls]
## External Interfaces
| Interface | Type | Direction | System |
|-----------|------|-----------|--------|
## Error Handling
| Error | Handler | User Message | Recovery |
|-------|---------|-------------|----------|
## Performance Considerations
- [Known performance patterns — indexed access, buffering, parallel processing]
## Technical Gaps
| # | Item | Impact | Recommendation |
|---|------|--------|---------------|
Verification
Next Skill
After completing this skill, invoke: code-review (if the reverse-engineered code needs quality assessment)
Or: s4hana-migration (if the spec is being produced for migration analysis)
Cross-References
code-review — Review the code quality during reverse engineering
s4hana-migration — Use spec output for migration compatibility analysis
solution-architecture — Use spec output for architecture documentation
1---2name: program-to-spec3description: Use when reverse-engineering an existing ABAP program into a functional or technical specification. Reads code and produces structured documentation — not a code dump, a proper spec document that a consultant can hand to a client.4---56# Program-to-Spec — Reverse Engineering78This skill reads existing ABAP code and produces a structured specification document — either a Functional Specification (what it does from a business perspective) or a Technical Specification (how it works from a developer perspective). The output is client-ready, not a code comment dump.910## Iron Laws11121. **NEVER PRODUCE A CODE WALKTHROUGH DISGUISED AS A SPEC.** A spec explains business logic, data flows, and decisions — not line-by-line code commentary. If your output reads like "Line 42 calls BAPI_SALESORDER_CREATEFROMDAT2", you are producing a walkthrough, not a spec.13142. **ALWAYS IDENTIFY THE BUSINESS PROCESS.** Every program exists to support a business process. Identify it. Name it. Map the program's logic to process steps. If you cannot identify the business process, state the gap — do not invent one.15163. **ALWAYS DOCUMENT ASSUMPTIONS AND GAPS.** Reverse-engineered specs have blind spots — hardcoded values without explanation, dead code paths, unclear business rules. Document these explicitly as "Assumptions" and "Gaps for Clarification."17184. **ALWAYS PRODUCE BOTH VIEWS.** Generate both the functional spec (for business stakeholders) and the technical spec (for developers). They serve different audiences and neither is complete alone.19205. **NEVER FABRICATE BUSINESS JUSTIFICATIONS.** If the code does something without clear business reason, say "Business justification unclear — clarify with process owner." Do not invent justifications.2122## Rationalization Table2324| Agent Will Try To... | Why It Seems Reasonable | Why It Fails | Counter |25|---|---|---|---|26| Describe code instead of business logic | "The code IS the specification" | Code is implementation, not specification. Specs describe WHAT and WHY. Code describes HOW. | Iron Law 1. Translate code into business terms. |27| Skip dead code analysis | "Dead code doesn't matter" | Dead code in SAP is often conditionally active (different plants, company codes, or periods). Document it. | Analyze all code paths. Flag potentially dead code as "Conditional — verify activation criteria." |28| Invent business reasons for hardcoded values | "This must be for tax calculation" | Guessing business logic from hardcoded values is how wrong specs get written. | Iron Law 5. Document as: "Hardcoded value [X] — business justification needed." |29| Produce one combined document | "One document is simpler" | Business users won't read technical details. Developers don't need business context. | Iron Law 4. Two separate docs. |3031<HARD-GATE>32Before producing the specification:331. The source code must be fully read (all includes, function modules, classes)342. The program type must be identified (report, module pool, function group, class, interface, CDS view)353. All external dependencies must be cataloged (BAPIs, FMs, RFC destinations, CDS views)36If the code cannot be fully read (missing includes, broken references), document the gaps explicitly.37</HARD-GATE>3839## Analysis Process4041### Step 1 — Code Inventory42Read the complete program and produce an inventory:43- Program type and technical name44- All includes with purposes45- All classes/methods with signatures46- All function module calls47- All database access (tables/views/CDS entities)48- All external interfaces (RFC, HTTP, file I/O)49- All screen elements (Dynpros, ALV, selection screen)50- All text elements and message classes5152### Step 2 — Business Process Mapping53Map the code logic to business process steps:54- Identify the trigger (user action, batch job, event)55- Trace the main execution path56- Identify branching logic and its business meaning57- Map database operations to business entities58- Identify output (reports, documents, updates, messages)5960### Step 3 — Data Flow Analysis61Document how data moves through the program:62- Input sources (selection screen, file, API, database)63- Transformations (calculations, validations, enrichments)64- Output destinations (database updates, files, APIs, UI)65- Error handling paths6667### Step 4 — Produce Functional Specification6869```markdown70# Functional Specification: [Program Name]7172## Overview73**Program:** [Technical name]74**Business Process:** [Process name]75**Module:** [SAP module]76**Purpose:** [1-2 sentence business description]7778## Business Context79[Why this program exists, what business need it serves]8081## Scope82### In Scope83- [Business function 1]84- [Business function 2]8586### Out of Scope87- [Explicitly excluded functions]8889## Process Flow901. [Business step 1] — [What happens]912. [Business step 2] — [What happens]923. ...9394## Business Rules95| Rule | Description | Implementation |96|------|-------------|----------------|97| BR-01 | [Rule description] | [How it's enforced] |9899## Input/Output100### Inputs101| Input | Source | Format | Validation |102|-------|--------|--------|------------|103104### Outputs105| Output | Destination | Format | Trigger |106|--------|------------|--------|---------|107108## Authorization109| Auth Object | Field | Values | Business Role |110|-------------|-------|--------|--------------|111112## Assumptions & Gaps113| # | Item | Type | Status |114|---|------|------|--------|115| 1 | [Item] | Assumption/Gap | Needs clarification |116```117118### Step 5 — Produce Technical Specification119120```markdown121# Technical Specification: [Program Name]122123## Technical Overview124**Program:** [Name] | **Type:** [Report/Module Pool/Class]125**Package:** [Package] | **Transport:** [If known]126**ABAP Release:** [Minimum required]127128## Architecture129[Class diagram or structure overview]130131## Object Inventory132| Object | Type | Purpose |133|--------|------|---------|134| [Name] | Class/FM/Include | [Purpose] |135136## Data Model137### Tables/Views Accessed138| Table/CDS | Access Type | Purpose |139|-----------|------------|---------|140141### Internal Data Structures142| Structure | Fields | Purpose |143|-----------|--------|---------|144145## Method/Function Documentation146### [Method Name]147- **Purpose:** [What it does]148- **Parameters:** [In/Out/Changing/Returning]149- **Exceptions:** [What can go wrong]150- **Dependencies:** [What it calls]151152## External Interfaces153| Interface | Type | Direction | System |154|-----------|------|-----------|--------|155156## Error Handling157| Error | Handler | User Message | Recovery |158|-------|---------|-------------|----------|159160## Performance Considerations161- [Known performance patterns — indexed access, buffering, parallel processing]162163## Technical Gaps164| # | Item | Impact | Recommendation |165|---|------|--------|---------------|166```167168## Verification169170- [ ] Complete code inventory produced (all includes, classes, FMs cataloged)171- [ ] Business process identified and mapped172- [ ] Functional specification produced in structured format173- [ ] Technical specification produced in structured format174- [ ] All assumptions explicitly documented175- [ ] All gaps flagged for clarification176- [ ] No fabricated business justifications177- [ ] Both specs are independently readable by their target audience178179## Next Skill180181After completing this skill, invoke: `code-review` (if the reverse-engineered code needs quality assessment)182Or: `s4hana-migration` (if the spec is being produced for migration analysis)183184## Cross-References185186- `code-review` — Review the code quality during reverse engineering187- `s4hana-migration` — Use spec output for migration compatibility analysis188- `solution-architecture` — Use spec output for architecture documentation