Odata includes standard CRUD operations that map to http methods GET,POST,PUT/MERGE,DELETE. In addition to these OData support another operation which is called function imports which can be invoked by http GET or POST methods.
Function import creations are easy.Dont go for a function import if the standard CRUD methods can fulfill your requirement.Some examples when we need a function import are given below
- Confirm Workitem
- Check Flight availability
In this tutorial we will create a function import for knowing a particulat flight fare.
Pre-requisites
Steps
- Go to tcode SEGW.Open our project ZTEST_ODATA we created already.Click on the project and go to edit mode.Expand project node and right click on Data Model node and select Create->Function Import.This will open up Function Import creation window.
- Give the function import name and click okay(tick) button.I have given CheckFlightFare as function import name.
- Now a new node name Function Imports will be created under Data Model node of our project.See screenshots.
- For each function import we can define return kind.Three return kinds supported are Complex type,Entity type and No return.In this function import we need to return some data so that we need to create an entity type and entityset for this.So again right click on Data Model and select Create->Entity Type.
- Entity creation window will open.Give Entity type name.check Create Related Entity Set checkbox and give entityset name.Click okay.
- Open created FlightFare entity type and create two properties called Fare and Currency.Give type as Edm.string.Dont forget to set any or both of these properties as keys otherwise while generating it will throw error.Check and generate the project.
- Now open our Function Import CheckFlightFare by clicking on it.Select return kind as Entity type and select Return type as our newly created FlightFare entity type.select Return Cardinality as 1.Return cardinality specify how many of return type can occur in result.Supported values are 0..1,1,0..n,1..n.Select return http method as GET.You can choose POST also according to requirements.
- Expand FlightFare function import node and double click on Function Import Parameters.We will add three import parameters which are flightdate,connectionid and carrierid.For flightdate type is Edm.DateTime and for others Edm.String.Check and Generate the project.
- Time for some coding.Open our ***DPC_EXT class and right click on EXECUTE_ACTION and click Redefine.
- Put below code inside the method.Here we access the function import parametes and return the Flight fare based on the query result.Activate the method.
- Function import implementation is finished.To check open gateway client (/IWFND/GW_CLIENT)and give Url : /sap/opu/odata/SAP/ZTEST_ODATA_SRV_01/CheckFlightFare?carrierid='AC'&connectionid='820'&flightdate=datetime'2002-12-20T00:00:00' and press execute button.See screenshot.
DATA: ls_parameter TYPE / iwbep / s_mgw_name_value_pair, ls_entity type zcl_ztest_odata_01_mpc => ts_flightfare, lv_carrier TYPE zcl_ztest_odata_01_mpc => ts_flight - carrid, lv_connection TYPE zcl_ztest_odata_01_mpc => ts_flightschedule - connid, lv_fldate TYPE dats. IF it_parameter IS NOT INITIAL. DATA: BEGIN OF str_fare, price type sflight - price, currency type sflight - currency, END OF str_fare. READ TABLE it_parameter INTO ls_parameter WITH KEY name = 'carrierid'. IF sy - subrc = 0. lv_carrier = ls_parameter - value. ENDIF. READ TABLE it_parameter INTO ls_parameter WITH KEY name = 'connectionid'. IF sy - subrc = 0. lv_connection = ls_parameter - value. ENDIF. READ TABLE it_parameter INTO ls_parameter WITH KEY name = 'flightdate'. IF sy - subrc = 0. lv_fldate = ls_parameter - value. ENDIF. ENDIF. case iv_action_name. when 'CheckFlightFare'. SELECT single price currency from sflight into str_fare where carrid = lv_carrier and connid = lv_connection and fldate = lv_fldate . ls_entity - fare = str_fare - price. ls_entity - currency = str_fare - currency. endcase. copy_data_to_ref(EXPORTING is_data = ls_entity CHANGING cr_data = er_data).
If you enjoyed this post, Please Share!!
I have a 500 Internal server error and when i see the log it say:
ReplyDeleteException of type /IWCOR/CX_DS_INTERNAL_ERROR has occurred. See details for more information
Message no. /IWFND/CM_LOGGING006
can you help me?
debug your code inserting an external breakpoint,debugging gateway service
Deletethere are few corrections needed in the code ( 1. Ls_entity should be appended to LT_entity and the table should be passed to IS_data of the last method call . Then the O/P will be displayed . Rest all is correct and thank you for sharing the knowledge
ReplyDeleteThanks for the useful Information
DeleteGoood post
ReplyDelete6892B3EA5B
ReplyDeletetelegram görüntülü şov
fx15
vigrande
themra macun
viagra
bufalo çikolata
geciktirici
skype şov
ücretli show
6F478BA68F
ReplyDeletebufalo çikolata
degra
whatsapp ücretli show
themra macun
görüntülü şov
performans arttırıcı
stag
lady era
kaldırıcı
A468097C1C
ReplyDeletesertleştirici
görüntülü şov whatsapp numarası
viga
stag
viagra
görüntülü şov
vigrande
lady era hap
whatsapp görüntülü show güvenilir
A70F01D680
ReplyDeletesertleştirici
cobra vega
novagra hap
bufalo çikolata
skype şov
ereksiyon hapı
telegram show
görüntülü şov whatsapp numarası
yapay kızlık zarı
5F98CEE798
ReplyDeletebayan azdırıcı damla
ereksiyon hapı
cobra vega
skype show
cam şov
vigrande
görüntülü şov whatsapp numarası
canli web cam show
kamagra hap
C935AF3159
ReplyDeleteyoutube türk beğeni satın al
D65214111F
ReplyDeletetwitter ucuz beğeni