In below program I have used SAP_CONVERT_TO_XLS_FORMAT function module to convert internal table data to excel file and save file to user computer.
Code :
DATA: LV_MATNR TYPE MARA-MATNR.
SELECT-OPTIONS: S_MATNR FOR LV_MATNR.
START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE @DATA(IT_MARA) WHERE matnr IN @S_MATNR.
IF sy-subrc eq 0.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = '#'
I_LINE_HEADER = 'X'
i_filename =
'C:\Users\CODETHETA\Desktop\xyz.xls'
I_APPL_KEEP = ' '
tables
i_tab_sap_data = IT_MARA
* CHANGING
* I_TAB_CONVERTED_DATA =
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF sy-subrc <> 0.
write:/ 'error'.
ENDIF.
IF sy-subrc eq 0.
write:/ 'created'.
ENDIF.
ENDIF.
SELECT-OPTIONS: S_MATNR FOR LV_MATNR.
START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE @DATA(IT_MARA) WHERE matnr IN @S_MATNR.
IF sy-subrc eq 0.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = '#'
I_LINE_HEADER = 'X'
i_filename =
'C:\Users\CODETHETA\Desktop\xyz.xls'
I_APPL_KEEP = ' '
tables
i_tab_sap_data = IT_MARA
* CHANGING
* I_TAB_CONVERTED_DATA =
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF sy-subrc <> 0.
write:/ 'error'.
ENDIF.
IF sy-subrc eq 0.
write:/ 'created'.
ENDIF.
ENDIF.
Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us. We will reply you as soon as possible.
Post a Comment