Skip to content

abap/run: add support for simple macros/templates/variables#175

Merged
jfilak merged 1 commit into
masterfrom
abap_run_define
Jun 13, 2026
Merged

abap/run: add support for simple macros/templates/variables#175
jfilak merged 1 commit into
masterfrom
abap_run_define

Conversation

@jfilak

@jfilak jfilak commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Creating an ABAP snippet is cool for quick testing but we can use these ABAP snippets to overcome missing RFC connectivity and call much more versatile ABAP snippets doing some real stuff.

Lets start small without external dependencies and without complex features like custom functions similar Ansible filters - we can do that latter if needed.

This patch just introduces the possibility to put "{{NAME}}" into ABAP snippet and then specify --define NAME=foo in the command sapcli abap run.

Sure, similar feature can be achieved by piping via sed (but that's no go for Windows users). The needed ABAP snippet with the needed value can be generated by LLM but tokens are getting expensive. So when developing agents skills you can put your uber-cool ABAP snippet doing some fantastic job into assets/ and instruct the agent to call it with the needed --define instead of burning tokens on generation of the entire ABAP snippet based on some template.

Creating an ABAP snippet is cool for quick testing but we can use
these ABAP snippets to overcome missing RFC connectivity and call
much more versatile ABAP snippets doing some real stuff.

Lets start small without external dependencies and without complex
features like custom functions similar Ansible filters - we can do that
latter if needed.

This patch just introduces the possibility to put "{{NAME}}" into ABAP
snippet and then specify `--define NAME=foo` in the command `sapcli abap run`.

Sure, similar feature can be achieved by piping via sed (but that's no
go for Windows users). The needed ABAP snippet with the needed value
can be generated by LLM but tokens are getting expensive. So when
developing agents skills you can put your uber-cool ABAP snippet doing
some fantastic job into assets/ and instruct the agent to call it with
the needed --define instead of burning tokens on generation of the
entire ABAP snippet based on some template.
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 389760dc-949b-4187-995b-8c149d0680b5

📥 Commits

Reviewing files that changed from the base of the PR and between d49ef69 and e8733b2.

📒 Files selected for processing (5)
  • doc/commands/abap.md
  • sap/cli/abap.py
  • sap/platform/abap/run.py
  • test/unit/test_sap_cli_abap.py
  • test/unit/test_sap_platform_abap_run.py

📝 Walkthrough

Walkthrough

This PR adds ABAP source preprocessing to substitute template tokens in provided ABAP source code. The -D/--define NAME=VALUE CLI flag supplies token definitions; {{NAME}} tokens in the source are replaced with their values. Core validation rejects reserved Jinja-like delimiters ({%, {#), enforces plain token names, and reports undefined tokens.

Changes

ABAP Preprocessing Feature

Layer / File(s) Summary
Preprocessing implementation and contract
sap/platform/abap/run.py, test/unit/test_sap_platform_abap_run.py
Adds regex-based token extraction and a preprocess(user_code, definitions) function that validates reserved Jinja-like delimiters, substitutes {{TOKEN}} placeholders when content is a valid token name, accumulates undefined tokens, and raises SAPCliError for unsupported or missing tokens. Tests cover token replacement, whitespace handling, single-brace non-matching, empty values, undefined and unsupported syntax errors, multiline constraints, and reserved delimiter rejection.
CLI definition argument parsing
sap/cli/abap.py, test/unit/test_sap_cli_abap.py
Introduces _parse_definitions(define_args) to convert repeatable NAME=VALUE CLI arguments into a dictionary, validating token names and raising errors for malformed input such as missing =, empty names, whitespace, disallowed characters, or leading digits. Tests verify single/multiple definitions, values containing =, empty values, override behavior, and rejection of invalid formats.
CLI command integration with preprocessing
sap/cli/abap.py, test/unit/test_sap_cli_abap.py
Adds the repeatable -D/--define argument to the ABAP command group and integrates preprocessing into run() by parsing definitions and passing loaded source through preprocess() before execution. Integration tests verify token substitution in the full run command, multiple defines, values with =, and error cases (missing/undefined tokens, reserved delimiters, invalid formats) where SAPCliError is raised and execution is skipped.
Feature documentation
doc/commands/abap.md
Documents the -D/--define NAME=VALUE syntax, token replacement rules (case sensitivity, whitespace handling, literal insertion in comments/strings), error conditions, and provides an example substituting multiple variables when running ABAP from stdin.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for simple macros/templates/variables to ABAP run functionality, which aligns with the documented {{NAME}} token substitution feature.
Description check ✅ Passed The description clearly explains the purpose and motivation for the feature, relating directly to the changeset's implementation of template substitution via --define flags in ABAP snippets.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch abap_run_define

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jfilak jfilak merged commit 555226a into master Jun 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant