May 20

OData Basics – Part 5 (Build Service with BAPI)

Let’s see how to build OData service by consuming Remote function module. Follow below steps:

2017-05-21 05_51_36-183.82.114.111_3333 - Remote Desktop Connection

Click ‘Create’ button

2017-05-21 05_51_59-183.82.114.111_3333 - Remote Desktop Connection

Enter Project, description and package as shown below:

2017-05-21 05_53_29-183.82.114.111_3333 - Remote Desktop Connection

Import data model from Remote enabled function module:

2017-05-21 05_54_21-183.82.114.111_3333 - Remote Desktop Connection

I have used BAPI_FLIGHT_GETLIST

2017-05-21 05_55_28-183.82.114.111_3333 - Remote Desktop Connection

Choose FLIGHT_LIST from parameters..

2017-05-21 05_56_26-183.82.114.111_3333 - Remote Desktop Connection

Make AIRLINEID as key field..

2017-05-21 05_56_49-183.82.114.111_3333 - Remote Desktop Connection

Define query operation and map it to data source:

2017-05-21 05_57_47-183.82.114.111_3333 - Remote Desktop Connection2017-05-21 05_58_32-183.82.114.111_3333 - Remote Desktop Connection

Click ‘Propose Mapping’ to perform automatic mapping. As our entity set is defined based on parameters of same RFC, automatic mapping is performed. If not, we have to manually drag and drop fields to map them.

2017-05-21 05_59_59-183.82.114.111_3333 - Remote Desktop Connection

Now, click ‘Generate’ button to generate run time artifacts.

2017-05-21 06_00_52-183.82.114.111_3333 - Remote Desktop Connection2017-05-21 06_01_15-183.82.114.111_3333 - Remote Desktop Connection

Activate service using trasanction “/IWFND/MAINT_SERVICE”

2017-05-21 06_04_57-183.82.114.111_3333 - Remote Desktop Connection

Click ‘Add Service’

2017-05-21 06_05_49-183.82.114.111_3333 - Remote Desktop Connection2017-05-21 06_07_34-183.82.114.111_3333 - Remote Desktop Connection2017-05-21 06_08_36-183.82.114.111_3333 - Remote Desktop Connection

2017-05-21 06_09_47-183.82.114.111_3333 - Remote Desktop Connection

Click ‘Call Browser’ to test the service:

2017-05-21 06_10_20-183.82.114.111_3333 - Remote Desktop Connection

http://<<FQDN>>/sap/opu/odata/sap/ZRZ_SERVICE_BY_RFC_SRV/$metadata will show the metadata information of our service

2017-05-21 06_12_15-183.82.114.111_3333 - Remote Desktop Connection

http://<<FQDN>>/sap/opu/odata/sap/ZRZ_SERVICE_BY_RFC_SRV/FlightListSet will return us complete data

2017-05-21 06_14_33-183.82.114.111_3333 - Remote Desktop Connection

I went back to modify the data model and included MAX_ROWS field as import parameter:

2017-05-21 10_54_20-183.82.114.111_3333 - Remote Desktop Connection.jpg

 

http://<<FQDN>>/sap/opu/odata/sap/ZRZ_SERVICE_BY_RFC_SRV/FlightListSet?$filter=Airline eq ‘AA’ and MaxRows eq 2

Output of RFC gave only two records now as shown in below screenshot:

2017-05-21 09_34_36-183.82.114.111_3333 - Remote Desktop Connection