2025 Mar 11 5:08 AM
Good morning,
I have to code some ABAP to receive data from https://smard.api.bund.dev/
For my first attemped I used the URL "https://smard.api.proxy.bund.dev/app/chart_data/1223/DE/index_hour.json"
When I use this URL in the browser I see/get |
|
I created a SM59 connection: |
|
My code is:
DATA: lo_http_client TYPE REF TO if_http_client,
lv_url TYPE string.
cl_http_client=>create_by_destination(
EXPORTING
destination = 'BUNDESNETZAGENTURSTROMMARKTDATEN'
IMPORTING
client = lo_http_client " HTTP Client object
EXCEPTIONS
argument_not_found = 1
destination_not_found = 2
destination_no_authority = 3
plugin_not_active = 4
internal_error = 5
OTHERS = 6 ).
lo_http_client->request->set_method( if_http_request=>co_request_method_post ).
lo_http_client->request->set_version( if_http_request=>co_protocol_version_1_1 ).
lv_url =
'/app/chart_data/1223/DE/index_hour.json'.
CALL METHOD cl_http_utility=>set_request_uri
EXPORTING
request = lo_http_client->request
uri = lv_url.
lo_http_client->request->set_content_type( 'application/json' ).
CALL METHOD lo_http_client->send "sending request to api
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD lo_http_client->receive "receiving response from api
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
DATA:
* http_status TYPE string,
reason TYPE string,
response TYPE string.
CALL METHOD lo_http_client->response->get_status
IMPORTING
code = data(http_status)
reason = reason.
response = lo_http_client->response->get_cdata( ).
* cl_demo_output=>display_json( json = json_response ).
cl_demo_output=>display_text( text = response ).
But my ABAP Code displays only: |
|
What I am doing wrong
2025 Mar 17 3:33 PM - edited 2025 Mar 17 3:33 PM
2025 Mar 19 5:57 AM
Hi M-K,
thx for the reply. But this did not solve the issue 😞
thanks regards,
Mario
a month ago
I would try to use method get_data instead of get_cdata on line 51.
3 weeks ago
Hi Ulrich,
many thanks. Looks much better but not 100% 🙂
But when I put the URL
https://smard.api.proxy.bund.dev/app/chart_data/1223/DE/index_hour.json
in the Browser I get:
What am I doing wrong?
thanks regards,
Mario
3 weeks ago
The data you get from get_cdata is binary data. You have to translate it into your program internal data.
First you can translate it into readable data to see that you have the right data, for instance using method CL_BINARY_CONVERT=>XSTRING_UTF8_TO_STRING.
You can map the binary data using "CALL TRANSFORMATION" to program internal data. Maybe a "Simple Transformation" does the job for you (https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenabap_st.htm).
Or use the sXML library to analyze the data (https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenabap_sxml_lib.htm).
There may be other ways to analyze the json data.