cancel
Showing results for 
Search instead for 
Did you mean: 

How to consume oData Service in ABAP client?

Former Member
0 Kudos

Hello experts,

I am trying to consume oDATA service in ABAP client.

I've created a Project in SAP NWG Service Builder, maintained and activated service in SAP System 1 (SAP NWG).

I want to consume this service in other SAP System 2 (SAP ERP 6.0).

I tried searching different forums and followed the instructions but it didn't work.

Can somebody help me with this?

Thanks,

Ravi

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member184739
Contributor
0 Kudos

Hi Ravi,

Please see these blogs. These might give you some insights.

http://scn.sap.com/docs/DOC-47366

http://scn.sap.com/docs/DOC-49811

Regards

Prabaharan

Former Member
0 Kudos

Hello Prabaharan,

I've already visited these blogs, but no help. Anyways thanks.

former_member184739
Contributor
0 Kudos

Hi Ravi,

Do you have Gateway add-ons in the backend ERP system in which you are trying to consume OData service  ? Thanks

former_member184739
Contributor
0 Kudos

Hi Ravi,

If could post more details like whether Gateway addons are present in ERP system then we could help you more easier. Thanks.

former_member184739
Contributor
0 Kudos

Hi Ravi ,

This code snipped worked me to consume OData service.

REPORT Z_CONSUME_ODATA_SERVICE.

DATA: lo_http_client TYPE REF TO if_http_client,

         lv_service TYPE string,

         lv_filter TYPE string,

         lv_result TYPE string,

         lo_ixml TYPE REF TO if_ixml,

         lo_streamfactory TYPE REF TO if_ixml_stream_factory,

         lo_istream TYPE REF TO if_ixml_istream,

         lo_document TYPE REF TO if_ixml_document,

         lo_parser TYPE REF TO if_ixml_parser,

         lo_weather_element TYPE REF TO if_ixml_element,

         lo_weather_nodes TYPE REF TO if_ixml_node_list,

         lo_curr_node TYPE REF TO if_ixml_node,

         lv_value TYPE string,

         lv_node_length TYPE i,

         lv_node_index TYPE i,

         lv_node_name TYPE string,

         lv_node_value TYPE string.

lv_service = 'http://abc.com:8030/sap/opu/odata/sap/TEST_GW/ContactDetails?$filter=IvContact%20eq%20'.

lv_filter = ''''.

CONCATENATE lv_service lv_filter  INTO lv_service.

CONCATENATE lv_service '1521458603' INTO lv_service.

lv_filter = ''''.

CONCATENATE lv_service lv_filter  INTO lv_service.

cl_http_client=>create_by_url(

     EXPORTING

       url                = lv_service

     IMPORTING

       client             = lo_http_client

     EXCEPTIONS

       argument_not_found = 1

       plugin_not_active  = 2

       internal_error     = 3

       OTHERS             = 4 ).

CALL METHOD LO_HTTP_CLIENT->AUTHENTICATE(

   EXPORTING

     CLIENT = '100'

     USERNAME = 'abc'

     PASSWORD = 'abc'

     LANGUAGE = 'E'

     )

     .

   lo_http_client->send(

     EXCEPTIONS

       http_communication_failure = 1

       http_invalid_state         = 2 ).

   lo_http_client->receive(

     EXCEPTIONS

       http_communication_failure = 1

       http_invalid_state         = 2

       http_processing_failed     = 3 ).

"Prepare XML structure

   CLEAR lv_result .

   lv_result = lo_http_client->response->get_cdata( ).

   WRITE : 'Test Report to cosume OData service'.



More details in this blog .

http://scn.sap.com/community/gateway/blog/2014/03/27/consuming-an-external-restful-web-service-with-...


Also if you Netweaver release is latest one you can make use of this class to achieve the same.

CL_ODL_API


Let me know if this is useful.


Regards

Prabaharan Asokan

Former Member
0 Kudos

Thanks a lot Prabharan . Let me try this. I will update you.

former_member184739
Contributor
0 Kudos

Hi Ravi,

If your query is answered please close this thread by marking "Answered". Thanks.

former_member184739
Contributor
0 Kudos

Hi Ravi,

Did you succeed consuming the service in ABAP client ?

Prabaharan