ERPClimb logoERPClimb

Code examples · ABAP RAP · Intermediate

Call your RAP business object from ABAP with EML (create, read, approve, commit)

The problem

A batch job must import leave requests from a legacy file.

How we solve it

  1. 1MODIFY ENTITIEScreate
  2. 2READ ENTITIEScheck result
  3. 3MODIFY ENTITIESapprove action
  4. 4COMMIT ENTITIESsave

The result

A runnable ABAP console class that creates requests through the business object, inspects the FAILED and REPORTED tables, approves, and commits in one controlled save.

Overview drawn by ERPClimb from this example. The steps are the same as in the code below.

1. The requirement

A batch job must import leave requests from a legacy file. It must not bypass the rules: the same date validation and initial status must apply as in the Fiori app. The job must also approve the first imported request in the same run.

2. How we design it

Treat the business object as the only door to the data. The job builds the requests in memory with MODIFY ENTITIES, looks at the response tables, and saves once with COMMIT ENTITIES. Because the save goes through the business object, every determination and validation runs exactly as it does for the Fiori app.

Why we decided it this way

  1. 1EML instead of INSERT into the tableA direct INSERT skips determinations, validations and ETag handling. EML keeps one set of rules for UI, API and batch.
  2. 2One commit at the endAll requests are saved together or not at all, which is what an import job needs.
  3. 3Check FAILED and REPORTED after every stepThey tell you which instance broke which rule. Reading only after the commit hides the cause.

Before you start

  • The Leave Request business object from the 'Build a managed RAP business object' example, activated in your system.
  • An ABAP class that implements IF_OO_ADT_CLASSRUN so you can run it with F9 in ADT.

3. The code, step by step

Step 1 of 4: Create requests through the business object

Create two requests. EML triggers the BO's determinations and validations just like the UI does.

ABAP · Class · ZCL_LEAVE_EML_DEMO
" Console class skeleton
CLASS zcl_leave_eml_demo DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.
ENDCLASS.

CLASS zcl_leave_eml_demo IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    " MODIFY ENTITIES ... CREATE
    MODIFY ENTITIES OF zi_leaverequest
      ENTITY LeaveRequest
        CREATE FIELDS ( EmployeeId StartDate EndDate )
        WITH VALUE #(
          ( %cid = 'L1' EmployeeId = '00000042' StartDate = '20270105' EndDate = '20270109' )
          ( %cid = 'L2' EmployeeId = '00000042' StartDate = '20270210' EndDate = '20270201' ) )
      MAPPED   DATA(mapped)
      FAILED   DATA(failed)
      REPORTED DATA(reported).
    " Three response tables
    out->write( |Created in buffer: { lines( mapped-leaverequest ) }| ).
    out->write( |Failed so far:     { lines( failed-leaverequest ) }| ).
Part by part (plain text)
  1. Console class skeleton. IF_OO_ADT_CLASSRUN lets you run the class from ADT and print with the 'out' parameter, with no report or screen needed.
  2. MODIFY ENTITIES ... CREATE. %cid is a temporary key you invent to refer to each new instance before it has its real UUID. The second request has an end date before its start date, so the validation will reject it when we commit.
  3. Three response tables. MAPPED maps your %cid to the generated key. FAILED lists instances that could not be processed. REPORTED holds messages. At this point nothing is saved: EML only changes a transactional buffer until you commit.

Open in the portal

The SAP objects named in this code are linked in the code above and listed here. Each opens its page in the SAP Library.

4. The final outcome

A runnable ABAP console class that creates requests through the business object, inspects the FAILED and REPORTED tables, approves, and commits in one controlled save.

What you should see

First run: both requests appear in the buffer with status N, then 'Rejected, 1 instance(s) failed validation' because request L2 has its end date before its start date. After correcting L2's end date: 'Saved.' and both rows exist, with L1 approved.

Try it and check the result

  • Run with F9 in ADT. Expected output: both requests appear in the buffer with status N, then 'Rejected, 1 instance(s) failed validation' (instance L2).
  • Change L2's EndDate to '20270212' and run again: the output becomes 'Saved.' and both rows exist with L1 approved.
  • Check the table ZLEAVE_REQ in the Data Preview (F8 on the CDS view ZI_LeaveRequest) to confirm what was written.

Common mistakes

  • Never write into ZLEAVE_REQ with a direct INSERT. That bypasses determinations, validations and ETag handling.
  • In ABAP Cloud, prefer COMMIT ENTITIES to save a RAP transaction: it returns FAILED and REPORTED instead of ending in a runtime error.
  • Do not read FAILED/REPORTED only after COMMIT. Check both after each MODIFY and again after COMMIT: they can differ.

Keep learning

Checking status: Reviewed line by line against SAP documentation. Not executed on a live system. Reviewed 2026-11-25. Release: ABAP Cloud / RAP managed. Requires the Leave Request business object from the managed RAP example.

Original ERPClimb teaching code with illustrative names. Not taken from a customer system. Syntax can differ by release; check the references below and activate in a sandbox first. ERPClimb is independent of SAP SE.