首页 > SAP > ABAP > Function Import in SAP OData Service
2019
08-29

Function Import in SAP OData Service

Hello everyone, in this tutorial we will learn about Function Import in SAP Gateway OData Service and how to implement Function Import.

1.What is Function Import ?

Function Imports are the actions like release of a sale-ale settingss order/purchase order executed in the backend system.We use Function Imports when ever the requirement the does not fit into the CRUD-Q operations.They are defined at service level and you can have N number of function imports functions.

2.Business Example

We have a table in which it contains customer information. Each every customer information have to be approved to make use of it. In this scenario to approve each customer information we will use Function Import.

Function Import in SAP OData Service - 第1张  | 优通SAP

3.

3.1.Create Function Import in SAP Netweaver OData Service

1. Go to Gateway Service Builder SEGW and choose the project in which you want to create Function Import.

2. Expand the project, right click on Data Model and choose Create and the Function Import.

3. Specify the name of the function import and click on green tick mark button.

4.  In the next screen you will find different options for the Function Imports lets have a look at each of them.

Return Type Kind :  If you want the Function Import to return data you can set this field. We have 3 possible options available

Complex Type – if the return data is of complex entity type, select this option
Entity Type – if the return data is of entity type, select this option and
No return – if you do not want to return anything, select this option.

Return Type : This field depends on the option you have choose above. You need to specify the name of the type in this field. Use the input help to choose from existing types or create a new type.

If you choose Complex Type in the above step, you need to specify the name of the complex entity type in this field and specify the name of entity type if you choose Entity Type option in the above step.
if you choose No return, this field will be empty.

Return Cardinality :

[adsenseyu1]

HTTP Method Type : Choose the HTTP method type to invoke the Function Import. Choose GET , when you want to get the data from the backend using Function Import. Choose POST, when you want to push data to backend using Function Import.

Action for Entity Type : This field is used to identity to which Entity Type in the service, the Function Import is applies as ACTION. Specify the entity type name available in the service.

Label :

In our business requirement we have set the following options

5. In this step we need to create Import Parameters to the Function Import we have created in the above step.In our business case, we need to two importing parameters Customer Id and Approval Flag. Create them and Save the parameters.

6. Till now we have defined  the Function Import and our next step is to implement it before going further we want to make sure that every thing is OK till now.Save the project and click on Generate to generate runtime objects. We should see the Function Import in the meta data of the service.

Go to Netweaver Gateway Client /IWFND/GW_CLIENT and specify the service name with meta data URI Option and Execute.

7. Now we need to implement the Function Import and this is done in the DPC_EXT class and method is /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION. Go the DPC_EXT class and redefine the method. Put the below code in the method.

The above code will update the status of APPROVED field which exists in the table.If the update is successfully it will return the success message or will return the error message.

8. So we are ready with Function Import implementation, it’s time to test the service.Go to Netweaver Gateway Client /IWFND/GW_CLIENT and specify the service name with Function Import name and its importing parameters. The Url will look like below

/sap/opu/odata/sap/ZTEST_GW_SRV_SRV/demoFuncImport?Approved_Flag=’X’&CustId=’0000000001′

Change the HTTP method to POST and hit execute button.You should see the success message in output like below.

Go back to table and check whether the approval flag has been set to ‘X’.

Please stay tuned to us for more SAP Netweaver Gateway Tutorials.Please feel free to comment and let us know your feedback. You feedback will keep us alive.

Thank you.

最后编辑:
作者:yangsen
本站为个人博客网站,全由我个人维护,我从事SAP开发13年,其它ERP开发7年,基本都是零售行业。本站记录工作学习的过程, 有SAP相关询问专、兼职工作可随时联系我。 有网站相关的问题可直接在文章下方留言,或者联系我。 邮件:yan252@163.com给我。 QQ:415402519

留下一个回复

你的email不会被公开。