$npx -y skills add likweitan/abap-skills --skill rapHelp with RAP (RESTful ABAP Programming Model) development including behavior definitions, EML statements, managed and unmanaged BOs, draft handling, actions, validations, determinations, side effects, and business events. Use when users ask about RAP, BDEF, BDL, EML, behavior de
| 1 | # RAP (RESTful ABAP Programming Model) |
| 2 | |
| 3 | Guide for building transactional applications using the ABAP RESTful Application Programming Model (RAP) in ABAP Cloud. |
| 4 | |
| 5 | ## Workflow |
| 6 | |
| 7 | 1. **Determine the user's goal**: |
| 8 | - Creating a new RAP BO from scratch |
| 9 | - Adding behavior (actions, validations, determinations) to an existing BO |
| 10 | - Writing EML statements to consume a RAP BO |
| 11 | - Troubleshooting RAP-related issues |
| 12 | - Understanding RAP concepts |
| 13 | |
| 14 | 2. **Identify the scenario**: |
| 15 | - Managed (greenfield) vs. unmanaged (brownfield) |
| 16 | - Draft-enabled or not |
| 17 | - Numbering concept: early/late, internal/external/managed |
| 18 | - Single entity or composition tree (root + children) |
| 19 | |
| 20 | 3. **Guide implementation** following the RAP layered architecture: |
| 21 | - Data modeling (database tables → CDS view entities) |
| 22 | - Behavior definition (BDEF using BDL) |
| 23 | - Behavior implementation (ABAP behavior pool) |
| 24 | - Business service exposure (service definition → service binding) |
| 25 | |
| 26 | 4. **Provide code examples** using correct BDL and EML syntax |
| 27 | |
| 28 | ## RAP Architecture Layers |
| 29 | |
| 30 | | Layer | Artifacts | Purpose | |
| 31 | | --------------------------- | --------------------------------------------- | ----------------------------------------------------------------------- | |
| 32 | | **Data Modeling** | Database tables, CDS root/child view entities | Data persistence and semantic data model | |
| 33 | | **Behavior Definition** | BDEF (`.bdef`) | Declares transactional behavior (operations, characteristics) using BDL | |
| 34 | | **Behavior Implementation** | ABAP behavior pool (`BP_*`) | Implements business logic in handler/saver classes | |
| 35 | | **Projection** | CDS projection views, projection BDEF | Adapts BO for specific service consumers | |
| 36 | | **Business Service** | Service definition, service binding | Exposes BO as OData service | |
| 37 | |
| 38 | ## Implementation Types |
| 39 | |
| 40 | ### Managed (Greenfield) |
| 41 | |
| 42 | - Framework handles transactional buffer and standard CRUD operations automatically |
| 43 | - Only need custom code for non-standard operations (actions, validations, determinations) |
| 44 | - Automatic save handling (can be enhanced with `additional save` or replaced with `unmanaged save`) |
| 45 | |
| 46 | ``` |
| 47 | managed implementation in class zbp_r_entity unique; |
| 48 | strict ( 2 ); |
| 49 | ``` |
| 50 | |
| 51 | ### Unmanaged (Brownfield) |
| 52 | |
| 53 | - Developer provides transactional buffer and implements all operations |
| 54 | - Used when existing business logic needs to be embedded in RAP |
| 55 | |
| 56 | ``` |
| 57 | unmanaged implementation in class zbp_r_entity unique; |
| 58 | strict ( 2 ); |
| 59 | ``` |
| 60 | |
| 61 | ## Behavior Definition (BDL) Quick Reference |
| 62 | |
| 63 | ### Complete BDEF Structure |
| 64 | |
| 65 | ``` |
| 66 | managed implementation in class zbp_r_root unique; |
| 67 | strict ( 2 ); |
| 68 | with draft; |
| 69 | |
| 70 | define behavior for ZR_Root alias Root |
| 71 | persistent table zroot_tab |
| 72 | draft table zroot_d |
| 73 | etag master LocalLastChangedAt |
| 74 | lock master |
| 75 | total etag LastChangedAt |
| 76 | authorization master ( global ) |
| 77 | late numbering |
| 78 | { |
| 79 | // Field characteristics |
| 80 | field ( readonly ) RootUUID, CreatedBy, CreatedAt, LastChangedBy, LastChangedAt; |
| 81 | field ( mandatory ) Description; |
| 82 | field ( numbering : managed ) RootUUID; |
| 83 | |
| 84 | // Standard operations |
| 85 | create; |
| 86 | update; |
| 87 | delete; |
| 88 | |
| 89 | // Association to child entity |
| 90 | association _Child { create; } |
| 91 | |
| 92 | // Actions |
| 93 | action doSomething result [1] $self; |
| 94 | static action createFromTemplate parameter ZD_CreateParam result [1] $self; |
| 95 | internal action recalculate; |
| 96 | |
| 97 | // Validations |
| 98 | validation validateDescription on save { create; field Description; } |
| 99 | |
| 100 | // Determinations |
| 101 | determination setDefaults on modify { create; } |
| 102 | determination calcTotal on modify { field Quantity, Price; } |
| 103 | |
| 104 | // Draft actions |
| 105 | draft action Resume; |
| 106 | draft action Edit; |
| 107 | draft action Activate optimized; |
| 108 | draft action Discard; |
| 109 | draft determine action Prepare |
| 110 | { |
| 111 | validation validateDescription; |
| 112 | } |
| 113 | |
| 114 | // Side effects |
| 115 | side effects |
| 116 | { |
| 117 | field Quantity affects field TotalAmount; |
| 118 | field Price affects field TotalAmount; |
| 119 | determine action Prepare executed on field Description affects message |