Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
volkerdrees
Product and Topic Expert
Product and Topic Expert
Hello again.

In the first part (1) we have created a service that consists of two entities (Sales Order and Sales Order Line Item) and two related entity-sets. The runtime artifacts have been generated and the OData service has been registered and activated.
In this part (2) we will map both entity-sets to the related data providers – in our case the 2 EPM BAPIs.
When it comes to data provider mapping / implementation of OData services you usually start with the Query method as this is a typical entry point when consuming a service. In our case we will first enable the query: “provide me all Sales Orders that exist”. In a real business case you would probably make some filtering mandatory to not overload the backend system. But let’s keep it simple for the time being… 

1. As mentioned we will start with the Query method for the SalesOrderCollection entity-set. Expand the node Service Implementation ->  SalesOrderCollection and right-click GetEntitySet (Query) and select Map to Data Source:
2. In the map to data source window, enter the following values and choose Enter:
Target SystemLocal
Data Source TypeRemote Function Call
Data Source NameBAPI_EPM_SO_GET_LIST

3. The mapping has already done because the data model has been built based on the same RFC interface. For each property, set the Mapping Direction to Output. Choose Enter:
Now we can move on and do the mapping for the Read operation (GetEntity) of the SalesOrderCollection.
1. Right-click GetEntity (Read) and select Map to Data Source:
2. In the Map to Data Source dialog box, enter the following values and choose Enter:
Target SystemLocal
Data Source TypeRemote Function Call
Data Source NameBAPI_EPM_SO_GET_DETAIL
3. This time there are no default mapping settings because the data model has been defined based on a different RFC module.
Expand the HEADERDATA node from the tree on the right-hand side:
4. Drag&drop the following fields from the right-hand tree to the Data Source Parameter column of the grid in the middle of the screen:
RFC Field (right –hand side)Entity Property
SO_IDSoId
NOTENote
BUYER_IDBuyerId
BUYER_NAMEBuyerName
CURRENCY_CODECurrencyCode
GROSS_AMOUNTGrossAmount
NET_AMOUNTNetAmount
TAX_AMOUNTTaxAmount

In any Read Operation we also need to provide the primary key of the underlying entity as an input parameter. For this we have to manually add a new line to the mapping screen.

1. Choose the Append Row pushbutton:

2. On the new line press F4 to select the entity set property. Double-click SoId to select the entry:

3. Expand the SO_ID node from the tree on the right-hand side:

4. Drag&Drop the RFC field SO_ID (from node SO_ID) to the newly-created line:

5. This performs the mapping on the input parameter (Sales Order ID to fetch the Sales Order details):

Now we can move on with mapping the Query operation for the Sales Order Item entity-set


1. Expand the node Service Implementation -> SalesOrderItemCollection and right-click GetEntitySet (Query) and select Map to Data Source:

2. In the Map to Data Source dialog box, enter the following values and choose Enter:

Target SystemLocal
Data Source TypeRemote Function Call
Data Source NameBAPI_EPM_SO_GET_DETAIL

3. There is again no default mapping because the data model has been built based on a different RFC module. Expand the ITEMDATA node from the tree on the right-hand side:

4. Drag&drop the following fields from the right-hand tree to the Data Source Parameter column of the grid in the middle of the screen:

RFC Field (right –hand side)Entity Property
SO_IDSoId
SO_ITEM_POSSoItemPos
PRODUCT_IDProductId
NOTENote
CURRENCY_CODECurrencyCode
GROSS_AMOUNTGrossAmount
NET_AMOUNTNetAmount
TAX_AMOUNTTaxAmount
QUANTITYQuantity
QUANTITY_UNITQuantityUnit


5. In the Direction Column set all fields to Output. Choose Enter:

6. Choose Append Row button:

7. From the input help, select SoId for the new line:

8. Expand the SO_ID node from the right-hand tree:

9. Drag&drop the RFC field SO_ID (from node SO_ID) to the newly created line:

Now we are done with the data provider mapping (at least for the Query and Read operations we need). Now we can re-generate the runtime artifacts and run our OData service.

1. Choose the Generate pushbutton:

2. Verify that the runtime objects have been generated successfully:

3. Start the Gateway Client (Transaction /IWFND/GW_CLIENT) in a separate window to run the service. Provide the following URI to get the Sales Order Collection. This executes the query method of the Sales Order entity-set: 
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection

4. Choose any sales order entry and use the URI to navigate to the sales order detail, for example:
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderCollection('0500000001')

5. Get the related sales order line items via the following URL:
/sap/opu/odata/sap/ZGW100_XX_SO_SRV/SalesOrderItemCollection/?$filter=SoId eq '0500000001'

 

To navigate from the Sales Order entity to the related line items (Entity-Set), you need to construct the URI yourself. In the next part (3) you will see how to define an association and a navigation property between the two Entities.
31 Comments