I have in my ABAP program an internal table with several rows of data. I loop over the table and call the same BSP page for each entry. The goal is to read the data of each line in HTML format and then download it as an HTML file.
Problem is:
the first call (first run) works perfectly and returns HTML text, but on next calls (next data lines) the method http_client->response->get_cdata( )
does not return any data, even though everything ran without errors (response status = 200).
Two more points:
http_client
instance is created outside the loop (call method cl_http_client=>create_internal()
), but unfortunately it didn't work either.Thanks in advance.
Here is the call logic:
loop at it_data .....
......
......
CALL METHOD cl_http_ext_webapp=>create_url_for_bsp_application
EXPORTING
bsp_application = iv_app
bsp_start_page = iv_page
bsp_start_parameters = lt_params
IMPORTING
abs_url = lv_url.
* Create internal http client
CALL METHOD cl_http_client=>create_internal
IMPORTING
client = lr_http_client
EXCEPTIONS
plugin_not_active = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
ev_error = abap_true.
RETURN.
ENDIF.
cl_http_utility=>set_request_uri( request = lr_http_client->request
uri = lv_url ).
lr_http_client->request->set_header_field( name = '~request_method'
value = 'GET' ).
* Send and recieve
lr_http_client->send(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5
).
IF sy-subrc = 0.
lr_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4
).
ENDIF.
IF sy-subrc <> 0.
CALL METHOD lr_http_client->get_last_error
IMPORTING
code = lv_rc
message = lv_message.
ev_error = abap_true.
RETURN.
ENDIF.
lr_http_client->response->get_status( IMPORTING code = lv_rc
reason = lv_reason ).
IF lv_rc = 200.
ev_html = lr_http_client->response->get_cdata( ).
ELSE.
ev_error = abap_true.
RETURN.
ENDIF.
lr_http_client->close( ).
endloop.
Thanks for your help.
The error lies in the BSP app Settings. I solved it as follows: 1- BSP application properties -> set as stateful. 2- BSP page Properties->Lifetime changed to 'Request'. (this determines how long the instance of the page/controller will be retained.)
It worked properly now.