Steps to build an RFC based OData Service with multiple selection values
Here is a step by step guide on how to build an RFC based OData service with multiple selection (input) values.This document would help developers who are new to the Odata services. You can also find few sample queries at the end of the document.
The business requirement given here is to build an OData service which can retrieve shopping cart information from the system based on a combination of input fields (single and multiple values).
Below is the list of input fields:
Selection fields |
Multiple values? |
User ID (Requestor) |
|
User ID (Creator) |
|
Creation Date (From) |
|
Creation Date (To) |
|
Product Category Code |
Yes |
Vendor Number |
Yes |
Shopping Cart Number |
|
External Req Number |
|
Shopping Cart Status |
|
Supplier Part Number |
|
Cost Center |
|
Line Item Description |
|
Company Code |
|
Purchasing Group |
Yes |
Plant |
Below is the expected output:
Display fields |
Shopping Cart Number |
Creation Date |
Shopping Cart Status |
Shopping Cart Requestor |
Shopping Cart Creator |
Shopping Cart Description |
Total Price of Shopping Cart |
Process Level |
Current Work Agent |
Step1.
Create a RFC function module in the backend system with below parameters as input
For the input parameters that need multiple values to be supplied, create them as range table types.
Step2.
Go to SAP Netweaver Gateway Service builder (SEGW) and create a project.
Step3.
Click on Data Model -> Import -> RFC/BOR Interface
Step4.
Enter the Entity Type name and the RFC details.
Step5.
Select all the fields to be used in the entity type
Step6.
Make the Shopping Cart ID as the key field.
Step7.
Change the field names and set rest of the attributes as required.
Step8.
Now create an entity set and link the entity type to the entity set.
Step9.
Now go to Service Implementation and create a GetEntitySet (Query) operation
Step10.
Do the mapping between entityset and RFC for both input and output fields.
The fields which are of range table type would appear with a [ ] sign.
Step11.
After all the mapping is completed, click on the “Generate” button (highlighed below in yellow).
This will generate all the runtime artifacts for this service as shown below.
Step12.
Now go to tcode /IWFND/MAINT_SERVICE in the Netweaver gateway system and search for the service.
Step13.
Double click on the service ZGSTS_ITM_SC_PO_DISPLAY_SRV to add and activate it.
ICF Nodes and System Aliases are populated. Now the service is activated.
Now we can construct queries in order to retrieve the shopping cart information using this OData service (few examples given below):
/sap/opu/odata/sap/ZGSTS_ITM_SC_PO_DISPLAY_SRV/SCHeaderCollection?$filter= IN_ShopCartId eq ‘1000045468’ and IN_IsidRequestor eq ‘USMANAGER6’
/sap/opu/odata/sap/ZGSTS_ITM_SC_PO_DISPLAY_SRV/SCHeaderCollection?$format=json&$top=10&$filter= IN_ShopCartId eq ‘1000045468’and IN_IsidRequestor eq ‘USMANAGER6’
/sap/opu/odata/sap/ZGSTS_ITM_SC_PO_DISPLAY_SRV/SCHeaderCollection?$filter= IN_IsidRequestor eq ‘USEMPLOYEE15′ and IN_CreateDate eq datetime’2013-12-01T00:00:00′ and IN_CreateDateTo eq datetime’2013-12-31T00:00:00’
/sap/opu/odata/sap/ZGSTS_ITM_SC_PO_DISPLAY_SRV/SCHeaderCollection?$filter= IN_IsidRequestor eq ‘USEMPLOYEE15’ and (IN_CategoryId eq ‘10100000’ or IN_CategoryId eq ‘43211507’)