API: return response as HTML table
想要把response table变成HTML的table,即想达到下面这种的话
Customer | Date | Debit Amount | Payment Amount | Remain Balance |
---|---|---|---|---|
40000446 | 20250501 | 17227.80 | 0.00 | 17227.80 |
40000446 | 20250515 | 54.52 | 0.00 | 54.52 |
可以这样子开发:
METHOD if_http_extension~handle_request.
DATA: lv_jsonbody TYPE string,
lv_xstring TYPE xstring,
lv_html_string TYPE string.
\"get Request Body: JSON->ABAP
lv_jsonbody = server->request->get_cdata( ).
CALL METHOD /ui2/cl_json=>deserialize
EXPORTING
json = lv_jsonbody
pretty_name = /ui2/cl_json=>pretty_mode-none
assoc_arrays = abap_true
CHANGING
data = ms_req.
**********************************************************************
CALL METHOD me->pre_requisition.
CALL METHOD me->business_logic.
**********************************************************************
lv_html_string = \'
Customer | Date | Debit Amount | Payment Amount | Remain Balance |
---|---|---|---|---|
\' && -customer && \' | \' && -date && \' | \' && -debit_amount && \' | \' && -payment_amount && \' | \' && -remain_balance && \' |
\'.
**********************************************************************
CALL METHOD server->response->set_content_type( if_rest_media_type=>gc_text_html ).
CALL METHOD server->response->set_cdata(
EXPORTING
data = lv_html_string ).
CALL METHOD server->response->set_status(
EXPORTING
code = 201
reason = \'Executed\' ).
ENDMETHOD.