abap-code-patterns
Skill1 starsChanged 4 months agoMITView on GitHub
ABAP development patterns and best practices — BAPI/RFC, dynamic programming, Clean ABAP, DDIC design, exception handling, BAL logging, ABAP OO. Use when writing, reviewing, or refactoring ABAP code; implementing ZROUTER handlers.
In this repository413 other files it gives its agents.
- .agents/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- .codex/AGENTS.mdAGENTS.md
- .cursor/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- sap-router-skillCopilot instructions
- .cursor/rules/sap-router.mdcCursor rule
- abap-cloud-migrationSkill
- abap-cloudSkill
- abap-code-reviewSkill
- abap-docs-referenceSkill
- abapgitSkill
- abapSkill
- abap-snippetSkill
- abap-sql-amdpSkill
- abap-system-infoSkill
- abap-unit-testingSkill
- arc-1-skillsSkill
- atc-cloudificationSkill
- authorization-iamSkill
- automation-pilot-catalog-explorerSkill
- automation-pilot-command-generationSkill
- automation-pilot-command-reviewSkill
- automation-pilot-content-management-via-apiSkill
- automation-pilot-debuggerSkill
- automation-pilot-executions-apiSkill
- automation-pilot-executor-executescriptSkill
- automation-pilot-executor-httprequestSkill
- automation-pilot-mcp-server-generationSkill
- automation-pilot-scheduled-executions-apiSkill
- badi-enhancementSkill
- btp-abap-environmentSkill
- btp-best-practicesSkill
- btp-build-work-zoneSkill
- btp-business-application-studioSkill
- btp-ciasSkill
- btp-cloud-foundrySkill
- btp-cloud-identitySkill
- btp-cloud-loggingSkill
- btp-cloud-platformSkill
- btp-cloud-transport-managementSkill
- btp-connectivitySkill
- btp-developer-guideSkill
- btp-diagram-generatorSkill
- btp-integration-suiteSkill
- btp-job-schedulingSkill
- btp-master-data-integrationSkill
- btp-service-managerSkill
- cap-add-remote-serviceSkill
- cap-developerSkill
- cap-triviaSkill
- capture-answerSkill
- cap-upgradeSkill
- cds-view-entitiesSkill
- claude-abap-skillsSkill
- claude-memSkill
- clean-abapSkill
- context-modeSkill
- cpi-iflow-developmentSkill
- engine-cap-developmentSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
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
- Very specific: line 78
No COMMIT WORK: Use BAPI_TRANSACTION_COMMIT with wait = 'X'
- Very specific: line 80
JSON: Use /UI2/CL_JSON — never manual PCRE parsing
- Very specific: line 112
Use CHAR1 for flags (X = true), NUMC4 for version, TIMESTAMPL for UTC
≈ “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.
Files
ABAP Code Patterns
Reference for ABAP development in ZROUTER_DISPATCH and related SAP projects. Validated against Clean ABAP guidelines and abaplint rules.
Prerequisites
- SAP NetWeaver 7.40+ (inline declarations, VALUE, COND, FOR)
- abaplint configured (config in
package.jsonabaplintkey, or rootabaplint.json) - Access to SE80/ADT for object creation
1. BAPI/RFC Pattern
" BAPI call with proper commit/rollback
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING headdata = ls_header
IMPORTING return = ls_ret.
IF ls_ret-type = 'E' OR ls_ret-type = 'A'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
RAISE EXCEPTION TYPE cx_zrouter EXPORTING mv_text = ls_ret-message.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'.
ENDIF.2. GENERATE SUBROUTINE POOL (Dynamic Eval)
" Compile ABAP at runtime — lighter than INSERT REPORT + SUBMIT
DATA: lt_source TYPE TABLE OF string,
lv_pool TYPE string.
APPEND |PROGRAM.| TO lt_source.
APPEND |FORM eval CHANGING cv_result TYPE string.| TO lt_source.
APPEND LINES OF lt_lines TO lt_source.
APPEND |ENDFORM.| TO lt_source.
GENERATE SUBROUTINE POOL lt_source NAME lv_pool
MESSAGE DATA(lv_msg) LINE DATA(lv_line) WORD DATA(lv_word).
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_zrouter
EXPORTING mv_text = |Syntax error line { lv_line - 2 }: { lv_msg }|.
ENDIF.
PERFORM ('EVAL') IN PROGRAM (lv_pool) IF FOUND CHANGING cv_result.3. Clean ABAP Quick Rules
- Field lists:
SELECT matnr, maktx FROM mara— neverSELECT * - Inline declarations:
DATA(lv_matnr) = 'MAT001' - NEW operator:
mo_log = NEW zcl_logger( )— notCREATE OBJECT - VALUE:
lt_data = VALUE #( ( a = 1 ) ( a = 2 ) ) - COND/SWITCH:
lv_st = COND #( WHEN sy-subrc = 0 THEN 'OK' ELSE 'ERR' ) - Field symbols:
LOOP AT lt_tab ASSIGNING FIELD-SYMBOL(<ls>) - No COMMIT WORK: Use
BAPI_TRANSACTION_COMMITwithwait = 'X' - Exceptions: Inherit
CX_STATIC_CHECK, neverCX_ROOT - JSON: Use
/UI2/CL_JSON— never manual PCRE parsing - BAL logging:
BAL_LOG_CREATE→BAL_LOG_MSG_ADD→BAL_DB_SAVE
4. ABAP OO Pattern — Abstract Handler + Factory
CLASS zcl_handler_abstract DEFINITION PUBLIC ABSTRACT.
PUBLIC SECTION.
INTERFACES zif_handler.
PROTECTED SECTION.
METHODS handle_action ABSTRACT.
ENDCLASS.
CLASS zcl_handler_mm DEFINITION PUBLIC FINAL
INHERITING FROM zcl_handler_abstract.
PROTECTED SECTION.
METHODS handle_action REDEFINITION.
ENDCLASS.
" Factory dispatch
CASE to_upper( iv_module ).
WHEN 'MM'. ro_handler = NEW zcl_handler_mm( ).
WHEN 'SD'. ro_handler = NEW zcl_handler_sd( ).
ENDCASE.5. DDIC Table Design — Header + Item
- Header (
ZROUTER_TMPL_HD):MANDT(key),TEMPLATE_ID(key),MODULE,ACTION,VERSION,TITLE,CREATED_BY,CREATED_AT,ACTIVE_FLAG - Items (
ZROUTER_TMPL_CD):MANDT(key),TEMPLATE_ID(key),LINE_NUM(key),CODE_LINE - Use
CHAR1for flags (X= true),NUMC4for version,TIMESTAMPLfor UTC
6. INSERT REPORT + SUBMIT (Full Dynamic)
" Heavier — use only when you need WRITE output capture
INSERT REPORT lv_report FROM lt_source.
SUBMIT (lv_report) VIA SELECTION-SCREEN AND RETURN.
" Capture via LIST_FROM_MEMORY + LIST_TO_ASCIPitfalls
- GENERATE SUBROUTINE POOL line offset:
- Cause: Error line numbers start at FORM, not PROGRAM.
- Solution: Subtract 2 to map back to user expression line.
- BAPI_TRANSACTION_COMMIT without WAIT:
- Cause: Update task runs async; next BAPI may read stale data.
- Solution: Always pass
wait = 'X'.
- RFC_READ_TABLE 512-char truncation:
- Cause: Field values silently truncated beyond 512 chars.
- Solution: Use ADT SQL or HANA query for long text fields.
- sy-subrc after BAPI call:
- Cause: Some BAPIs return
sy-subrc = 0withBAPIRET2-TYPE = 'E'. - Solution: Always check
BAPIRET2-TYPE, notsy-subrc.
- Cause: Some BAPIs return
Verification
# Lint the ABAP source
npx abaplint templates/**/*.abap
# Verify BAPI commit pattern present
grep -rn "BAPI_TRANSACTION_COMMIT" src/ | grep -c "wait.*X"
# Verify no COMMIT WORK in source
grep -rn "COMMIT WORK" src/ && echo "FAIL: found COMMIT WORK" || echo "OK"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
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.

