A Custom Entity in RAP is like a virtual data model — it does not persist data in a DB table, but fetches it from logic (e.g., CDS views, APIs, function modules, or custom code).
It is exposed via a behavior definition and then published as an OData/Web API service.
1. Create a Custom Entity in CDS
@EndUserText.label: ‘Custom Employee API Entity’
define custom entity ZC_EMPLOYEE_API {
key empid : abap.char(10);
empname : abap.char(40);
department: abap.char(20);
}
2. Define a Behavior Implementation (Handler Class)
CLASS zcl_employee_handler DEFINITION
PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_rap_query_provider.
ENDCLASS.
CLASS zcl_employee_handler IMPLEMENTATION.
METHOD if_rap_query_provider~select.
DATA lt_data TYPE TABLE OF zc_employee_api.
“Fetch data (from table, FM, RFC, etc.)
SELECT empid, empname, dept AS department
FROM zemployees
INTO TABLE @lt_data.
“Return data
result = CORRESPONDING #( lt_data ).
ENDMETHOD.
ENDCLASS.
3. Register Service in Service Definition
@EndUserText.label: ‘Employee API Service’
define service ZUI_EMPLOYEE_API {
expose ZC_EMPLOYEE_API;
}
4. Publish via Service Binding
- Create a Service Binding (
ZUI_EMPLOYEE_API_BIND
). - Choose OData V4 as binding type.
- Activate it → SAP generates a URL endpoint.
/sap/opu/odata4/sap/zui_employee_api/srvd_a2x/sap/zui_employee_api/0001/
5. Test the API
-
Use
/IWFND/MAINT_SERVICE
(for OData V2 in SEGW) or Fiori Preview (for OData V4). -
Run the URL in browser or Postman:
GET …/ZC_EMPLOYEE_API
Summary
-
Custom Entity = Virtual CDS entity (no table).
-
Implement a handler class to supply data.
-
Expose it in a service definition.
-
Bind it with service binding (OData V2/V4).
-
Test via Fiori preview or Postman.