Business Example
You are a developer or solution architect in your company. You need to implement an SAP Gateway service based on a CDS view.
- Template:
- None
- Solution:
- GW100_C_SupplierPublish (CDS Data Definition)
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 ABAP Project in Eclipse
Steps
In Eclipse, create an ABAP project connecting to your SAP S/4HANA (S4H) system. Add package ZGW100_##_BES as favorite.
In the Windows start menu, choose Eclipse.
Choose Hide in the upper right corner of the Welcome page.
Choose Open Perspective in the upper right corner.
Select ABAP and choose OK.
Choose New → ABAP Project.
In the Connection Settings popup, in the System ID field, enter the system ID of your S4H.
Select the Active Secure Network Communication (SNC) checkbox.
Choose Next >.
Enter your client and user and choose Finish.
In the Project Explorer, expand your system.
Right-click Favorite Packages and choose Add Package….
Enter ZGW100_##_BES and choose OK.
Expand Favorite Packages.
Task 2: Create a CDS Data Definition
Steps
Create the CDS view entity Z##_C_Supplier in your ZGW100_##_BES package with SEPM_I_BusinessPartner as data source. Set @Metadata.ignorePropagatedAnnotations to false and delete the @ObjectModel annotation.
Right-click the ZGW100_##_BES node and choose New → Other ABAP Repository Object.
In the New ABAP Repository Object popup, select Core Data Services → Data Definition.
Choose Next.
In the New Data Definition popup, in the Name field, enter Z##_C_Supplier.
In the Description field, enter a value of your choice.
Choose Next.
Select your transport request and choose Next.
Select the template Define View Entity.
Choose Finish.
For the data source name, enter SEPM_I_BusinessPartner and choose Enter.
Set @Metadata.ignorePropagatedAnnotations to false.
Delete the @ObjectModel annotation.
Your code should look like this:
123456789
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Supplier ##'
@Metadata.ignorePropagatedAnnotations: false
define view entity Z##_C_Supplier
as select from SEPM_I_BusinessPartner
{
}
Choose Save.
Note
There is still the error Unexpected word "}"
. Fields will be added in the next exercise step.
Include the following columns in Z##_C_Supplier. You may use the Insert all elements template of the code completion. Activate and run the data definition as ABAP application.
BusinessPartnerUUID
BusinessPartner
BusinessPartnerRole
Currency
CompanyName
LegalForm
EmailAddress
FaxNumber
PhoneNumber
URL
Place the cursor between the curly brackets.
Choose Ctrl+Space.
Select Insert all elements (template) and choose Enter.
Delete all associations.
Delete the following columns:
AddressUUID
CreatedByUser
CreationDateTime
LastChangedByUser
LastChangedDateTime
Your code should look like this:
12345678910111213141516171819
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Supplier ##'
@Metadata.ignorePropagatedAnnotations: false
define view entity Z##_C_Supplier
as select from SEPM_I_BusinessPartner
{
key BusinessPartnerUUID,
BusinessPartner,
BusinessPartnerRole,
Currency,
CompanyName,
LegalForm,
EmailAddress,
FaxNumber,
PhoneNumber,
URL
}
Choose Activate.
Choose Run → Run As → ABAP Application or F8.
Result
The Data Preview displays a list of suppliers.
Task 3: Publish a CDS Data Definition as OData Service
Steps
In Eclipse, connected to your S4H, publish the Z##_C_SUPPLIER data definition as OData service. Test the service from the Outline of the data definition.
In Eclipse, connected to your S4H, add @OData.publish: true above the view definition.
Your code should look like this:
12345678910
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Supplier ##'
@Metadata.ignorePropagatedAnnotations: false
@OData.publish: true
define view entity Z##_C_Supplier
as select from SEPM_I_BusinessPartner
...
}
Choose Activate.
In the Outline, expand Z##_C_SUPPLIER → secondary objects.
Right click OData Exposure and choose Open.
Log on using your user and password of your S4H.
Result
The Web browser displays the error No service found....
In the SAP Gateway Service Maintenance of your S4H, register the Z##_C_SUPPLIER_CDS service for system alias LOCAL using your package ZGW100_##_FES.
In the SAP Easy Access of your S4H, search for SAP Gateway Service Maintenance or start transaction /IWFND/MAINT_SERVICE.
In the SAP Gateway Service Maintenance, choose Add Service.
In the System Alias field, enter LOCAL.
In the Technical Service Name field, enter Z##*.
Choose Get Services.
Choose Z##_C_SUPPLIER_CDS.
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.
In the Information popup, choose Continue.
Choose Back.
Task 4: Test the Metadata, Query, and Read Operations of the SAP Gateway Service
Steps
In the SAP Gateway Client of your S4H, test the metadata of your service. What are the names of the entity type and entity set?
In the SAP Gateway Service Maintenance of your S4H, choose SAP Gateway Client.
In the SAP Gateway Client, select HTTPS as Protocol.
Choose Add URI Option.
In the Add URI Option popup, double-click $metadata.
Example
/sap/opu/odata/SAP/Z##_C_SUPPLIER_CDS/$metadata
Choose Execute.
Result
The HTTP Response displays the metadata of Z##_C_SupplierType and Z##_C_Supplier.
Test the paging operation for suppliers in your service. Query the first two suppliers.
Choose Entity Set.
In the Entity Sets popup, double-click Z##_C_Supplier.
Choose Add URI Option.
In the Add URI Option popup, double-click $top=2.
Example
/sap/opu/odata/SAP/Z##_C_SUPPLIER_CDS/Z##_C_Supplier?$top=2
Choose Execute.
Result
The HTTP Response displays the first two suppliers.
Test the sorting operation for suppliers in your service. Query suppliers are sorted by their company name ascending.
In the Request URI field, add &$orderby=CompanyName asc to the URI.
Example
/sap/opu/odata/SAP/Z##_C_SUPPLIER_CDS/Z##_C_Supplier?$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/Z##_C_SUPPLIER_CDS/Z##_C_Supplier?$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/Z##_C_SUPPLIER_CDS/Z##_C_Supplier(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.
Task 5: Change the OData Service Data Model in a CDS Data Definition
Steps
In Eclipse connected to your S4H, in the Z##_C_SUPPLIER data definition, set the entity set name to Supplier and the entity type name to SupplierType.
In Eclipse connected to your S4H, add @OData.entitySet.name: 'Supplier' one line beneath @OData.publish: true.
Add @OData.entityType.name: 'SupplierType' one line beneath @OData.entitySet.name: 'Supplier'.
Your code should look like this:
123456789101112
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Supplier ##'
@Metadata.ignorePropagatedAnnotations: false
@OData.publish: true
@OData.entitySet.name: 'Supplier'
@OData.entityType.name: 'SupplierType'
define view entity Z##_C_Supplier
as select from SEPM_I_BusinessPartner
...
}
Activate your changes.
In the SAP Gateway Client of your S4H, test the metadata of your service. What are the names of the entity type and entity set?
In the SAP Gateway Client, select HTTPS as Protocol.
Choose Add URI Option.
In the Add URI Option popup, double-click $metadata.
Example
/sap/opu/odata/SAP/Z##_C_SUPPLIER_CDS/$metadata
Choose Execute.
Result
The HTTP Response displays the metadata of SupplierType and Supplier.
Test the query operation for suppliers in your service. Query all suppliers.
Choose Entity Set.
In the Entity Sets popup, double-click Supplier.
Example
/sap/opu/odata/SAP/Z##_C_SUPPLIER_CDS/Supplier
Choose Execute.
Result
The HTTP Response displays all suppliers.