/sap-gen-code:sap-docs-extract <path-to-document OR work-folder OR _raw.txt>from sap-gen-code
Extracts structured SAP design document content (program summaries, domains, tables, etc.) from Excel/Word/PDF into separate text files for downstream processing.
Ships in sap-gen-code. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You read a SAP design document (Excel / Word / PDF) and extract structured
information into separate files by information type. The previous two-step
flow (sap-docs-convert → sap-docs-extract) is now folded into this single
skill: if the input is a raw document, extract handles the format conversion
itself before structuring.
Task: $ARGUMENTS
| File | Purpose |
|---|---|
<SAP_DEV_CORE_SHARED_DIR>/rules/skill_operating_rules.md | Mandatory operating rules |
<SAP_DEV_CORE_SHARED_DIR>/rules/ddic_excel_layout_rules.md | DDIC Excel-spec authoring rules — naming-suffix consistency, primitive-type-as-DTEL trap, currency reference, column order, no merged data cells. Detect spec-side defects at extract time. |
<SAP_DEV_CORE_SHARED_DIR>/rules/language_independence_rules.md | GUI-scripting language independence — offline extractor, but rule applies to downstream deploy skills the spec feeds |
Resolve work_dir via the env-aware helper — do NOT take work_dir from a direct settings.json read (that ignores the SAPDEV_AI_WORK_DIR env var and userconfig.json). Use the WORK_DIR= value printed by:
powershell -NoProfile -ExecutionPolicy Bypass -Command ". '<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_settings_lib.ps1'; . '<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_connection_lib.ps1'; Write-Output ('WORK_DIR=' + (Get-SapWorkDir)); Write-Output ('RUN_TEMP=' + (Get-SapRunTemp))"
The settings note below still applies to the OTHER keys.
Settings reads/writes follow <SAP_DEV_CORE_SHARED_DIR>/rules/settings_lookup.md — merge per-key on the .value field (env var → settings.local.json → userconfig.json → settings.json); non-per-connection writes go to userconfig.json. Resolve cross-plugin paths: 3 levels up from <SKILL_DIR>, then into sap-dev-core\settings.json and (if present) sap-dev-core\settings.local.json. Read custom_url, design_docs_url, source_code_url.
| Setting | Default if blank |
|---|---|
work_dir | C:\sap_dev_work |
custom_url | {work_dir}\custom |
design_docs_url | {work_dir}\design_docs |
source_code_url | {work_dir}\source_code |
Set {WORK_TEMP} = {work_dir}\temp. Ensure it exists:
cmd /c if not exist "{WORK_TEMP}" mkdir "{WORK_TEMP}"
Set {RUN_TEMP} = the RUN_TEMP= value printed above (Get-SapRunTemp
mints + creates a fresh per-run dir {work_dir}\temp\run_<id>) — the per-run
scratch dir holding the log state file. Mint it once here and reuse the same
value in Step 0.5 and Final — do not call Get-SapRunTemp again later (each
call mints a NEW dir, and the -Action end state-file lookup would miss).
Start a structured log run. The shared helper persists run_id to a state
file so subsequent steps and Step 4 can append to the same run. Logging is
best-effort — if userConfig.log_enabled=false or the lib can't load, the
helper silently no-ops.
<SAP_DEV_CORE_SHARED_DIR> resolves to plugins/sap-dev-core/shared/.
State file: {RUN_TEMP}\sap_docs_extract_run.json
powershell -ExecutionPolicy Bypass -File "<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_log_helper.ps1" -Action start -StateFile "{RUN_TEMP}\sap_docs_extract_run.json" -Skill sap-docs-extract -ParamsJson "{\"input\":\"<USER_INPUT_PATH>\"}"
Extract the path argument from $ARGUMENTS.
If no path is given, ask the user:
"Please provide the path to the design document (.xlsx / .docx / .pdf), an existing work folder, or a
_raw.txtfile."
Classify the argument using this decision table (evaluate rules in order; the first matching rule wins):
| # | Condition | Action | Section |
|---|---|---|---|
| 1 | Argument is a file ending in _raw.txt | Use it directly | 1a |
| 2 | Argument is an existing directory | Locate the single _raw.txt inside | 1b |
| 3 | Argument is a file with extension .xlsx, .docx, or .pdf | Create work folder and dump to _raw.txt | 1c |
| 4 | Argument is a file with extension .doc (legacy binary Word — no working extraction path) | Abort with: ERROR: .doc (legacy binary Word) is not supported. Open the file in Word, save it as .docx, then re-run /sap-docs-extract. | — |
| 5 | None of the above | Abort with: ERROR: Unsupported file format. | — |
*_raw.txt)If the argument ends with _raw.txt and exists as a file → use it directly.
Set {work_folder} = the parent directory of that file.
Set {doc_name} = filename minus _raw.txt suffix.
If the argument is a directory, locate the single *_raw.txt file inside it:
Get-ChildItem -Path "{work_folder}" -Filter "*_raw.txt"
If zero or multiple _raw.txt files exist, abort with the error message:
"ERROR: Expected exactly one _raw.txt file in the directory."
If the argument is a document file with one of those extensions, create a fresh work folder and dump the document to plain text first:
Derive names:
{doc_name} = filename without extension
(e.g., spec_sample from spec_sample.xlsx){doc_name} exceeds 50 characters, truncate to 50.{timestamp} = current date/time as yyyyMMddHHmmss{work_folder} = {source_code_url}/work/{doc_name}_{timestamp}Create the work folder:
mkdir -p "{work_folder}"
Dump the document to {work_folder}/{doc_name}_raw.txt using the right
reader for the file type:
For Excel (.xlsx) — Python with openpyxl:
import openpyxl
path = r"THE_DOCUMENT_PATH"
output = r"THE_OUTPUT_PATH"
def clean(c):
# Cell sanitization (chain contract): embedded TAB -> single space,
# embedded newline (Alt+Enter cell, routine in JA specs) -> "; ".
# MUST happen BEFORE cells are joined with \t and rows with \n.
s = "" if c is None else str(c)
s = s.replace("\t", " ")
s = s.replace("\r\n", "; ").replace("\n", "; ").replace("\r", "; ")
return s
wb = openpyxl.load_workbook(path)
lines = []
for sheet_name in wb.sheetnames:
ws = wb[sheet_name]
lines.append(f"========== Sheet: {sheet_name} (rows={ws.max_row}, cols={ws.max_column}) ==========")
for row_idx, row in enumerate(ws.iter_rows(min_row=1, max_row=ws.max_row, values_only=True), start=1):
if any(c is not None for c in row):
cells = [clean(c) for c in row]
lines.append(f"R{row_idx}\t" + "\t".join(cells))
lines.append("")
with open(output, "w", encoding="utf-8") as f:
f.write("\n".join(lines))
For Word (.docx) — Python with python-docx (same clean() sanitization
for table cells — .docx cells routinely contain newlines):
from docx import Document
def clean(s):
s = s.replace("\t", " ")
return s.replace("\r\n", "; ").replace("\n", "; ").replace("\r", "; ")
doc = Document(r"THE_DOCUMENT_PATH")
lines = []
for para in doc.paragraphs:
if para.text.strip():
lines.append(para.text)
for table_idx, table in enumerate(doc.tables):
lines.append(f"========== Table {table_idx + 1} ==========")
for row in table.rows:
cells = [clean(cell.text.strip()) for cell in row.cells]
lines.append("\t".join(cells))
with open(r"THE_OUTPUT_PATH", "w", encoding="utf-8") as f:
f.write("\n".join(lines))
For Word (.doc) — legacy binary OLE format: there is no working extraction path (the Read tool cannot parse it). Abort with:
"ERROR: .doc (legacy binary Word) is not supported. Open the file in Word and save it as .docx, then re-run /sap-docs-extract."
For PDF (.pdf) — use the Read tool on the .pdf path; write the extracted text to the output file with the Write tool. Apply the same sanitization to any table-like lines you emit with tab-separated cells.
Cell sanitization is part of the chain contract: in
_raw.txt(and every_*.txtderived from it) 1 row = 1 line and 1 cell = 1 field — an embedded TAB becomes a single space, an embedded newline becomes"; ", always applied BEFORE joining cells with TAB and rows with newline. Downstream consumers (/sap-docs-convert,/sap-docs-check,/sap-gen-abap) rely on this invariant when splitting rows and cells.
After 1c completes you have a populated {work_folder}/{doc_name}_raw.txt.
All output files in subsequent steps MUST be written to {work_folder} — the
same directory that contains the _raw.txt file. Read the entire _raw.txt
file using the Read tool before proceeding to Step 2.
For .xlsx inputs, open the original workbook with openpyxl and look for
a (Meta) Layout sheet. This sheet is the per-workbook contract that
tells the parser how every other sheet maps to an output file. The
canonical spec_template.xlsx ships with one populated.
If the workbook has no (Meta) Layout sheet, abort with:
ERROR: This workbook has no (Meta) Layout sheet. Either:
- Copy your data into the canonical spec_template.xlsx (it ships with
a Meta sheet), OR
- Run /sap-docs-layout bootstrap <workbook> to add a Meta sheet from
the canonical template.
For non-xlsx inputs (.docx, .pdf), there is no Meta sheet —
proceed with text-based extraction by inspecting _raw.txt directly and
inferring sections from natural document structure (headings, table
boundaries, well-known keywords).
For xlsx inputs, walk the (Meta) Layout SECTIONS rows. For each row:
Locate the named worksheet by sheet_name.
Resolve the section's data anchor — first by anchor_named_range, else
by an anchor_keyword scan:
[4]SourceTemplateSheet!$A18 (the [N] prefix points at a
DIFFERENT workbook, and the sheet name is the source template's — often
in another language); its sheet does not exist in THIS workbook, so it
is NOT resolvable — fall through to the keyword
scan. (Treat any destination sheet not in wb.sheetnames as a miss; do
not let a broken external-ref named range abort the section.)anchor_keyword, across ALL columns (top-to-bottom,
then left-to-right within each row) — not just column A. A section's
anchor keyword may live in any column: e.g. ddic_tables_fields uses
FIELDNAME, which sits in column C (after the Table join column
in A and No in B), so a column-A-only scan never finds it and the
fields half of _tables.txt silently comes out empty. The matched
cell's row is the header row; data starts data_starts_offset rows
below.WARN: section <key>: anchor '<anchor_keyword>' not found on sheet '<sheet_name>' — section skipped and skip the section. NEVER silently
write an empty or partial output file — a visible WARN is required so a
missing table/section is never mistaken for "the spec had none".Dispatch on format:
kv — read 2-column key/value pairs from the anchor row downward,
emit as KEY\tVALUE lines.tsv — read the header row at the anchor, then data rows below;
emit as TSV with the COLUMNS table's output_column order.image — handled in Step 3.5.text — handled in Step 3.4.Apply each column's transform (trim, upper, lower, int,
bool_X) and default_if_blank per the COLUMNS table.
Forward-fill the first output column on tsv sections. After the
COLUMNS-driven extraction emits rows, walk the rows top-down: any data
row whose first column is blank inherits the most recent non-blank
first-column value. The header row is never filled. The carry pointer
PERSISTS across sections that write to the same output_file —
so a later section (e.g. ddic_tables_fields) inherits the join key
(TABLE) from the earlier section (ddic_tables_metadata.TABLE_NAME)
when the spec author left the FK column blank on every field row. For
multi-table specs the author still must put the table name on the
first field row of each table — subsequent rows of that table carry
automatically.
Why this is conservative: if every field row already has an explicit
TABLE value, forward-fill is a no-op (nothing is blank to fill). If
ALL upstream sections produce zero rows AND the current section has
blank first column, the first row stays blank — a downstream
/sap-docs-check (DDIC dimension) finding surfaces the authoring issue.
For non-xlsx inputs (no Meta sheet), apply hardcoded heuristics: scan the raw text for the standard sections (Cover, DDIC, Process, Validation, etc.) using natural document structure. This path is best-effort and may miss customer-specific extensions.
If the original input was an .xlsx file AND the workbook contains a
(Meta) Layout sheet listing one or more sections with format = text,
dump those sheets verbatim now. A text section has no header row, no
TSV columns — the customer wrote free-form notes anywhere on the sheet.
Skip this step entirely when:
_raw.txt file or an existing work folder, OR(Meta) Layout sheet, ORformat = text.For each format = text section in (Meta) Layout:
sheet_name and output_file columns..xlsx with openpyxl, locate the named worksheet.worksheet.max_row. For each row:
worksheet.max_columnNone with empty string{work_folder}/{doc_name}{output_file} as UTF-8.Reference Python:
import openpyxl
wb = openpyxl.load_workbook(xlsx_path, data_only=True)
ws = wb[sheet_name]
lines = []
for row in ws.iter_rows(min_row=3, max_row=ws.max_row,
values_only=True):
cells = ["" if c is None else str(c) for c in row]
while cells and cells[-1] == "":
cells.pop()
lines.append("\t".join(cells))
while lines and lines[-1].strip() == "":
lines.pop()
out_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
A completely empty supplement sheet results in an empty _supplement.txt
file — write the file anyway (zero bytes is a valid signal: customer
opted out of supplemental notes).
If the original input was an .xlsx file (sub-step 1c) AND the workbook
contains a (Meta) Layout sheet listing one or more sections with
format = image, extract those images now. Images live in the binary
.xlsx archive — they are NOT in {doc_name}_raw.txt (the text dump in
Step 1c discards images). Source = the original .xlsx, not _raw.txt.
Skip this step entirely when:
_raw.txt file or an existing work folder (no .xlsx
to read images from), OR(Meta) Layout sheet (legacy template), OR(Meta) Layout has format = image.For each format = image section in (Meta) Layout:
sheet_name and output_file columns..xlsx with openpyxl, locate the named worksheet.worksheet._images — the list of embedded Image objects.WARN: section <key>: sheet "<sheet_name>" has no embedded images. Skipping image extraction.
{work_folder}/{doc_name}{output_file} (note: output_file already
begins with an underscore, e.g. _selection_screen_layout.png).Reference Python:
import openpyxl
from PIL import Image as PILImage
import io
wb = openpyxl.load_workbook(xlsx_path)
ws = wb[sheet_name]
if not ws._images:
print(f"WARN: sheet '{sheet_name}' has no embedded images")
else:
img = ws._images[0]
pil = PILImage.open(io.BytesIO(img._data()))
pil.save(out_path, format="PNG")
If multiple images exist on one sheet, V1 saves only the first and emits a
warning naming the count. (V2 may save additional images as
<output_file_stem>_2.png, _3.png, etc.)
Write each file to {work_folder} (the same folder that contains the
_raw.txt file) using the Write tool. All files use UTF-8 encoding.
Overwrite policy: If a target file already exists, OVERWRITE it without prompting. Do not back up, rename, or skip existing files. The Write tool replaces the file content, which is the desired behaviour.
Multiple sections → one output_file (concatenate, do NOT overwrite): when
two or more (Meta) Layout SECTIONS write to the SAME output_file (e.g.
ddic_tables_metadata and ddic_tables_fields both → _tables.txt),
accumulate their blocks in SECTIONS order into a single file content, then
write once — the later section must NOT overwrite the earlier one's rows.
Precede each block with a # === <SECTION_KEY> === banner (e.g.
# === METADATA ===, # === FIELDS ===) so the consumer (/sap-gen-abap)
can split them. This is the same output_file the Step 3 forward-fill carry
pointer persists across. A section skipped by the Step 3 WARN contributes no
block — but the other section(s) still write theirs.
File name pattern (all paths relative to {work_folder}):
| Information Type | Output File |
|---|---|
| Program summary | {doc_name}_PGM_summary.txt |
| Domains | {doc_name}_domains.txt |
| Data elements | {doc_name}_dataElements.txt |
| Tables (DDIC) | {doc_name}_tables.txt |
| Initial table data (one per table) | table_data_{TABLE_NAME}.txt |
| Error messages | {doc_name}_errorMsgs.txt |
| Text elements | {doc_name}_textElements.txt |
| Process logic | {doc_name}_process.txt |
| Interface contract | {doc_name}_interface.txt |
| Selection definition | {doc_name}_selection_definition.txt |
| Selection screen layout (image, Step 3.5) | {doc_name}_selection_screen_layout.png |
| File mapping (inbound) | {doc_name}_file_mapping_in.txt |
| File mapping (outbound) | {doc_name}_file_mapping_out.txt |
| Supplement (free-form, Step 3.4) | {doc_name}_supplement.txt |
| Golden tests | {doc_name}_golden.txt |
| Dependencies | {doc_name}_deps.txt |
If an information type is not present in the source document, do not create the file (do not write empty placeholders).
Report to the user:
{work_folder}/sap-docs-convert {work_folder} (optional) to apply customer-specific
field/type/flag rules from spec_conversion_rules.tsv before validation/sap-docs-check {work_folder} to validate the spec (process logic + DDIC
definitions; runs both dimensions by default)/sap-gen-abap {work_folder}/{doc_name}_process.txt to generate ABAP codeEnd the log run. Use EXISTED if the work folder already contained the
output files (and you only verified them); use SUCCESS for a fresh
extraction; use FAILED with an ErrorClass if any step blocked progress
(e.g. INPUT_NOT_FOUND, RAW_DUMP_FAILED, EXTRACT_FAILED):
powershell -ExecutionPolicy Bypass -File "<SAP_DEV_CORE_SHARED_DIR>\scripts\sap_log_helper.ps1" -Action end -StateFile "{RUN_TEMP}\sap_docs_extract_run.json" -Status SUCCESS -ExitCode 0
What SKILL.md sets; muted values are Claude Code's defaults
12 skills in this plugin
/sap-docs-checkValidates an extracted design spec before ABAP code generation, across two
dimensions: `ddic` checks DDIC objects (domains / data elements / tables) —
naming, data-type validity, domain/DTEL/table cross-references, currency-ref
completeness, the primitive-as-data-element trap; `process` checks the
process-logic text for unclear/ambiguous steps, missing info, and logic /
type / cross-reference inconsistencies. Both optionally verify references
against the live system over RFC when a SAP logon is given. Runs BOTH by default
(whichever inputs exist); --dimension ddic|process forces one. Writes a
TAB-separated result file per dimension for Excel review. Replaces the former
/sap-docs-check-ddic and /sap-docs-check-process.
Input: work folder path; optional SAP Logon description enables the RFC checks.
/sap-docs-convertApplies customer-specific normalisation rules to the extracted spec files
in a work folder. Reads `spec_conversion_rules.tsv` (default at
sap-dev-core/shared/tables/, override at {custom_url}/spec_conversion_rules.tsv)
and rewrites the affected `_*.txt` files in place.
Three rule categories:
* field_rename — legacy field name → canonical name
* type_rename — legacy DDIC type token → canonical token
* flag_mapping — legacy flag value → one or more KEY=VALUE pairs
Plus optional schema migration (legacy customer YAML/TSV layout → Customer
Brief layout).
Input: work folder containing the extracted `_*.txt` files (output of /sap-docs-extract).
Output: same files rewritten in place; a `.pre-convert/` snapshot is taken first.
This skill is OPTIONAL — projects already authoring specs in Customer Brief
format can skip it entirely.
npx claudepluginhub sapdev-ai/sap-dev --plugin sap-gen-code