Talking to RAP objects in code
Your Fiori UI talks to RAP objects through OData. But ABAP code — actions, determinations, validations, background jobs — needs its own way in. That's EML: Entity Manipulation Language.
EML is the typed, object-oriented API for reading and changing RAP business objects from ABAP. If you know what you want to do, EML is almost always the right tool — not direct SQL on the tables.
Golden rule: never bypass the BO. Writing directly to the persistent table skips validations, determinations, locking, and draft handling. EML goes through all of them.
READ ENTITIES: fetching data
READ ENTITIES OF zi_salesorder_tp IN LOCAL MODE
ENTITY SalesOrder
FIELDS ( OrderID NetAmount Status )
WITH VALUE #( ( %tky-OrderID = '1001' ) )
RESULT DATA(orders)
FAILED DATA(failed).
IN LOCAL MODE means: run inside the current behavior context (skip authorization checks meant for external callers). Reading from inside your own behavior implementation — determinations, validations, actions — this is the mode you want.
Request only the fields you need. EML reads are typed against the CDS entity, so typos fail at compile time instead of runtime.
MODIFY ENTITIES: changing data
MODIFY ENTITIES OF zi_salesorder_tp IN LOCAL MODE
ENTITY SalesOrder
UPDATE FIELDS ( Status )
WITH VALUE #( ( %tky-OrderID = '1001'
Status = 'APPROVED' ) )
FAILED DATA(mod_failed)
MAPPED DATA(mapped)
REPORTED DATA(mod_reported).
The three response parameters matter: FAILED tells you which instances didn't make it, MAPPED returns the key mapping (essential when creating — the framework assigns keys you need back), and REPORTED carries messages.
For creates, use CREATE FIELDS with %cid (content IDs) to reference not-yet-persisted instances — then read them back from MAPPED.
COMMIT ENTITIES: making it stick
EML changes live in the transactional buffer until you commit:
COMMIT ENTITIES
RESPONSE OF zi_salesorder_tp
FAILED DATA(commit_failed)
REPORTED DATA(commit_reported).
Inside a managed RAP runtime (UI, actions), the framework commits for you — never commit there. In standalone contexts (a background report driving EML), the commit is your responsibility. Forgetting it is the classic "my changes disappeared" bug.
EML habits that prevent pain
- Always handle FAILED. EML doesn't raise exceptions for business failures — if you ignore
FAILED, you're ignoring errors. - Use %tky for addressing. The technical key struct is the canonical instance reference; don't invent your own key handling.
- Prefer EML over SQL in BO logic. Determinations, validations, and actions should speak EML — it keeps behavior consistent no matter who triggers it.
- Batch your operations. One
MODIFY ENTITIESwith a table of instances beats a loop of single calls, every time.
EML is verbose on purpose. Every keyword —
IN LOCAL MODE,FIELDS,FAILED— is a decision made explicit. Verbose code that can't misunderstand you beats clever code that can.
What's the trickiest EML pattern you've wrestled with — deep creates, %cid mapping, draft EML? Share it in the comments.