on 08-26-2022 7:30 AM
Hi Experts,
When I click the button in my application OData service should call and download the excel file directly.
Please help me. Thanks in advance.
Thanks & Regards
Srinivas Raju
Try below,
method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM.
*Method 3
DATA: t_t100 TYPE STANDARD TABLE OF t100.
DATA: lv_xml TYPE STRING.
DATA: lo_xml_doc TYPE REF TO cl_xml_document.
TYPES: BEGIN OF TY_DATA,
CARRID TYPE S_CARR_ID,
CONNID TYPE S_CONN_ID,
FLDATE TYPE S_DATE,
PRICE TYPE S_PRICE,
PLANETYPE TYPE S_PLANETYE,
END OF TY_DATA.
DATA: GT_DATA TYPE STANDARD TABLE OF TY_DATA.
DATA: gv_xmlstr TYPE STRING.
*SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE GT_DATA.
CALL TRANSFORMATION ZEXCEL_SFLIGHT
SOURCE TABLE = GT_DATA
VAR = 'Testing Variable'
RESULT XML gv_xmlstr.
DATA: ls_stream TYPE ty_s_media_resource,
lv_data_string TYPE string,
lv_xstring TYPE xstring,
ls_header TYPE ihttpnvp,
lt_fields TYPE STANDARD TABLE OF dfies.
create object lo_xml_doc.
lo_xml_doc->parse_string( gv_xmlstr ).
lo_xml_doc->export_to_file( 'C:\text_output.xls' ).
** Convert String to xstring
CALL FUNCTION 'TREX_TEXT_TO_XSTRING'
EXPORTING
text = gv_xmlstr
IMPORTING
BUFFER = lv_xstring
EXCEPTIONS
CONVERSION_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* Pass back stream values
ls_stream-value = lv_xstring.
ls_stream-mime_type = 'application/msexcel'.
* Set Header for Response
DATA(lv_filename) = |{ 'IHS' }-{ sy-datum }-{ sy-uzeit }.xls|.
lv_filename = escape( val = lv_filename format = cl_abap_format=>e_url ).
ls_header-name = 'Content-Disposition'.
ls_header-value = |outline; filename="{ lv_filename }"|.
me->set_header( ls_header ).
copy_data_to_ref(
EXPORTING is_data = ls_stream
CHANGING cr_data = er_stream ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.