Convert internal table to excel format in SAP ABAP | MS_EXCEL_OLE_STANDARD_DAT | Internal table to excel SAP ABAP program example

Convert internal table to excel format in SAP ABAP| MS_EXCEL_OLE_STANDARD_DAT| Internal table to excel SAP ABAP program example | convert internal table to excel in sap abap

Dear Readers, In this article we are going to see how to convert internal table into excel format using SAP ABAP program or using SAP ABAP Function Module MS_EXCEL_OLE_STANDARD_DAT. Sometime we required to transfer our internal table data to excel sheet for some verification or any other kind of work like creating a mail using abap program with excel attachment.

Convert internal table to excel format in SAP ABAP

MS_EXCEL_OLE_STANDARD_DAT

MS_EXCEL_OLE_STANDARD_DAT is the function module which will convert our internal table into excel format. In this function code we will Importing FILE_NAME object from our program which is excel file location where excel file will be saved. In tables data DATA_TAB which is internal table and FIELDNAMES which is header data of internal table.

IMPORTING
FILE_NAME: Path of file where you want to download.
TABLES
DATA_TAB:  Internal table.
FIELDNAMES: Header data of internal table or Header data of fields.
MS_EXCEL_OLE_STANDARD_DAT

Convert internal table to excel format in SAP ABAP

To convert internal table to excel format in SAP ABAP we will use the “MS_EXCEL_OLE_STANDARD_DAT” function module or call this function module in our program like showing in below picture.

Convert internal table to excel format in SAP ABAP

Internal table to excel SAP ABAP program example

REPORT ZPS_JW_PRINT.

TYPES: BEGIN OF TY_HEAD,
         MAT(20)  TYPE C,
         DATE(20) TYPE C,
         NAME(20) TYPE C,
       END OF TY_HEAD.

DATA: P_FILENAME TYPE RLGRAP-FILENAME,
      IT_HEAD    TYPE TABLE OF TY_HEAD WITH HEADER LINE.

IT_HEAD-MAT = 'material number'.
IT_HEAD-DATE = 'Created Date'.
IT_HEAD-NAME = 'Created By'.
APPEND IT_HEAD.
CLEAR IT_HEAD.



SELECT MATNR, ERSDA, ERNAM FROM MARA UP TO 10 ROWS INTO TABLE @DATA(IT_FINAL).


P_FILENAME = 'C:\Users\Desktop\abcde'.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
  EXPORTING
    FILE_NAME                 = P_FILENAME
*   CREATE_PIVOT              = 0
*   DATA_SHEET_NAME           = ' '
*   PIVOT_SHEET_NAME          = ' '
*   PASSWORD                  = ' '
*   PASSWORD_OPTION           = 0
  TABLES
*   PIVOT_FIELD_TAB           =
    DATA_TAB                  = IT_FINAL
    FIELDNAMES                = IT_HEAD
  EXCEPTIONS
    FILE_NOT_EXIST            = 1
    FILENAME_EXPECTED         = 2
    COMMUNICATION_ERROR       = 3
    OLE_OBJECT_METHOD_ERROR   = 4
    OLE_OBJECT_PROPERTY_ERROR = 5
    INVALID_PIVOT_FIELDS      = 6
    DOWNLOAD_PROBLEM          = 7
    OTHERS                    = 8.
IF SY-SUBRC <> 0.
  MESSAGE 'check' TYPE 'E'.
ENDIF.

In SAP ABAP so many other function module is available to convert our internal table into excel and download the same in our system.

SAP_CONVERT_TO_XLS_FORMAT


DATA: P_FILENAME TYPE RLGRAP-FILENAME,



SELECT MATNR, ERSDA, ERNAM FROM MARA UP TO 10 ROWS INTO TABLE @DATA(IT_FINAL).
  P_FILENAME = 'C:\Users\Desktop\abcde'.
  
  CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
    EXPORTING
     I_FIELD_SEPERATOR          = '#'
     I_LINE_HEADER              = 'X'
      I_FILENAME                 = p_filename
*     I_APPL_KEEP                = ' '
    TABLES
      I_TAB_SAP_DATA             = it_final
*   CHANGING
*     I_TAB_CONVERTED_DATA       =
*   EXCEPTIONS
*     CONVERSION_FAILED          = 1
*     OTHERS                     = 2
            .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

BAPI_PO_CREATE1

Cell Color in ABAP ALV Grid Report

CONTROL BREAK STATEMENTS IN SAP ABAP

For the next blog please connect with us and follow us on twitter.com/einfonett

%d bloggers like this: