Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Naveen_n
Explorer
3,090

Why Use CDS and OData for Lookups? 

  • CDS Views: Provide a high-level abstraction for modeling data and implementing business logic in a standardized way. 
  • OData Services: Offer a protocol for querying and updating data through REST-based APIs. Exposing CDS views as OData services allows consumption in SAP Fiori, mobile apps, or external systems. 

The combination of CDS and OData provides flexibility, scalability, and easy integration, which is critical for modern web-based lookup services. 

Step 1: Create database table and Define the CDS View for Product Lookup 

The first step is to Create database table and define a CDS view that will serve as the basis for our lookup service. The CDS view will fetch relevant fields from the product master data and allow filtering using input parameters. 

Naveen_n_0-1727680172308.png

Naveen_n_1-1727680172314.png

Naveen_n_2-1727680172317.png

Naveen_n_3-1727680172320.png

Step 2: Activate and Expose the OData Service 

Once the CDS view is created, the next step is to activate the OData service. 

Steps to Activate the OData Service: 

  1. Go to SAP Gateway Service Builder (transaction code SEGW). 
  1. Activate the service by navigating to System AliasActivate and Maintain Services. 
  1. Find the newly created OData service corresponding to your CDS view (e.g., ZNA_LOOKUP_SERVICE). 
  1. Activate the service and ensure it’s available for consumption. 

Once activated, you can now consume this OData service in any client   to perform product lookups.

Naveen_n_4-1727680172322.png

 

@AbapCatalog.sqlViewName: 'ZNA_VALUE'
@AbapCatalog.compiler.compareFilter: true 
@AbapCatalog.preserveKey: true 
@AccessControl.authorizationCheck: #NOT_REQUIRED 
@EndUserText.label: 'lookup service for Product table' 
@Metadata.ignorePropagatedAnnotations: true 
define view zna_value_help as select from zna_t_product 
{ 
@Consumption.valueHelpDefinition: [{ entity: {element: 'Id',name: 'ZNA_T_PRODUCT' } }] 
key id as Id, 
@Consumption.valueHelpDefinition: [{ entity: {element: 'Name',name: 'ZNA_T_PRODUCT' } }] 
name as Name, 
@Consumption.valueHelpDefinition: [{ entity: {element: 'Category',name: 'ZNA_T_PRODUCT' } }] 
category as Category, 
@Consumption.valueHelpDefinition: [{ entity: {element: 'Price',name: 'ZNA_T_PRODUCT' } }] 
price as Price 
} 

 

Naveen_n_5-1727680172323.png

Here in  Data model, Choose Reference--> Data Source and Provide CDS Entity name. 

Naveen_n_6-1727680172324.png

Naveen_n_7-1727680172326.png

Here we can Observe that CDS Entity is Added here. 

Naveen_n_8-1727680172328.png

Here Just we have to Select Entity set and Perform Get Operation then Click On Execute. 

Naveen_n_9-1727680172330.png

Here we can See the Data. 

Naveen_n_10-1727680172334.png

Conclusion 

In this blog post, we’ve walked through how to create a lookup service for product details using CDS and OData. This service allows applications to dynamically query product information based on user input, making it highly flexible and interactive. 

By combining CDS views with OData, you can easily expose SAP data for external consumption while benefiting from the performance and flexibility of SAP HANA. Whether you’re building an SAP application or integrating with external systems, this approach ensures a smooth and efficient lookup experience. 

 

Labels in this area