How do you call a function import in SAP ODATA Service

Function imports:

They are useful in performing predefined actions in the system. Function imports are implemented when the implementation cannot be done using the CRUD-Q Methods

Steps to create a function import in ODATA Service

  1. Go to the Transaction SEGW ( Gateway service builder ) and open the Project.
  2. Expand the ‘Project’ and choose the ‘Data model’ and then right click to choose ‘Create’ and then select the function import.
  3. The Function import is uniquely identified based on its name. so give an unique name and select the tick mark.
  4. Maintain the critical parameters of the Function import such as Return type kind, Return Type, Return Cardinality and HTTP method type.
  5. If the Return type kind is entity type, then mention the name of the entity type in the column Return Type.
  6. HTTP Method type can be of two different types. a) GET : to get the data. b ) POST: to post the data in the backend.
  7. The next step would be to save the project and generate the Runtime objects. The function import is visible in the metadata of the ODATA service.
  8. Now open the SAP Gateway client using the Transaction /n/IWFND/GW_CLIENT and mention the ODATA Service name in the metadata URI option and finally execute. The function import looks like this <Functionimport Name = “Function1″ EntitySet=” ” HTTPmethod=” ” ReturnType=” “>
  9. Function import parameters can also be inserted in the ODATA Service
  10. Implementation of Function import in the class DPC_EXT. The method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION is redefined. This method will implement the necessary functionality of the Functionimport
  11. Now the function import can be tested using the SAP Gateway client. Transaction: /n/IWFND/GW_CLIENT. The Request URI looks like /sap/opu/odata/SAP/service_name1/functionimport1?parameter1=’678cd’. Please set the HTTP Method to POST and execute the URI. The success message must appear on the HTTP response.