F How to transfer internal table data to excel file using SAP_CONVERT_TO_XLS_FORMAT in SAP ABAP | CodeTheta

How to transfer internal table data to excel file using SAP_CONVERT_TO_XLS_FORMAT in SAP ABAP

October 24, 2023

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 :

DATALV_MATNR TYPE MARA-MATNR.

SELECT-OPTIONSS_MATNR FOR LV_MATNR.

START-OF-SELECTION.
SELECT FROM MARA INTO TABLE @DATA(IT_MARAWHERE 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.

IDE Used To Test This Code : SAP ABAP Editor.

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