In ABAP Make an API HTTP Request. / ABAP HTTP Request

Photo by Barn Images on Unsplash
DATA: lv_http_dest TYPE rfcdest VALUE 'SAP_SCPI_ConEmp'.
DATA: o_client TYPE REF TO if_http_client.
TRY.
cl_http_client=>create_by_destination(
EXPORTING destination = lv_http_dest
IMPORTING client = o_client).
o_client->request->set_method( if_http_request=>co_request_method_post ).
o_client->send( ).
o_client->receive( ).
o_client->response->get_status( IMPORTING
code = lv_http_rc
reason = lv_reason ).
IF lv_http_rc = 200.
DATA(lv_json) = o_client->response->get_cdata( ).
WRITE lv_json.
ELSE.
WRITE: / 'Error: ', lv_http_rc.
ENDIF.
o_client->close( ).
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.

The other Method(HACK)!:

DATA(lv_url) = |https://www.google.de/|.
DATA: o_client TYPE REF TO if_http_client.
TRY.
cl_http_client=>create_by_destination(
EXPORTING url = lv_url
IMPORTING client = o_client).
o_client->request->set_method( if_http_request=>co_request_method_post ).
o_client->send( ).
o_client->receive( ).
o_client->response->get_status( IMPORTING
code = lv_http_rc
reason = lv_reason ).
IF lv_http_rc = 200.
DATA(lv_json) = o_client->response->get_cdata( ).
WRITE lv_json.
ELSE.
WRITE: / 'Error: ', lv_http_rc.
ENDIF.
o_client->close( ).
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.

--

--

--

If you like my work or have question contact me.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Git Flow: Develop Code With Others using Git

How to Outsource Software Development [for Founders] | SpdLoad

Functional and Nonfunctional Requirements: Specification and Types

Dependency Injection in Golang

NFTs have an Accessibility Problem

How to build Jenkins automation server from a docker image

What Is Snowflake Database — Guide for 2022

C# 9.0 The Main New Features Explained in Less Than 5 Minutes

C# 9.0 comes with very interesting new features like record type, top-level statements and so on.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Walter-Tscharf-Development

Walter-Tscharf-Development

If you like my work or have question contact me.

More from Medium

How to Create Your Certificate and Use It With Postman

Integrate User Login to Your WordPress Website with WSO2 Identity Server

Application Programming Interface