Skip to Content
author's profile photo Former Member
Former Member

Function Imports - USE

Hi !!

I have been developing OData Services in SEGW and came across Function imports. I went through

https://help.sap.com/saphelp_nw74/helpdata/en/c5/dc22512c312314e10000000a44176d/content.htm

and I still am not clear about it. Could anyone please help me with this ?

Could anyone explain -

  • The use of function imports ?
  • Why use function imports , when we can implement CRUD operations through entities.
  • some scenarios where function imports are used ?
  • When to use function imports and when to implement CRUD through entities.
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Aug 08, 2014 at 01:57 PM

    Hi,

    Please refer my blog Let’s code CRUDQ and Function Import operations in OData service! and check the last section on function import.

    Regards,

    Chandra

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Supriya,

      Are u using SEGW to build services ?

      If yes then below details will help u resolving error.

      However even if u r not using segw t-code to build services and if u r using Code based Implementation ( se80 ) technique, then also we its good to code the below way.

      U get that error because there is a structure mismatch.

      So Please check again and send back the appropriate structure as response.

      Please refer this which will help u resolving the issue.

      When u go to ur /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET in DPC_EXT class

      the code and the method signature would be like this ( care fully observe the text highlighted )

      method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET.

      DATA get_empset_get_entityset TYPE zcl_zash_test_user_01_mpc=>tt_get_emp.

      DATA testset_get_entityset TYPE zcl_zash_test_user_01_mpc=>tt_test.

      DATA lv_entityset_name TYPE string.

      lv_entityset_name = io_tech_request_context->get_entity_set_name( ).

      CASE lv_entityset_name.

      *-------------------------------------------------------------------------*

      * EntitySet - get_empSet

      *-------------------------------------------------------------------------*

      WHEN 'get_empSet'.

      * Call the entity set generated method

      get_empset_get_entityset(

      EXPORTING

      iv_entity_name = iv_entity_name

      iv_entity_set_name = iv_entity_set_name

      iv_source_name = iv_source_name

      it_filter_select_options = it_filter_select_options

      it_order = it_order

      is_paging = is_paging

      it_navigation_path = it_navigation_path

      it_key_tab = it_key_tab

      iv_filter_string = iv_filter_string

      iv_search_string = iv_search_string

      io_tech_request_context = io_tech_request_context

      IMPORTING

      et_entityset = get_empset_get_entityset

      es_response_context = es_response_context

      ).

      * Send specific entity data to the caller interface

      copy_data_to_ref(

      EXPORTING

      is_data = get_empset_get_entityset

      CHANGING

      cr_data = er_entityset

      ).

      *-------------------------------------------------------------------------*

      * EntitySet - testSet

      *-------------------------------------------------------------------------*

      WHEN 'testSet'.

      * Call the entity set generated method

      testset_get_entityset(

      EXPORTING

      iv_entity_name = iv_entity_name

      iv_entity_set_name = iv_entity_set_name

      iv_source_name = iv_source_name

      it_filter_select_options = it_filter_select_options

      it_order = it_order

      is_paging = is_paging

      it_navigation_path = it_navigation_path

      it_key_tab = it_key_tab

      iv_filter_string = iv_filter_string

      iv_search_string = iv_search_string

      io_tech_request_context = io_tech_request_context

      IMPORTING

      et_entityset = testset_get_entityset

      es_response_context = es_response_context

      ).

      * Send specific entity data to the caller interface

      copy_data_to_ref(

      EXPORTING

      is_data = testset_get_entityset

      CHANGING

      cr_data = er_entityset

      ).

      WHEN OTHERS.

      super->/iwbep/if_mgw_appl_srv_runtime~get_entityset(

      EXPORTING

      iv_entity_name = iv_entity_name

      iv_entity_set_name = iv_entity_set_name

      iv_source_name = iv_source_name

      it_filter_select_options = it_filter_select_options

      it_order = it_order

      is_paging = is_paging

      it_navigation_path = it_navigation_path

      it_key_tab = it_key_tab

      iv_filter_string = iv_filter_string

      iv_search_string = iv_search_string

      io_tech_request_context = io_tech_request_context

      IMPORTING

      er_entityset = er_entityset ).

      ENDCASE.

      endmethod.

      If u go inside the method GET_EMPSET_GET_ENTITYSET

      Signature ->

      Here when u return the response the response shud be of the type which is highlighted in red.

      If u go inside the method TESTSET_GET_ENTITYSET

      Signature->

      Here when u return the response the response shud be of the type which is highlighted in red.

      The copy_data_to_ref method is a standard method and u need to call that which is correct.

      Hope this will help u in resolving the error.

      Regards,

      Ashwin

  • author's profile photo Former Member
    Former Member
    Posted on Aug 12, 2014 at 09:17 AM

    Hi Manvitha,

    As stated in other responses, function imports can be used where CRUD doesn't fit, however there are some drawbacks.

    Overuse can start to make the ODATA protocol more SOAP-like with a focus on business functions rather than the data.

    They aren't currently associated with a particular entity, they float around in the service definition. If I understand the Odata 4 spec properly, this is going to change.

    Most operations that are turned into a function import can be implemented under CRUD with the right design, such as using "aliased" entities (I'm not sure if there is an official term for this technique).

    An example of aliasing would be a set of entities based on the "sales order" business object. You could have Orders, UnconfirmedOrders and ConfirmedOrders.

    A full query on Orders would result in a union of all three possible sets, but a full query on the other two would result in two mutually exclusive sets. If I wish to confirm an order under CRUD, I simply get it from UnconfirmedOrders and PUT it to ConfirmedOrders. The source and target entities indicate to the backend what is happening so the logic can run the confirmation process. After the PUT, I will find that the 'location' of the order has changed; it is still in Orders, but is now in ConfirmedOrders instead of UnconfirmedOrders.

    I actually prefer this design pattern as it fits in with REST principles of using URI's and navigating. By "moving" the URI to a navigable point, I have managed to alter the business object state.

    The main difficulty, with a function import or an aliased entity, is conveying the usage pattern to a consumer. Assume that the consumer doesn't know all the little wrinkles in your service. Yes, you are porbaly writing it for your won app, but OData is about published services that might need to be exposed to the global community, they should not be anachronistic!

    I would try to use whichever one requires the simplest form of URI and is easiest to convey usage.

    Regards

    Ron.

    Add a comment
    10|10000 characters needed characters exceeded

    • Very interesting Ron..

      Definitely would need explanation understanding this and implementation.

      If I wish to confirm an order under CRUD, I simply get it from UnconfirmedOrders and PUT it to ConfirmedOrders. The source and target entities indicate to the backend what is happening so the logic can run the confirmation process

      May be you can I request you to write a blog on this design pattern? Also interested to understand how do you design 'Search Helps'.

      Thanks

      Krishna

  • Posted on Aug 08, 2014 at 02:57 PM

    Hello Manvitha,

    We go for Function_Import or Custom_Action when the operation/business-scenario which we would like to do/implement will not fall under standard CRUD operations.

    Apart from what Chandra has explained, i would like to quote one more example where we go or Function_Import/Custom_Action.

    Lets say we have a scenario -

    1. Say we have ordered a an ITEM with ID 'IT-001'

    2. User can also cancel that order correct ?!

    3. Now question is how to implement this Business_Case ?!

    a. This can be implemented using Update/Delete operations as Cancelling your Order can be treated as Update as well as a Delete operation.

    b. This can also be implemented as Function_Import/Custom_Action as the above business case will not fall under standard Update/Delete operation.

    Technically we can fit the above scenario in Update/Delete operation and also in Custom-Action/Function-Import as well as the code written would be the same for the above case irrespective of whether we are calling Delete or Update or some Custom_Action.

    But GW provides some standard ways to handle the above kind of business-cases. So we go for Function-Import.

    Regards,

    Ashwin

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Ashwin,

      Thanks for the information. so, as per my understanding-

      We can choose between the two options for implementing CRUD operations and it would be ideal to implement it through execute_action using function imports for scenarios like the one you mentioned.

      Regards,

      Manvitha

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2014 at 06:36 AM

    Hi,

    Interesting thread to me... I had this confusion earlier, but only until I find a use case.

    I worked on a sample which requires that form be approved/rejected from browser. And, I did not find the need to use POST operating to do this as this has nothing to do with any of the entities and associated data. All I need is to trigger the workflow with some inputs to the same.

    I used a function import with defined parameters and the job is done...

    Also, one more use case where I have to pre-load the employee details along with his line manager details. I don't know the employee number to perform a query from form, so I used a function import with no parameters at all, that just reads the data and the result is the entities with information I required.

    Now that the discussion is going good, can someone suggest me with a better approach..

    Best regards,

    Nadh

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 15, 2019 at 02:17 PM

    Function Import is used when we dont want to send any payload data in request body, but passing some data(key like order) in URL or just calling that specific action(Function Import) that specific action is executed. Example in SAP EWM is like Picking, Packing or in SD and MM confirmation of any order where in only action need to execute with parameter, no need to payload in request.

    So in SD, MM, PP for confirmation of any order just sending order number in url , confirmation action will be executed(where underneath method or function doesn't require any data except order).

    Same for in EWM picking and packing, just need to pass order and corresponding function import will be executed.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 22, 2019 at 10:40 AM

    We go for Function Import when the operations or business scenario are not achievable by CRUD operations. For Example, Say we have same field in 2 tables(Different Entitysets) which doesn't have any relationships, If we want to fetch the data based on one table to another then we will write this code in Function Import . Remember Function Imports are independent of Entitysets.

    Thank you and correct me if I am wrong.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.