Skip to Content
author's profile photo Former Member
Former Member

Download data to excel sheet

Hi experts,

I am facing this problem :

I have an internal table, and i want to download the data of this internal table in a excel sheet. This downloading has to be done through ABAP code.

How can i do this task, kindly help me out.

Thanks in advance

Regards

MA

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 11:21 AM

    using GUI_download u can download into excel format

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 11:23 AM

    Hi mayank,

    Use FM GUI_DOWNLOAD with parameter -- field_separator = 'X'.

    Give file extension as .xls

    you may also use other FM like SAP_CONVERT_TO_XLS_FORMAT.

    Regards,

    Mohaiyuddin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 11:24 AM

    Check the following code:

    REPORT ztablexls.
    ********************************************************************
    * Developer        : S.Srini.
    * Location         : Chennai,
    *                  : Tamil Nadu,
    *                  : India.
    * Date             : 3/10/2001.
    ********************************************************************
    * TESTED - MS EXCEL 97
    * NOT RECOMMENDED FOR LENGTHY OUTPUT AND LARGE DATA TABLE BROWSING
    ********************************************************************
    TABLES: USR03,DD02L.
    DATA: ZX030L LIKE X030L.
    DATA BEGIN OF ZDFIES OCCURS 0.
         INCLUDE STRUCTURE DFIES.
    DATA END OF ZDFIES.
    DATA: BEGIN OF FLDITAB OCCURS 0,
          FLDNAME(11) TYPE C,
          END OF FLDITAB.
    DATA ITABUSR03 LIKE USR03 OCCURS 0 WITH HEADER LINE.
    DATA TNAME LIKE DD02L-TABNAME.
    SELECT * FROM USR03 INTO TABLE ITABUSR03.
    TNAME = 'USR03'.
    PERFORM GETFIELEDS.
    PERFORM SHOW123.
    ********************************************
    FORM GETFIELEDS.
         CALL FUNCTION 'GET_FIELDTAB'
          EXPORTING
              LANGU              = SY-LANGU
              ONLY               = SPACE
              TABNAME            = TNAME
              WITHTEXT           = 'X'
          IMPORTING
              HEADER             = ZX030L
          TABLES
              FIELDTAB           = ZDFIES
          EXCEPTIONS
              INTERNAL_ERROR      = 01
              NO_TEXTS_FOUND      = 02
              TABLE_HAS_NO_FIELDS = 03
              TABLE_NOT_ACTIV     = 04.
         CASE SY-SUBRC.
            WHEN 0.
              LOOP AT ZDFIES.
                   FLDITAB-FLDNAME = ZDFIES-FIELDNAME.
                   APPEND FLDITAB.
              ENDLOOP.
            WHEN OTHERS.
                 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  with  SY-SUBRC.
          ENDCASE.
    ENDFORM.
    ***********************************
    FORM SHOW123.
    CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
         EXPORTING
              FILE_NAME                 = 'C:\USR03.XLS'
              DATA_SHEET_NAME           = 'USER LIST'
        TABLES
             DATA_TAB                  =  ITABUSR03
             FIELDNAMES                =  FLDITAB
        EXCEPTIONS
             FILE_NOT_EXIST            = 1
             FILENAME_EXPECTED         = 2
             COMMUNICATION_ERROR       = 3
             OLE_OBJECT_METHOD_ERROR   = 4
             OLE_OBJECT_PROPERTY_ERROR = 5
             INVALID_FILENAME          = 6
             INVALID_PIVOT_FIELDS      = 7
             DOWNLOAD_PROBLEM          = 8
             OTHERS                    = 9.
    IF SY-SUBRC <> 0.
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 31, 2008 at 11:26 AM

    TABLES: mara.

    TYPES: BEGIN OF st_mara,

    matnr TYPE mara-matnr,

    ersda TYPE mara-ersda,

    ernam TYPE mara-ernam,

    laeda TYPE mara-laeda,

    END OF st_mara.

    DATA: in_mara TYPE TABLE OF st_mara WITH HEADER LINE.

    DATA: wa_mara LIKE in_mara.

    SELECT-OPTIONS: s_matnr FOR mara-matnr.

    AT SELECTION-SCREEN.

    IF s_matnr-low LE 20 OR s_matnr-high GE 1700.

    MESSAGE e001(zts1) .

    ENDIF.

    START-OF-SELECTION.

    SELECT matnr ersda ernam laeda

    FROM mara

    INTO TABLE in_mara

    WHERE matnr IN s_matnr.

    LOOP AT in_mara INTO wa_mara.

    WRITE: / wa_mara-matnr,

    wa_mara-ersda,

    wa_mara-ernam,

    wa_mara-laeda.

    ULINE.

    ENDLOOP.

    END-OF-SELECTION.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    • BIN_FILESIZE =

    filename = 'd:\san.txt'

    FILETYPE = 'ASC'

    • APPEND = ' '

    • WRITE_FIELD_SEPARATOR = ' '

    • HEADER = '00'

    • TRUNC_TRAILING_BLANKS = ' '

    • WRITE_LF = 'X'

    • COL_SELECT = ' '

    • COL_SELECT_MASK = ' '

    • DAT_MODE = ' '

    • CONFIRM_OVERWRITE = ' '

    • NO_AUTH_CHECK = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

    • WRITE_BOM = ' '

    • TRUNC_TRAILING_BLANKS_EOL = 'X'

    • WK1_N_FORMAT = ' '

    • WK1_N_SIZE = ' '

    • WK1_T_FORMAT = ' '

    • WK1_T_SIZE = ' '

    • IMPORTING

    • FILELENGTH =

    TABLES

    data_tab = in_mara

    • FIELDNAMES =

    • EXCEPTIONS

    • FILE_WRITE_ERROR = 1

    • NO_BATCH = 2

    • GUI_REFUSE_FILETRANSFER = 3

    • INVALID_TYPE = 4

    • NO_AUTHORITY = 5

    • UNKNOWN_ERROR = 6

    • HEADER_NOT_ALLOWED = 7

    • SEPARATOR_NOT_ALLOWED = 8

    • FILESIZE_NOT_ALLOWED = 9

    • HEADER_TOO_LONG = 10

    • DP_ERROR_CREATE = 11

    • DP_ERROR_SEND = 12

    • DP_ERROR_WRITE = 13

    • UNKNOWN_DP_ERROR = 14

    • ACCESS_DENIED = 15

    • DP_OUT_OF_MEMORY = 16

    • DISK_FULL = 17

    • DP_TIMEOUT = 18

    • FILE_NOT_FOUND = 19

    • DATAPROVIDER_EXCEPTION = 20

    • CONTROL_FLUSH_ERROR = 21

    • OTHERS = 22

    .

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    Edited by: Abap-fresher on Jan 31, 2008 12:28 PM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.