0% found this document useful (0 votes)
4 views3 pages

SAP ABAP REST API Data Handling

The document outlines a report for consuming a REST API using ABAP, detailing the structure of data types and the steps involved in making an HTTP request. It includes creating an HTTP client, sending a request, receiving a response, and processing JSON data. The final output is intended to be displayed in an HTML format using the ABAP browser.

Uploaded by

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

SAP ABAP REST API Data Handling

The document outlines a report for consuming a REST API using ABAP, detailing the structure of data types and the steps involved in making an HTTP request. It includes creating an HTTP client, sending a request, receiving a response, and processing JSON data. The final output is intended to be displayed in an HTML format using the ABAP browser.

Uploaded by

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

REPORT zdemo rest_api_consumption.

DATA:1v_url TYPE string.


TYPES:BEGIN OF ty_data,
user_name TYPE string,
first name TYPE string,
last name TYPE string,
middle name TYPE string,
gender TYPE string,
age TYPE string,
emails TYPE string,
favorite feature TYPE string,
features TYPE string,
addressinfo TYPE string,
homeaddress TYPE string,
END OF ty_data.
DATA:It_output TYPE TABLE OF ty_data.

DATA:1v_url TYPE string.


lv_url="http:// [Link]/users'.

"Step1

cl_http_client->create_by_url(
EXPORTING
url
IMPORTING
client
EXCEPTIONS
argument_not_found
plugin_not_active
internal_error
OTHERS
sy-subre-0.
"Step2
lo_http->send(
EXPORTING
timeout
EXCEPTIONS
.lv_url
-DATA(lo_http)
OTHERS
1
2
3
http_communication failure
http_invalid_state
http_processing failed
http_invalid_timeout
-15
-2
-3
<-4
IF sy-subrc<>8.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

"Step3

lo_http->receive(
EXCEPTIONS
http_communication
http_invalid_state
failure1
-2
http_processing failed -3
OTHERS
).
IF sy-subre8.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
"Step4
DATA(result)lo_http->response->get_cdata().
"Step5
cl_abap_browser->show_html(
EXPORTING
title
).
-"SAPYARD Rest API Training"
html_string-result
ENDIF.

"Step5
cl_abap_browserw>show_html(
EXPORTING
title
htel string result
-)..
).

SPLIT result AT[INTO DATA(lv_string1)DATA(lv_string2).


lv_string2 =|{ '[' && lv_string2 }|.
DATA(lv_final_string) = substring(val=lv_string2 off=0 len=strlen(lv_string2)-1).
|

Step6
/ui2/cl_json->deserialize(
EXPORTING
json - lv_final_string

pretty_name - /ui2/cl_json->pretty_mode-camel_case

*SAPYARD Rest API Training


CHANGING
data - lt_output
).

You might also like