Core Data Services (CDS) ABAP

CDS and OData

Basics

What is OData?

  • OData stands for Open Data Protocol and was originally designed by Microsoft
  • OData contains “SQL-like” statements such as filters

What is it used for?

  • OData is one of SAP's standard protocols for modern data exchange
  • OData is the foundation of ALL Fiori applications!

CDS and OData – but how?

SEGW and RDS

  • The “classic” approach from ancient times (since ABAP 7.00)
  • Since ABAP 7.50 with SADL and RDS
    • SADL: Service Adaptation Description Language
    • RDS: Referenced Data Source
  • BUT: offers the most flexibility, because redefinition is possible

Via Annotation

@OData.publish: true

  • “New” since ABAP 7.50
  • An OData service is created directly from a CDS view

Service Definition and Service Binding

  • Since S/4HHANA 1809
  • Foundation for RAP

Publishing Service Bindings

Local publication cannot be transported!
Only for testing purposes or the local preview of the app.

OData V2

Transaction /IWFND/MAINT_SERVICE

OData V4

Transaction /IWBEP/V4_ADMIN

Metadata of a Service

Append $metadata to the service URL:
<host>/sap/opu/odata4/sap/z_99_service/srvd/sap/z_00_service/0001/$metadata

Calling an Entity Set

<host>/sap/opu/odata4/sap/z_99_service/srvd/sap/z_00_service/0001/<EntitySetName>

The Entity Set Name is the name defined in the Service Definition file.
You also find it in the metadata under EntitySet Name:

Data Format

$format=json

Possible formats:

  • xml – Only V2
  • json – V2 & V4
  • xlsx – Excel download, directly from V2!

Debug Tools

?$format=json&sap-ds-debug=true

https://s4d.sap.kli-int.com/sap/opu/odata/sap/ZDKUI_I_TASKS/Tasks?$format=json&sap-ds-debug=true

Additional Parameters

  • &$top=5 => retrieve only 5 records
  • &$skip=10 => skip the first 10 (useful for paging!)
  • &$orderby=Priority desc => order by priority descending
  • Resolve associations using expand:
    /sap/opu/odata/sap/Z_99_SERVICE_V2/Users?$expand=to_TasksToDo