Business Example
You are a developer or solution architect in your company. You have been asked to import and map CDS views to read and query operations for two entity sets of an SAP Gateway service and also map the association between the two.
- Template:
- None
- Solution:
- GW100_S_CDS (SAP Gateway Project)
Note
This exercise requires an SAP Learning system. Login information is provided by your system setup guide.Note
Whenever the values or object names in this exercise include ##, replace ## with the number of your user.Prerequisites
The packages were created in exercise Define a Data Model Based on a Data Dictionary Structure .
Task 1: Create an SAP Gateway Project for Mapping a CDS View
Steps
In the SAP Gateway Service Builder of your S4H, create a new project named ZGW100_##_CDS in your ZGW100_##_BES package.
In the SAP Easy Access of your S4H, search for SAP Gateway Service Builder or start transaction SEGW.
In the SAP Gateway Service Builder, choose Create Project.
In the Create Project popup, enter the following values:
Field | Value |
---|
Project | ZGW100_##_CDS |
Description | <your choice> |
Package | ZGW100_##_BES |
Choose Continue.
Choose Save.
In the Prompt for transportable workbench request popup, in the Request field, select the transport request provided to you.
Choose Continue.
Task 2: Define the Entities Supplier and Article
Steps
Import the data dictionary structure GW100CSUPPLIER as entity Supplier, selecting all fields except MANDT. Set BUSINESSPARTNERUUID as key.
In the SAP Gateway Service Builder of your S4H, right-click the Data Model node and choose Import → DDIC Structure.
In the Import from DDIC Structure popup, in the Name field, enter Supplier.
In the ABAP Structure field, enter GW100CSUPPLIER.
Choose Next.
Select the GW100CSUPPLIER checkbox.
Deselect the MANDT checkbox.
Choose Next.
In the BUSINESSPARTNERUUID field, select the Is Key checkbox.
Choose Finish.
Choose Save.
Import the data dictionary structure GW100CARTICLE as entity Article, selecting all fields except MANDT. Set PRODUCTUUID as key.
Right click-the Data Model node and choose Import → DDIC Structure.
In the Import from DDIC Structure popup, in the Name field, enter Article.
In the ABAP Structure field, enter GW100CARTICLE.
Choose Next.
Select the GW100CARTICLE checkbox.
Deselect the MANDT checkbox.
Choose Next.
In the PRODUCTUUID field, select the Is Key checkbox.
Choose Finish.
Choose Save.
Task 3: Model a Navigation between Supplier and Article
Steps
Model navigation Supplier_Articles between the Supplier and Article entities, connecting one Businesspartneruuid to many Supplieruuid. Create the navigation properties Article and Supplier in the according entity types.
In the SAP Gateway Service Builder of your S4H, expand the Data Model node.
Right-click the Associations node and choose Create.
In the Create Association popup, in the Association Name field, enter Supplier_Articles.
For the Principal Entity, enter the following values:
Field | Value |
---|
Entity Type Name | Supplier |
Cardinality | 1 |
Navigation Property | Article |
For the Dependent Entity, select the Create related Navigation Property checkbox.
For the Dependent Entity, enter the following values:
Field | Value |
---|
Entity Type Name | Article |
Cardinality | 0..n |
Navigation Property | Supplier |
Choose Next.
In the Dependent Property field, enter Supplieruuid by using the value help.
Choose Next.
Choose Finish.
Choose Save.
Task 4: Map Read and Query Operations to CDS Data Definitions
Steps
In the SAP Gateway Service Builder of your S4H, map the read and the query operations of entity set SupplierSet to the CDS view GW100_C_Supplier using the association _ARTICLES for navigation.
In the SAP Gateway Service Builder of your S4H, expand the Service Implementation node.
Right-click the SupplierSet node and choose Map to Data Source.
In the Map to Data Source popup, in the Type dropdown, select Business Entity.
In the Name field, use the value help.
In the Select Business Entity popup, enter the following values:
Field | Value |
---|
SADL Model Type | CDS Core Data Services |
SADL Model | GW100_C_Supplier |
Choose Continue.
Note
The Data Source Attribute Name field should now contain the value CDS~GW100_C_Supplier.Choose Continue.
Choose Generate Mapping.
Choose Associations.
Choose Generate Mapping.
Choose Save.
Map the read and the query operations of entity set ArticleSet to the CDS view GW100_C_Article using the association _SUPPLIER for navigation.
Right-click the ArticleSet node and choose Map to Data Source.
In the Map to Data Source popup, in the Type field, enter Business Entity.
In the Name field, use the value help.
In the Select Business Entity popup, enter the following values:
Field | Value |
---|
SADL Model Type | CDS Core Data Services |
SADL Model | GW100_C_Article |
Choose Continue.
Note
The Name for the Data Source Attribute field should now contain the value CDS~GW100_C_Article.Choose Continue.
Choose Generate Mapping.
Choose Properties.
Choose Generate Mapping.
Choose Save.
Task 5: Generate and Register a CDS-based SAP Gateway Service
Steps
In the SAP Gateway Service Builder of your S4H, generate the runtime objects and add them to your package ZGW100_##_BES.
In the SAP Gateway Service Builder of your S4H, choose Generate Runtime Objects.
In the Model and Service Definition popup, to accept the proposed names, choose Continue.
In the Package field, enter ZGW100_##_BES.
Choose Save.
In the Prompt for transportable workbench request popup, in the Request field, select the transport request provided to you.
Choose Continue.
Register and activate the service in your S4H using your package ZGW100_##_FES.
Double-click the Service Maintenance node.
Right-click the LOCAL_GW system.
Select Register.
In the Select System Alias (Hub to Backend) popup, in the System Alias field, enter LOCAL.
Choose Continue.
In the Add Service popup, in the Package Assignment field, enter ZGW100_##_FES.
Choose Continue.
For every popup, choose the transport request provided to you.
Choose Save.
Task 6: Test the Query and Read Operations of Supplier and Article
Steps
In the SAP Gateway Client of your S4H, test the paging operation for suppliers in your service. Query the first two suppliers.
Choose SAP Gateway Client.
In the SAP Gateway Client, select HTTPS as Protocol.
Choose Entity Set.
In the Entity Sets popup, double-click SupplierSet.
Choose Add URI Option.
In the Add URI Option popup, double-click $top=2.
Example
/sap/opu/odata/SAP/ZGW100_##_CDS_SRV/SupplierSet?$top=2
Choose Execute.
Result
The HTTP Response displays the first two suppliers.
Test the sorting operation for suppliers in your service. Query suppliers sorted by their company name ascending.
In the Request URI field, add &$orderby=Companyname asc to the URI.
Example
/sap/opu/odata/SAP/ZGW100_##_CDS_SRV/SupplierSet?$top=2&$orderby=Companyname asc
Choose Execute.
Result
The HTTP Response displays the first two suppliers ordered by company name ascending.
Test the filter operation for suppliers in your service. Query the suppliers whose e-mail address starts with "supplier".
In the Request URI field, add $filter=startswith(Emailaddress, 'supplier') to the URI.
Example
/sap/opu/odata/SAP/ZGW100_##_CDS_SRV/SupplierSet?$top=2&$orderby=Companyname asc&$filter=startswith(Emailaddress, 'supplier')
Choose Execute.
Result
The HTTP Response displays the first two suppliers ordered by company name ascending whose e-mail address starts with "supplier".
Test the read operation for suppliers in your service. Read a single supplier.
In the Request URI field, replace all query options by the key of a supplier with guid in front.
Example
/sap/opu/odata/SAP/ZGW100_##_CDS_SRV/SupplierSet(guid'00505604-4e85-1edd-b9b4-a81d353342c0')Hint
Copy the self link of a supplier in the HTTP Response. Choose Execute.
Result
The HTTP Response displays the selected supplier.
Test the navigation between suppliers and articles in your service. Query the articles of a supplier.
Hint
If no articles are found for a supplier, make sure to select a supplier with an e-mail address starting with "supplier".In the Request URI field, add /Article to the URI.
Example
/sap/opu/odata/SAP/ZGW100_##_CDS_SRV/SupplierSet(guid'00505604-4e85-1edd-b9b4-a81d353342c0')/Article
Choose Execute.
Result
The HTTP Response displays the articles of the supplier.
Test the expand operation for suppliers and articles in your service. Read a supplier including its articles.
In the Request URI field, replace the / in front of Article with ?$expand=
Example
/sap/opu/odata/SAP/ZGW100_##_CDS_SRV/SupplierSet(guid'00505604-4e85-1edd-b9b4-a81d353342c0')?$expand=Article
Choose Execute.
Result
The HTTP Response displays the supplier including its articles.
Task 7: Document the Query Options Generated via SADL in the Metadata
Steps
In the SAP Gateway Service Builder of your S4H, set entity sets SupplierSet and ArticleSet to be Pageable and set all properties of entity types Supplier and Article to be Filterable and Sortable.
In the SAP Gateway Service Builder of your S4H, expand Data Model.
Double-click Entity Sets.
For the SupplierSet and ArticleSet, set the Pageable checkbox.
Expand Entity Types → Supplier.
Double-click Properties.
For all properties, set the Filterable and Sortable checkbox.
Expand Article.
Double-click Properties.
For all properties, set the Filterable and Sortable checkbox.
Choose Generate Runtime Objects.