0% found this document useful (0 votes)
696 views

Odata Service For CDS View Using Annotations

The document describes how to expose an ABAP CDS view as an OData service. It involves adding the @OData.publish: true annotation to the CDS view, activating the view, and then activating the generated OData service in the Gateway hub system. This creates artifacts like a technical service, Gateway model, and ABAP class that allow the CDS view data to be accessed via OData. An example CDS view with and without parameters is provided to demonstrate the process and structure of the exposed OData metadata.

Uploaded by

sekhar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
696 views

Odata Service For CDS View Using Annotations

The document describes how to expose an ABAP CDS view as an OData service. It involves adding the @OData.publish: true annotation to the CDS view, activating the view, and then activating the generated OData service in the Gateway hub system. This creates artifacts like a technical service, Gateway model, and ABAP class that allow the CDS view data to be accessed via OData. An example CDS view with and without parameters is provided to demonstrate the process and structure of the exposed OData metadata.

Uploaded by

sekhar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

ABAP CDS View OData Annotation

A new and easy way of creating OData services based on CDS views was introduced
using the annotation @OData.publish: true at view level.

Let's see how we can expose the ABAP CDS View as OData Service using an example and
below is the exposure process.

Example #1 – ABAP CDS View without Parameters

1. Create an ABAP CDS view using ABAP Development Tools. Copy and paste the below
code in DDL editor.

@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'OData service on ABAP CDS View'

define view ZODATA_DEMO as select from scarr

key carrid as AirlineCode,

carrname as AirlineName,

currcode as Currency,

url as AirlineURL

}
2. Add the annotation @OData.publish: true  above the DEFINE VIEW statement.

3. After adding the annotation to CDS View save and activate the view.

@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'OData service on ABAP CDS View'

@OData.publish: true

define view ZODATA_DEMO as select from scarr

key carrid as AirlineCode,

carrname as AirlineName,

currcode as Currency,

url as AirlineURL

}
CDS view should meet following rules for successful OData service generation.

 No syntax errors in DDL source code.


 At least one key element is defined in the SELECT list of the CDS view.
 The name of the CDS view should not exceed 26 characters in length.

4. After activating the CDS view, following Gateway artifacts will be generated by the
SADL framework in back-end server.

 Technical service name artifact – <cds_view_name>_CDS.


 Gateway Model artifact with name – <cds_view_name>_CDS.
 ABAP class with name – CL_<cds_view_name>.
You can find all these artifacts in the transaction code – “/IWBEP/REG_SERVICE”.

5. Launch the transaction code “/IWFND/MAINT_SERVICE” to activate the OData service


in hub system. Enter System Alias, Technical Service Name and click the Get
Services button. The service will be displayed for selection.
6. In the Add Service dialog box enter the package name. Technical service name and
Technical model name will already be suggested. Click on OK to continue.

7. A dialog box appears as shown below, click on OK to continue.

8. As a
Result OData service is activated successfully in the Gateway hub system. Launch the
transaction code “/IWFND/GW_CLIENT” to test the service.
Above is the metadata generated for the OData service created based on the ABAP CDS
view. Let's closely look at the metadata and identify the different artifacts as part of the
OData service.

 Entity Type – ZODATA_DEMOType


 Entity Set – ZODATA_DEMO

URL:
http://<server>:8001/sap/opu/odata/sap/ZODATA_DEMO_CDS/ZODATA_DEMO
Example #2 – ABAP CDS View with Parameters

1. Below is the code for ABAP CDS view with parameters

@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO_P'

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'OData service on ABAP CDS View'

@OData.publish: true

define view ZODATA_DEMO_PARAMS

with parameters p_carrid :S_CARR_ID

as select from scarr

key carrid as AirlineCode,

carrname as AirlineName,

currcode as Currency,

url as AirlineURL

where carrid = $parameters.p_carrid


NOTE: As of now there is no annotation/a way to make the input parameters OPTIONAL
in ABAP CDS Views. So you have to pass values for all input parameters in ABAP CDS
view while accessing the data from it.

2.  Repeat the steps explained above in the Example #1 to create the OData service for
this CDS view also.

3. On successfully OData service generation, execute the OData service and look at the
metadata generated and following are the 2 entity sets generated
ZODATA_DEMO_PARAMSSet – Entity set which has 2 key predicates, one is the input
parameter and the second one is the key of ABAP CDS View. You need to pass these 2
key predicates while accessing the data

ZODATA_DEMO_PARAMS – Entity set which has 1 key predicate, which is input


parameter. You need to pass this key predicate to access the data.

To access the data you can use both entity sets and lets look how we can form the URI
for both of them.

If you like to use entity set ZODATA_DEMO_PARAMSSet  following the URI to be used

/sap/opu/odata/sap/ZODATA_DEMO_PARAMS_CDS/
ZODATA_DEMO_PARAMSSet(p_carrid=’AA’,AirlineCode=’AA’)
If you like to use entity set ZODATA_DEMO_PARAMS  following the URI to be used  

/sap/opu/odata/sap/ZODATA_DEMO_PARAMS_CDS/
ZODATA_DEMO_PARAMS(p_carrid=’AA’)/Set

You might also like