Developing OData ABAP Service using Get_Entity( ) Method :
================================================
========
Get_Entity( ) Method is used to Fetch Single Record with Select Statement
Get_Entity( ) Method contain Two Important Parameters
it_Key_Tab : Will Accept Input Key Field Value(s) from Front-end App(SAP
Ui5/Fiori)
er_Entity : Will Send Output Record to Front-end App(SAP Ui5/Fiori)
Get_Entity( ) Method is Recommended if Front-end App(SAP Ui5/Fiori ) Contains
Form As Input
Form As Output
Get_Entity( ) Method is Triggered from Front-end App using bindElement( )
method
_______________________________________________________________________
Note : we can use Standard Structure for Declaring WorkArea for Key Fields
/IWBEP/S_MGW_NAME_VALUE_PAIR
Note : /IWBEP/S_MGW_NAME_VALUE_PAIR contains Two options
Name -> Name of Key Field
Value -> Value of Key Field
_________________________________________________________________________
Step by Step Procedure :
_______________________________
step1 : Create OData Service Project
-----------------------------------------------------------
open SEGW Tcode
click create Icon
Provide Project Name = ZTest630AMODataProject
Description = CRUDQ ODataProject
save in package/local
step2 : Create Entity Type and EntitySet
-----------------------------------------------------------------
Right Click DataModel -> Import -> DDIC Structure
Provide Entity Type = EMP
ABAP Structure = ZEMPDBTABLE ( Database Table )
Select CheckBox to Create EntitySet ( EMPSet )
Next
Select All Fields
Next
Select Key Fields ( Userid , Firstname )
Finish
step3 : Generate Runtime Artifacts :
--------------------------------------------------------------
Select Your Project Folder -> Click on Red Color Icon
Continue
Save in Package/local
step4 : Implement Functionality :
-----------------------------------------------------------------
open Runtime Artifacts
open Data Provider Extension Class ( DPC_EXT )
Click Change
Place Cursor on EMPSet_Get_Entity( ) Method
Click on "Redefine Method"
implement below Code
______________________________________________________
Data : Wa_Key_tab1 TYPE /iwbep/s_mgw_name_value_pair.
Data : Wa_Key_tab2 Type /iwbep/s_mgw_name_value_pair.
Read Table it_key_tab into wa_key_tab1 index 1.
Read Table it_key_tab into wa_key_tab2 index 2.
Select Single * from ZEMPDBTABLE
into
CORRESPONDING FIELDS OF er_entity
Where Userid = wa_key_tab1-value
and
Firstname = wa_key_tab2-value.
______________________________________________________
save And Activate
step5 : Register the Service
------------------------------------------------------
open Service maintainence Folder
Click on "Register"
continue
save in package/local
Finish
Note : The Odata Service will be internally Registered in SAP Netweaver
Gateway
& The Odata Service will be Activated in SICF Tcode Automatically
Step6 : Test the OData Service
--------------------------------------------------
open Service maintainence Folder
Goto SAP Gateway Client
Select EntitySets ( EMPSet )
To Fetch Record :
____________________
/sap/opu/odata/SAP/ZTEST630AMODATAPROJECT_SRV/
EMPSet(Userid='1001',Firstname='VIJAYENDAR')
Select "Get" option & Execute the Service
/sap/opu/odata/SAP/ZTEST630AMODATAPROJECT_SRV/
EMPSet(Userid='1002',Firstname='AJAY')
Select "Get" option & Execute the Service
/sap/opu/odata/SAP/ZTEST630AMODATAPROJECT_SRV/
EMPSet(Userid='1003',Firstname='VARUN')
Select "Get" option & Execute the Service
__________________________________________________________________________________
_____________