Implementation of SAP Odata V4 - SAP Community
Implementation of SAP Odata V4 - SAP Community
Community
sumit_joshi2
Participant
02-13-2020 12:07 PM
28 Kudos
In SAP terms, Odata a platform/framework that can be used to create SAP objects or
services that can be consumed from outside of SAP box to read or write data. A
service can be called an API that SAP provides to their consumers.
Any consumer or provider of SAP who can call REST APIs can use it. It’s OOP based,
faster, secure and having nice trace tools.
V4 is latest version of OData and its for data reduction. Size of Meta data can be
controlled in service output, enhanced paging technique. V4 is different from SEGW
project creation to DPC Ext methods, coding, service registration, URI, Json format,
debugging etc.
Odata V4 came with Code based implementation initially, with NW 750 it can be
created through SEGW.
V4 V2
We don’t have Associations same like in V2, but that can be done in a different way.
For multiple and deep structures like header and item or item and serial numbers,
define their Navigation properties:
Here navigation property of header ‘Items’ have target type entity ‘Item’ and Collection
is checked means a header can have multiple items.
Define Entity Sets and create bindings with Navigation properties created above:
There are 2 step process to register the service. If we have a separate SAP back-end
and gateway system like SAP ECC and Fiori then we’ll register the service in SAP ECC
and publish the same in SAP Fiori. If SAP gateway is in ECC, we do both steps in
ECC.
Create a service group – We can define a Service group by similar business area or
similar process area. Example – ZDIS_TRANSFER_POSTING if for all transfer postings
(MIGO) in distribution area.
By default this service bind in default service group, move it to the group we have
created:
Service is registered:
Click on Publish Service Group. Provide System Alias (Alias created for ECC->Fiori
system) and Service group name, hit Get service groups:
Service and group will be successfully imported in Gateway system. Publish the
group, lock the configuration in transport request.
Click on Metadata to display the metadata information or Service test to test the
service from SAP Gateway (/IWFND/GW_CLIENT):
Metadata:
Name Details
/IWBEP/IF_V4_DP_INTERMEDIATE
eTag handling, PATCH, $expand
Import parameters
IO_RESPONSE: to return business data to the SAP Gateway framework and to tell the
framework which processing steps the service implementation has handled itself
Example – Any get call with filterable values ‘Filter’ flag will have ‘X’.
In a Post call, todo list flags can be different. Basically it depends on type of Interface
method we redefine.
At the end of processing set Done list flags to inform Odata framework what the
implementation did.
IO_REQUEST:
GET_ENTITY_SET – Read entity set name to validate and control the flow
GET_KEY_DATA – Read key data if passed (can be used if 1-2 filterable fields in
a get call)
IO_RESPONSE:
Code lines:
io_request->get_entity_set(
IMPORTING
ev_entity_set_name = DATA(lv_entity_set_name) ).
io_request->get_busi_data(
IMPORTING
es_busi_data = li_busidata ). “li_busidata is type of entity structure
------Process on li_busidata-------
lst_done_list-busi_data = abap_true.
lst_done_list-deep_busi_data = abap_true. “If deep entity exists (Get to do list can
be checked)
io_response->set_busi_data(
EXPORTING
is_busi_data = li_busidata ). “Setting service O/P
lo_response_fnl ?= io_response.
Exception handling
Exception - /IWBEP/CX_GATEWAY
Code lines:
DATA(lo_message) = im_response->get_message_container( ).
lo_message->add_t100(
EXPORTING
iv_msg_type = <lfs_return>-type " Message Type
iv_msg_id = <lfs_return>-id " Message Class
iv_msg_number = <lfs_return>-number ). " Message Number
HTTP
Description
Code
Not Modified - the data is up to date already and does not need to be
304
sent
Bad Request - The request cannot be fulfilled due to bad syntax. -
400
Should not happen in the BEP
Forbidden - The request was a legal request, but the server is refusing to
403
respond to it
Not Found - The requested resource could not be found but may be
404
available again in the future
Method Not Allowed - A request was made of a resource using a request
405
method not supported by that resource
Not Acceptable - The requested resource is only capable of generating
406 content not acceptable according to the Accept headers sent in the
request
Conflict - Indicates that the request could not be processed because of
409
conflict in the request, such as an edit conflict
Gone - Indicates that a resources existed earlier but it’s not available
410
anymore
Precondition Failed - The server does not meet one of the preconditions
412
that the requester put on the request
Unsupported Media Type - The request entity has a media type which
415
the server or resource does not support
Precondition Required (RFC 6585) - The origin server requires the
428
request to be conditional
Server: Internal Server Error - A generic error message, given when no
500
more specific message is suitable
Server: Not Implemented - The server either does not recognize the
501
request method, or it lacks the ability to fulfill the request
Changes in URI:
V2: /sap/opu/odata/SAP/zdis_get_po/POHeaderS?
$expand=POHeaderToPOItem,POHeaderToReturnMsg&$filter=PoNumber eq
'3000000477'&$format=json
V4:
/sap/opu/odata4/sap/zdis_get_master_data/default/sap/zapi_get_plantsloc/0001/Plant
StorageLocationDetailsSet?$filter=(Plant eq '1000' or Plant eq '2000') and
CompanyCode eq 'CC01'
{
"PostingDate" : "2019-10-02", “Date format for type Edm.Date
"UserId" : "DUMMY",
"OrderNumber" : "1234567890",
"Message" : "",
"Items" : [
{
"ItemNumber" : "0001",
"ProjectNumber" : "F.01.000289",
"Plant" : "1000",
"StogareLocation" : "1100",
"Material" : "MM18",
"Quantity" : 1,
"MovementType" : "101",
"SpecialStockIndicator" : "Q",
"Batch" : "",
"ValuationType" : "",
"UnitOfMeasure" : "KG",
"Serials" : [
{
"SerialNumber" : ""
}
]
},
{
"ItemNumber" : "0002",
"ProjectNumber" : "F.01.000289",
"Plant" : "1000",
"StogareLocation" : "1100",
"Material" : "MM19",
"Quantity" : 1,
"MovementType" : "301",
"SpecialStockIndicator" : "",
"Batch" : "",
"ValuationType" : "",
"UnitOfMeasure" : "LB",
"Serials" : [
{
"SerialNumber" : ""
}
]
}
]
}
Debugging V4:
Below method calls SAP backend system from SAP Gateway system. Put one break
point here on call of backend RFC and one another on DPC EXT method that we have
implemented.
V4: /IWBEP/CL_V4_REMOTE_PROXY~CALL_BEP
Search V4 services:
Conclusion:
Odata URI can be called from consumer’s app or using tools like Postman. As it’s not
recommended to expose SAP system address and service information out, we can
use cloud based API proxy technique to add additional security. It uses industries best
authentication methods like OAuth2 or SMAL SSO, provide a platform for tracing
incoming or outgoing traffic, provide details of service performance and work as a
middle ware where we can do lookup and error handling.
Tags:
odata v4
16 Comments
andrefischer
Product and Topic Expert
02-13-2020 12:34 PM
2 Kudos
The use of SEGW when creating Odata Services is NOT recommended as described
in SAP Note 2485370
https://blogs.sap.com/2017/12/12/odata-v4-code-based-implementation-overview/
But one should be aware that the recommended odata v4 development approach in
S/4HANA is to use the ABAP Restful programming model once this will support odata
v4.
marco-silva
Participant
02-13-2020 3:41 PM
0 Kudos
Dear Andre,
Regards,
Marco
andrefischer
Product and Topic Expert
02-13-2020 4:07 PM
2 Kudos
With code based implementation you can implement everything that is supported by
the SAP Gateway OData V4 framework.
sdebeaulieu
Participant
02-13-2020 4:14 PM
1 Kudo
Thank you
former_member636171
Participant
02-26-2020 1:19 PM
0 Kudos
I'm having one problem that is I can't get the debugger to work like I could with Odata
v2. No matter where I set the external breakpoint the debugger never triggers even
though my code is running.
Best regards,
Birgir Snorrason
AbhijeetK
Active Participant
05-12-2020 10:19 AM
0 Kudos
Hi Severin,
Regards,
Abhijeet Kankani
marco-silva
Participant
05-28-2020 8:11 AM
0 Kudos
Hello,
It's too complex to implement, even not sure if it's possible with full functionality, from
my POV...
Regards,
Marco
naresh_kumar2
Explorer
09-01-2020 10:10 PM
0 Kudos
Hi Birgir,
Not sure if you got the answer, if your not then below are the steps for V4.
Class: /IWBEP/CL_V4_REMOTE_PROXY
Method: CALL_BEP
Hope it helps.
Thanks
former_member636171
Participant
09-02-2020 9:47 AM
0 Kudos
Hi Naresh,
Thanks for the reply. This sounds like what I tried originally and it didn't work for me. I
ended up using OData v2 so I never had to figure out the solution for this problem.
Best regards,
Birgir
d_enkel
Explorer
01-29-2021 2:48 PM
0 Kudos
Does anyone know where i can turn on oauth authentification for Odata4 Services?
Best regards,
Domenik
bernhard_grusie
Advisor
02-08-2021 11:56 AM
1 Kudo
Hi Domenik,
see http://help.sap.com/disclaimer?
site=https://launchpad.support.sap.com/#/notes/2322624
Best regards
Bernhard
chethansanthahalli_ningeg
Explorer
04-12-2021 6:36 PM
2 Kudos
I have created a new blog to expose CDS Views as V4 Services with Parent and Child
Relationship. Please check it.
https://blogs.sap.com/2021/04/09/sap-odata-v4-api-using-abap-restful-programming/
former_member796479
Explorer
08-02-2022 7:33 AM
0 Kudos
Hi,
For some business reasons we want to create the v4 service from segw. I tried
following the steps mentioned in the blog above but when creating Runtime artifacts
we are getting the error "Service Id already exists" for any name we enter and in all
systems it is same . I have attached the screenshot for the error below. If there is
anyway we can resolve this blocker?
Thanks,
Sanjay
sumit_joshi2
Participant
08-04-2022 2:41 AM
0 Kudos
Hi Sanjay,
Not very sure about this error, but can you check table /IWBEP/I_V4_MSRV and see if
this ZSEGW... service entry present in the table, if yes get the project and see if you
can delete it from the system if not getting used.
Regards,
Sumit
former_member657222
Explorer
10-21-2022 5:36 AM
0 Kudos
Hi Sumit,
Good Day,
Could you please let us know how did you add OAUTH to this service , since it has to
enabled while registration service , but in /iwbep/v4_admin, /iwfnd/v4_admin, we do
not see any oauth check box.
regards
Abhilash
P281512
Participant
05-18-2023 9:12 AM
0 Kudos
Hi Sumit
If one adds Odata v4 but wishes rollback to "Odata V2 only" state how to do it.
Regards
Jayanta
Comment
ABAP CDS Views - CDC (Change Data Capture) 3 ABAP Platform Trial 1
Basis Monitoring & Tcodes with Key notes 1 Best Practice 1 BTP 3
MDGM 1 Migrate your Data App 1 Migration 1 Modeling in SAP HANA Cloud 3
New Event Creation 1 PaPM Dynamic Data Copy through Writer function 1
route 1
Related Content
Mass Copy of files from old DMS Server to new DMS Server
in Technology Q&A 3 hours ago
former_member200339
Participant
jeffrey_towell2
Explorer
1001665 72 317
mstitsel
Top Kudoed Authors
Active Participant
WouterLemaire 1918
Murali_Shanmu 1916
Copyright Legal Disclosure
engswee
Trademark Newsletter 1214