Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182329
Participant
11,448

Hi All,

        This document covers about Function Import in OData along with an overview of Eclispe OData Modeler tool. Function import is a feature in OData that is similar to an RFC call. Function import will be having import and output parameters separate rather than using the same structure for import and export in other CRUD operations in OData

.

Usually function imports are used when the similar functionality cannot be achieved by CRUD operations. Function imports can be invoked as GET or POST HTTP methods.

     

The following are the steps involved in creating a Function Import. In this tutorial, instead of importing a DDIC structure. I will be creating the OData Model from a Eclipse OData Modeler.

Here the scenario is to  create an OData to fetch the Flight Booking Details from the SBook table.

Step1- Creating the necessary OData model in eclipse

    i) First create a blank UI5 project to add the OData Model into it

    ii)Now create a new OData Development project and select OData Model

    iii)Select Blank OData model and the folder should be pointing towards the black SAP UI5 project you have created before.

    iv)In the OData editor, you can create Entity Types, Navigation, Associations etc via the GUI editor.

    iv)Drag and drop the Entity Type into the editor, Right click the Entity Type and select Add Property and add new fields(Select simple).

    vi)You can directly edit the properties of each field in the properties tab as shown below

    vii)Add all the necessary fields for the Entity Type.

    viii)Now right click on the project and click on export, select OData Model under OData Development.

    ix)Select OData V2 SAP Specific from the drop down list


Step 2-Function Import creation in OData

    i)Create a new project and Import OData Model into Gateway Service Builder

    ii)Browse to the exported OData Model file

    iii)Choose the fields required for your Entity Type

    iv)Entity type is being created

    v)Create the corresponding Entity Set

    vi)Here specify the features that you want for your entity sets by checking the checkboxes

    vii)Now right click on the Function Import and click create

    viii)Give the name for your Function Import

    ix)Select the cardinality as 1:n and then mention the HTTP Method as GET ,select your Entity Set as return entity set and the Entity Type as the same Entity Type you created before.

     What is happening here is that you have to specify the return parameters for the function import, and we are using the entity set we created in this project as a return table parameter, which will be having all the booking details that is fetched from the backend Sbook table.

    x)Now we need to create import parameters for your import function.(This will be the fields that you will be passing to the OData to get the table in return from the function import as the result, just like how you will be calling an RFC).

     Click on new and create the two fields that we want as input parameters for the function import. In this case it will be carr_id and conn_id specify the EDM core Type and Data element.

    xi)Now click on the red generate button on the upper left side of the screen and system will now create all Data Provider and Model Provider classes .

    xii)Since ours is a custom method, we have to Go to Method /IWBEP/IF_MGW_APPL_SRV_RUNTIME

    xiii)Redefine the method (EXECUTE_ACTION)  /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION

          In this method

1) Parameter iv_action_name  will contain the custom function name that you will be requesting through OData URL.

2) Parameter it_parameter    will be having the key fields that you will be sending to the OData as input(ie conn_id and carr_id)

Code Sample


DATA:   ls_parameter  TYPE /iwbep/s_mgw_name_value_pair,

ls_entity     TYPE zcl_zfm_import_mpc=>ts_flight_booking_history,
lt_entityset 
TYPE zcl_zfm_import_mpc=>tt_flight_booking_history,
lv_task_id   
TYPE ztask_cnt,
lv_carr_id   
TYPE S_CARR_ID,
lv_conn_id   
TYPE S_CONN_ID.


IF iv_action_name = 'Flt_Bk_Hst'.
IF it_parameter IS NOT INITIAL.
*
** Read Function import parameter value
READ TABLE it_parameter INTO ls_parameter WITH KEY name = 'carr_id'.
lv_carr_id
= ls_parameter-value.
READ TABLE it_parameter INTO ls_parameter WITH KEY name = 'conn_id'.
lv_conn_id
= ls_parameter-value.


SELECT  * FROM sbook INTO CORRESPONDING FIELDS OF
TABLE lt_entityset 
WHERE CARRID  = lv_carr_id
AND   CONNID  = lv_conn_id.                                                                “Your logic to fetch your data goes here


copy_data_to_ref
( EXPORTING is_data = lt_entityset        "This is used to set the data back to the Odata response

CHANGING cr_data = er_data ).

ENDIF.

     xiv) Save the above code and activate it.The go to the Net weaver gateway client to test the OData.

          Use  /sap/opu/odata/sap/ZFM_IMPORT_SRV/$metadata (use the $metadata URI to see the custom function import name in the response body)

     xv) /sap/opu/odata/sap/ZFM_IMPORT_SRV/Flt_Bk_Hst?carr_id='AA'&conn_id='19'

          Now use the above URL format to access the function import and the input parameters which is separated by ‘&’.

     xvii)You can see the output of the OData with corresponding Booking Details against the Keys.

     xviii)Output in browser

Regards,

Bince Mathew

9 Comments
sreehari_vpillai
Active Contributor
0 Kudos

Good work Bince .

Sree

balaji_bodagala5
Participant
0 Kudos

Nice Mathew,

CarlosRoggan
Product and Topic Expert
Product and Topic Expert
0 Kudos

Great Document, that covers 2 tools end to end

Keep going, bince.mathew2

former_member220538
Active Participant
0 Kudos

Its useful.. thanks for sharing it!!!

vishnucta
Active Participant
0 Kudos

Hi Bince,

How about when there are multiple inputs.i.e internal table.

I040107
Advisor
Advisor
0 Kudos

Hi Bince,

     do you know a way in order to export Odata from SEGW into Eclipse ?

thanks

Filippo

CarlosRoggan
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Filippo,

what you can do  is to register your service, then invoke the $metadata document in a browser and download the xml source to a file.

This file can then be imported in Eclipse, while creating a new OData Model, you have the choice it create from "OData Metadata File".

Or you can use File -> Import -> OData Model

Alternatively, you can do the same directly from the "OData Service URL"

Cheers,

Carlos

karthikarjun
Active Contributor
0 Kudos

Hi,

Good work Bince :smile: ....

Thanks,

Karthi

0 Kudos
Hi

At Step xiv) you failed to mention that before you test the OData Service, (Transaction Code: /IWFND/GW_CLIENT) you need to Activate the Service under the Service Maintenance folder, by double-clicking something like GATEWAYSERVER. Or at least that is what I had to do.

In fact, I had to go to SPRO to create the GATEWAYSERVER in SAP Gateway Settings as per another document (http://go.sap.com/documents/2012/11/44779e8c-5b7c-0010-82c7-eda71af511fa.html)


 
Labels in this area