Patterns
CAP
ABAP

Code Library

Production-ready code patterns, templates, and snippets for SAP development. Covers ABAP Cloud (RAP), CAP CDS, OData V4 consumption, BTP service bindings, Joule skill SDK, and SAP Build formula patterns.

Overview

The Code Library is a curated collection of production-grade code patterns for the SAP development ecosystem. Unlike documentation, these patterns include annotations explaining the why behind each implementation choice — Clean Core compliance, error handling strategies, security considerations (XSUAA token propagation, principal propagation), and performance optimisations (CDS query push-down, HANA native functions).

Patterns are organised by technology layer. Each pattern links to a fully documented page with the complete code snippet, prerequisites, and deployment notes. All patterns are verified against the current releases: S/4HANA 2025 OP, CAP Node.js 8.x, BTP Q4 2025 services, and ABAP Cloud (S/4HANA ABAP Platform 2023).

ABAP Cloud — RAP Business Object with draft handling and CDS View Entity
CAP CDS — service definition, S/4HANA OData import, and custom handler
OData V4 — batch requests, deep insert, and $expand consumption from JavaScript
BTP SDK — SAP AI SDK Python/JS, XSUAA token fetch, Destination Service call
Joule Skill — intent handler, entity extraction, callAPI(), respond() card types
SAP Build Apps — OData V4 data variable, formula-based navigation, offline

Pattern Categories

ABAP Cloud / RAP
ABAP
  • RAP BO root entity — CDS View Entity + Behaviour Definition
  • ABAP Cloud class — FOR CLOUD DEVELOPMENT language version
  • Released BAdI implementation — filter condition, exception handling
  • CDS analytical query — @Analytics.query: true with aggregation
  • ABAP Unit Test — test class with CUT-based isolation
CAP Node.js
CAP
  • Service definition with OData V4 import and projection
  • Custom handler — before/on/after hooks with req.user
  • S/4HANA delegation — transparent remote service call
  • HANA native function call from CDS — $native expression
  • CAP Event Mesh — emit domain event and subscribe handler
OData V4 Consumption
OData
  • Fetch API call with CSRF token and SAP-Client header
  • Batch request ($batch) for multiple entity reads
  • Deep INSERT — header with items in one POST payload
  • $expand with $select for optimised payloads
  • OData V4 action invocation with bound action parameters
BTP Platform SDK
BTP SDK
  • XSUAA service binding — fetch JWT token for M2M calls
  • Destination Service API — resolve destination at runtime
  • SAP AI SDK — Gen AI Hub chat completion with streaming
  • SAP AI SDK — Gen AI Hub embedding for RAG pipeline
  • HANA Cloud client — node-hdb vs. @sap/hana-client
Joule Skills (Joule Studio)
Joule
  • Skill descriptor — intent, utterances, and slot definitions
  • Handler — callAPI() with principal propagation
  • respond() — card, list, confirmation, clarification types
  • Multi-turn conversation — context.session state management
  • Error handling — fallback message and escalation action
SAP Build Apps
Low-Code
  • Data variable — OData V4 collection with live refresh
  • Formula navigation — pageVars, appVars, route parameters
  • REST API integration — OAuth2 client credentials flow
  • Offline data sync — delta token and local storage binding
  • Custom component — reusable card with exposed properties
Detailed content for this section is being added in upcoming prompt modules. Use the navigation to explore fully documented sections.