Sap data workbook

From marcellourbani/vscode_abap_remote_fs · View interactive version

Sap data workbook is an AI agent skill from the GitHub repository marcellourbani/vscode_abap_remote_fs. Create SAP Data Workbooks (.sapwb) for SAP data analysis. Use when the user asks to analyze SAP data, create data quality checks, build reports, compare tables or systems, profile data, or any multi-step SAP data exploration. Workbooks have ABAP SQL cells (queries against SAP) and JavaScript cells (

How to use this skill

Skill file

SAP Data Workbook — SAP Data Analysis Made Reproducible

You create .sapwb files — VS Code notebooks with ABAP SQL and JavaScript cells that query SAP and process results. The user opens the file and clicks "Run All."

When To Create a Workbook

Create a workbook when the user wants to:

How to Create the File

You (GitHub Copilot in VS Code) create and edit workbooks with your notebook tools. Follow these rules exactly:

  1. Create the whole workbook in ONE create_file call, inside the workspace. Write the cells in your own notebook cell format, NOT the on-disk JSON shown under File Format (on-disk JSON written this way ends up as empty or Python cells):

```xml

<VSCode.Cell language="markdown">

# Title

What the workbook does.

</VSCode.Cell>

<VSCode.Cell language="abap-sql">

SELECT mandt, mtext FROM t000

</VSCode.Cell>

<VSCode.Cell language="javascript">

return cells[1].result.length

</VSCode.Cell>

```

The JSON form with cell_type, metadata.language and source also works. Languages are exactly abap-sql (NOT sql), javascript and markdown.

  1. Read the workbook back with your notebook read tool and check that every cell is there, with its content and the right language. A file that is valid but has empty cells, missing cells or Python cells is a failure: fix it before you tell the user it is done.
  1. Set systems, row limits and names with abapfs_workbook_cell_settings (see below), in one call, after all cells exist.
  1. One edit at a time. Wait for each notebook edit to finish before you start the next; never run edits in parallel (for example inserting a query while changing another cell fails). Read the workbook back after a series of edits.
  1. Never rewrite an existing workbook (no create_file over it, no replacing all cells, no converting it with a generic notebook writer). Notebook tools cannot carry a cell's name, system or maxRows, so a rewrite silently deletes them. Change only the cells that need changing, one at a time.

Cell Names, Systems and Row Limits

These are stored with each cell. Your notebook tools can neither see nor set them; the abapfs_workbook_cell_settings tool does both.

Read the current settings: pass only filePath. You get one line per cell: index, language, name, own or inherited system (and whether it is connected), row limit and first line. Do this before changing an existing workbook, and whenever you are unsure which index a cell has.

Change settings: pass filePath and cells, one entry per cell, with index (0-based, counting markdown cells: the N of cells[N]) and at least one of:

| Field | Effect |

|---|---|

| system | System marker: this ABAP SQL cell and every following SQL cell run on that connection id, until the next marker. SQL cells only. |

| clearSystem: true | Remove the marker; the cell inherits the marker above. |

| maxRows | Row limit of this ABAP SQL cell, 1 to 100000. Leave it out unless the user needs more than 1000 rows. |

| name | Cell name (letters, digits, _, unique); other cells can then use cells.<name>. |

| clearName: true | Remove the name. |

{
  "filePath": "C:/work/workbooks/clients.sapwb",
  "cells": [
    { "index": 1, "system": "SYS1" },
    { "index": 2, "system": "SYS2" },
    { "index": 3, "system": "SYS3", "maxRows": 5000 }
  ]
}

Rules:

File Format

For reference (reading a .sapwb file, or tools that write plain files and have no notebook tools), .sapwb files are JSON on disk:

{
  "version": 1,
  "title": "Descriptive Title",
  "cells": [
    { "type": "markdown", "content": "# Title\nExplanation" },
    { "type": "abap-sql", "content": "SELECT matnr, mtart FROM mara WHERE mtart = 'FERT'", "name": "materials" },
    { "type": "javascript", "content": "// first finished material\nconst rows = cells.materials.result;\nconst out = rows.map(r => ({ MATNR: r.MATNR, MTART: r.MTART }));\nout.FIRST = rows.length ? rows[0].MATNR : '';\nreturn out;", "name": "fert" },
    { "type": "abap-sql", "content": "SELECT matnr, werks FROM marc WHERE matnr = ${cells.fert.result.FIRST}", "name": "plants" }
  ]
}

Cell properties: type, content, and optionally maxRows, name and system (ABAP SQL cells only). If you are GitHub Copilot in VS Code, do not write this format: use the cell format under How to Create the File.

Critical Rules

  1. Get ABAP SQL syntax. Call abapfs_get_sql_syntax before writing SQL cells. ABAP SQL differs from standard SQL (tilde for table~field, no semicolons, etc.).
  1. Cell types are exactly: "abap-sql", "javascript", or "markdown". No other values.
  1. SQL cells execute ABAP SQL via ADT. Only SELECT and WITH are allowed. No DML. No semicolons. No comments containing ${...}.
  1. Cell references: cells[N] is 0-based and counts markdown cells. A named cell ("name" in the file, #n · name in the status bar) can also be referenced as cells.<name> and keeps working when cells move. Names are letters, digits and _, start with a letter or _, and are unique.
  1. JavaScript cells run in an isolated worker thread. They read earlier results via cells[N].result (or cells.<name>.result for named cells):
  1. Formatted output. A JS cell can return:

Returning a plain array of objects still renders as a table. A plain object renders as JSON text, a string as text. Keep the status word (RED/YELLOW/GREEN) in its own column, one finding per row, and do not truncate values: tables wrap.

  1. SQL interpolation: SQL cells reference previous results with ${cells[N].result.path} (or ${cells.<name>.result.path}). This resolves before execution.
  1. SAP 255-character SQL literal limit. SAP ADT rejects any SQL where a single literal exceeds 255 characters. This means interpolating large arrays into IN (...) clauses WILL FAIL. Never interpolate arrays that could have more than ~10 values into SQL. Use a sub-query or filter in a JavaScript cell instead.
  1. Row limit per SQL cell: 1000 by default; set maxRows with abapfs_workbook_cell_settings (see above). The table shows the first 200 rows (display.table limit up to 5000); later cells and exports receive all rows.
  1. Several SAP systems: a system marker on an ABAP SQL cell applies to it and every following SQL cell, until the next marker. JavaScript and markdown cells have no system.
  1. Start every workbook with a markdown cell explaining what it does and, if relevant, which cell runs on which system.
  1. File path: Write to the user's workspace root or a workbooks/ subfolder.
  1. Tell the user about the toolbar: Export… (data / code / comments to PDF, HTML, JSON, XML, Excel, CSV, Word or Markdown), collapse/expand all code or outputs, and the run plan.

Cell Referencing Examples

// Access SQL results (array of row objects)
const allRows = cells[1].result;                     // full array
const value = cells[1].result[0].MATNR;              // specific field
const ranOn = cells[1].system;                       // SAP system the query ran on

// Access JS cell results
const count = cells[2].result;                       // whatever that cell returned

// Use in SQL interpolation (quotes added automatically for strings — do NOT wrap in quotes)
// "SELECT ... WHERE matnr = ${cells[2].result.FIRST}"
// "SELECT ... WHERE lifnr IN (${cells[2].result.IDS})"  -- arrays auto-join with commas

Example: One Query on Three Systems

"Get the clients from T000 in SYS1, SYS2 and SYS3, add them up and show them in one table."

<VSCode.Cell language="markdown">
# Clients (T000) in SYS1, SYS2 and SYS3
Cells #1, #2 and #3 run the same query on SYS1, SYS2 and SYS3.
</VSCode.Cell>
<VSCode.Cell language="abap-sql">
SELECT mandt, mtext FROM t000
</VSCode.Cell>
<VSCode.Cell language="abap-sql">
SELECT mandt, mtext FROM t000
</VSCode.Cell>
<VSCode.Cell language="abap-sql">
SELECT mandt, mtext FROM t000
</VSCode.Cell>
<VSCode.Cell language="javascript">
// one table with every client, plus the totals
const parts = [cells[1], cells[2], cells[3]];
const rows = parts.flatMap(c => c.result.map(r => ({ System: c.system, Client: r.MANDT, Name: r.MTEXT })));
const systems = new Set(parts.map(c => c.system));
const counts = parts.map(c => c.system + ': ' + c.result.length).join(', ');
const note = systems.size === 3 ? '' : '\n\n**YELLOW:** the queries ran on ' + systems.size + ' system(s) only. Check the systems of cells #1, #2 and #3.';
return display.all(
  display.markdown('## ' + rows.length + ' clients (' + counts + ')' + note),
  display.table(rows, { wrap: true, title: 'Clients per system' })
);
</VSCode.Cell>

Then read the workbook back, and set the systems in one call:

{ "filePath": "<path of the workbook>", "cells": [ { "index": 1, "system": "SYS1" }, { "index": 2, "system": "SYS2" }, { "index": 3, "system": "SYS3" } ] }

Tell the user the workbook is ready for Run All, and pass on any warning (e.g. a system that is not connected).

Example: Data Quality Workbook

<VSCode.Cell language="markdown">
# Material Master Data Quality
Checks for materials missing a unit of measure or material group.
</VSCode.Cell>
<VSCode.Cell language="abap-sql">
SELECT matnr, mtart, matkl, meins FROM mara WHERE ersda > '20250101'
</VSCode.Cell>
<VSCode.Cell language="javascript">
// one row per check, status in its own column
const m = cells[1].result;
const noUoM = m.filter(r => !r.MEINS || !r.MEINS.trim()).length;
const noGroup = m.filter(r => !r.MATKL || !r.MATKL.trim()).length;
const rows = [
  { Status: m.length ? 'GREEN' : 'YELLOW', Check: 'Materials read', Count: m.length },
  { Status: noUoM ? 'RED' : 'GREEN', Check: 'Missing unit of measure', Count: noUoM },
  { Status: noGroup ? 'YELLOW' : 'GREEN', Check: 'Missing material group', Count: noGroup }
];
const worst = rows.some(r => r.Status === 'RED') ? 'RED' : rows.some(r => r.Status === 'YELLOW') ? 'YELLOW' : 'GREEN';
return display.all(
  display.markdown('## ' + worst + ' — material master quality'),
  display.table(rows, { wrap: true, highlight: true })
);
</VSCode.Cell>
<VSCode.Cell language="markdown">
## Next steps
Use **Export…** in the toolbar to send the results as Excel or PDF.
</VSCode.Cell>

If the user needs more than 1000 materials, set maxRows on cell #1 with abapfs_workbook_cell_settings.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.