0% found this document useful (0 votes)
101 views18 pages

Create OData Service in SAP Fiori Server, Register

Uploaded by

gagamel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views18 pages

Create OData Service in SAP Fiori Server, Register

Uploaded by

gagamel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Dilip Kumar Krishnadev Pandey

November 19, 2017 4 minute read

Create OData Service in SAP Fiori


Server
131556,538

Overview
 SAP Fiori apps use OData to display and update data in back-end server (SAP
or Non-SAP).
 OData (Open Data Protocol) is a standardized protocol for creating and
consuming data APIs.
 OData builds on core protocols like HTTP and commonly accepted
methodologies like REST.
 Odata supports message formats like JSON, XML.
 OData provides definitions for:
o Simple Types
o Complex Types
o Associations between entries
o Navigation Paths between entries
o Custom behavior (known as function imports) beyond the standard
QUERY, CREATE, READ, UPDATE, DELETE (QCRUD) operations
 Here we see how to create a Odata-Service which consumes RFC of SAP-R3
(Back-end) server.
 This is a example of business scenario where we need to display/update data
of SAP-R3 (Back-end) server in SAP UI5 Application.
 SAP UI5 Applcation consumes Odata-Service which in-turn consumes RFC of
SAP-R3.
 This blog is part of below parent blog:
o SAP Fiori – Custom App Implementation

Steps to create OData service (which


consumes RFC):
This is example to consume RFC in OData-Service.

RFC of SAP-R3 (backen-end) Server:

 Functionality of RFC is like, on invoke, it returns MARA table details.


 RFC has one output table structure ‘TBL_MARA‘, in which 10 records will be
fetched on execution

 below is RFC code to fetch 10 records from mara table


 This RFC will be consumed in OdataService of SAP-Fiori.

Steps to Create OData Service:


1. Pre-requisites:
 RFC of SAP-R3 (back-end) system
 In SAP-Fiori (front-end) system:
o One RFC-Destination connecting to SAP-R3 (back-end) System
o T-code ‘SEGW’
2. Go-to t-code ‘SEGW’ -> click on icon ‘Create Project’

3. Enter details as shown in screen


4. Click ‘ok’ icon, OData project gets created

5. Now we need to create a “Entity-Type” which is meta structure to hold RFC
table output
 Select ‘Entity-Types’ -> right click -. ‘Create’


 Enter names as per input.
 here ‘Entity Type’ is like Data Type and ‘Entity Set’ is like variable of
Data Type.
 With ‘Entity Set’ name we consume ODataService in UI5 App

 Click ‘Ok’ icon


 Now, add column (property) in ‘Entity Type’
 Double Click on Properties -> In center panel click on ‘Append Row’
icon to add new elements

 For example purpose, we need only two column details Material
Number and its Type, then create two elements
 And mark ‘Material’ as a key element

 Now Save and click on icon ‘Generate Runtime Objects’,

 Click ok in next pop-up


 Enter package details


 as a success below screen should appear

6. Redefine EntitySet method to consume RFC


 Once Meta structure is been defined, next is to consume RFC
 For that go to ‘Service Implementation’ -> ‘*_DPC_EXT‘
 ‘_DPC_EXT‘ has method ‘_GET_EntitySet‘ which we need to Re-
Define, for same we can follow below screen
 Once method gets re-defined, we can see it in folder Redefinitions.

 Now in ‘_GET_EntitySet’ method we need to do some ABAP Code logic


o When SAP UI5 Application calls this OdataService with this
EntitySet name i.e. ‘MateriallistSet’, GET_ENTITYSET method
gets invoked.
o Here we can write logic to call RFC of SAP-R3 (Back-end) server.
o RFC returns output in table format, which we need to map
structure of OData-Entity-Type ‘Materiallist’
o Below code can be written for same:

o method MATERIALLISTSET_GET_ENTITYSET.
o
o * Structure for RFC's mara table data
o TYPES:
o BEGIN OF ZMARA,
o MATNR TYPE C LENGTH 21,
o MTART TYPE C LENGTH 4,
o END OF ZMARA.
o
o DATA: IT_MARA TYPE TABLE OF ZMARA, "internal
table to store RFC result
o wA_MARA TYPE ZMARA, "work area
for single RFC result
o WA_ENTITY TYPE
ZCL_ZTEST_ODATA_MPC=>TS_MATERIALLIST. "work area for
Odata Entity 'MaterialList'
o
o * Calling SAR-R3 (Back-Ens) server RFC
o Call FUNCTION 'ZTEST_RFC_FIORI' DESTINATION
'rfcDestinationName'
o TABLES
o TBL_MARA = IT_MARA.
o
o * Return RFC output to Odata Entity output
'MaterialList'
o IF SY-SUBRC = 0.
o *if VALUE FOUND, then map output to Odata Entiy
'MaterialList'
o LOOP AT IT_MARA INTO WA_MARA.
o CLEAR WA_ENTITY.
o WA_ENTITY-MATERIAL = WA_MARA-MATNR.
o WA_ENTITY-MTYPE = WA_MARA-MTART.
o APPEND WA_ENTITY TO ET_ENTITYSET. "Append output
to Odata Entiy 'MaterialList'
o CLEAR WA_MARA.
o ENDLOOP.
o ENDIF.
o endmethod.

o
 Now activate the ‘GET_ENTITYSET‘ method and ‘_DPC_EXT‘.
7. Thus, a OData Service has been created, which consumes RFC of back-end
system.
8. Now next is to register the Service for same, we can follow below link:
 Register OData Service in SAP Fiori Server
9. Once service gets registered, it can be consumed in SAP UI5 Application for
display/upload of back-end data.
10. We can test this ODataService in SAP-Fiori (front-End):
 t-code /n/iwfnd/gw_client
 url
/sap/opu/odata/sap/ZTEST_ODATA_SRV/MaterialListSet
 Descritpion To get RFC detals via EntitySet ‘MaterialListSet’
 Test screen:

11. Thus we have developed one OData Service in SAP-Fiori which consumes RFC
of SAP-R3.
Register OData Service in SAP Fiori
Server
2746,360
Overview
 Here we see the process to activate and register custom Odata Service in
SAP-Fiori (Front-End) server.
 Odata Service ‘ZTEST_ODATA’ is been created/defined in t-code ‘SEGW’ of
SAP-Fiori, as can be seen in below screen:

o
 This blog is part of below parent blog:
o SAP Fiori – Custom App Implementation

Steps to Activate/Register OData Service:


[1] System Alias Maintainance
We can configure ‘system alias‘ Alias using below details:
 T-Code SPRO
 Path ‘SAP Reference IMG’ -> SAP Customizing Implementation Guide ->
SAP NetWeaver -> SAP Gateway -> OData Channel -> Configuration ->
Connection Settings -> SAP Gateway to SAP System -> Manage SAP System
Aliases
In SAP-Fiori (Front-End) System, we need to configure two ‘system alias‘ Alias:
1. System Alias for SAP-Fiori (Front-End) System: ‘Local’
 Local System alias is required to refer objects of same system
 Below settings needs to be configured in ‘Manage SAP System Aliases’
window
 Here check boxes ‘Local GW‘ & ‘For Local App‘ should be checked.
2. System Alias for SAP-ECC (Back-End) System
 This system alias is required to refer objects of for SAP-ECC (Back-End)
System
 Below settings needs to be configured in ‘Manage SAP System Aliases’
window

 Enter RFC-Destination and check boxes ‘Local GW‘ & ‘For Local App‘
should be un-checked.
 RFC-Destination should have enabled ‘Current-User’ logon settings

[2] Activate ICF node of OData Service


 In SAP-Fiori (fron-end server) use following details:
o T-Code ‘SICF’
o Path ‘/default_host/sap/opu/odata/sap/’
o service ZTEST_ODATA
o steps right click -> select ‘Activate’
 This ICF node can be activated during service registration also.
[3] Register OData Service
 To register Odata service for accessibility in UI5 application, In SAP-Fiori (fron-
end server) use following details:
o T-Code ‘/n/iwfnd/maint_service’
 Opened windows shows list of registered services
 Click on button ‘Add Service’ to proceed with new service registrations


 In next window, to get un-registered service list of same fiori system,
 select System Alias ‘Local’ -> click on button ‘Get Services’

 From the unregistered service list, select desired service


 and click on button ‘Add Selected Service’
 In appear pop-up click select input detaisl as shown in below scree and here
enter your desired package, for example purpose $TMP

 Click ok in next pop-up



 Once service gets registered, we can view it in t-code ‘/n/iwfnd/maint_service’
within registered list

 For testing the service, either select service as in above screen and click on
button ‘SAP Gatway Client’ or go to t-code ‘/n/iwfnd/gw_client’
 Please note:
o Post registration of Odata Service, its name gets a postFix like “_SRV“,
for e.g. in our case, Odata-Service gets registered with name
‘ZTEST_ODATA_SRV’
o And service definition name is ‘ZTEST_ODATA’
[4] Test OData Service
 For testing registerd OdataService, in SAP-Fiori (fron-end server) use following
details:
o T-Code ‘/n/iwfnd/gw_client’
 Enter Service url patterns like:
o To check Service registration Status, try service url as below
o /sap/opu/odata/sap/ZTEST_ODATA_SRV/?$format=xml
o To get complete metadata structure of OData Service, try service url as
below
o /sap/opu/odata/sap/ZTEST_ODATA_SRV/$metadata

 Status Code ‘200’ and reason ‘OK’ with green color response layout
represents everything is ok.
[5] Error Log Monitoring
 To view error logs OdataService in SAP-Fiori (fron-end server), go to T-Code
‘/n/iwfnd/error_log’
 Here we can identify root cause and possible action also been suggested in
case of standard error

You might also like