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

Downloading internal table data into excel sheet.

Hi All,

I want to download internal table data into excel sheet as it is. For that i am using 'GUI_DOWNLOAD'. This is creating a file at the specified location but the problem is that all the data is coming into one column where as my internal table has 18 different columns. So accordingly i want the data in the excel sheet in the 18 different columns. So please guide me how this can be achieved.

Thanks.

Regards,

Chetan.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Posted on Jan 03, 2008 at 10:13 AM

    Hi.

    check this example:

    data: begin of itab occurs 0,

    col1(10),

    col2 type matnr,

    end of itab.

    ....fill some data in the itab....

    call the GUI_DOWNLOAD with the following parameters:

    FILETYPE = DAT

    filename = 'c:\temp\test.xls'

    data_tab = itab

    and it should work fine.

    you can also fill a columns table and pass it to FIELDNAMES parameter in order to have column names in the gemerated excel file.

    Reward if it helps

    Regards,

    George

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 03, 2008 at 10:59 AM

    Dear Chetan,

    Try this.

    OPEN DATASET filename FOR OUTPUT

    TRANSFER fp_output_structure TO fp_output_file LENGTH l_len.

    Best Regards,

    Rajesh.

    Please reward points if found helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 03, 2008 at 11:21 AM

    Hi,

    see this link:

    downloading-to-excel

    and look to Allan's program

    Edited by: Rodrigo Paisante on Jan 3, 2008 9:21 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 07, 2008 at 06:19 AM

    its very simple.

    Code:

    select * from (DDIC Table name) into table (ur internal table).

    *****Now click on the PATTERN i.e Call Function and put 'Download'.

    *****Then use these parameters.

    EXPORTING

    FILENAME = 'C:'

    FILETYPE = 'DAT'

    TABLES

    DATA_TAB = Name of ur internal table.

    ***Save and execute.

    Reward points if useful.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 07, 2008 at 06:29 AM

    save it with .xls extension.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 06:37 AM

    hI Cheatan,

    I will send a small program for u check it once.In that after selecting the path we can mention the file name and also mention .XLS along with that ok..

    First u have to copy the below code and execute it and ur problem is solved ok..

    code:

    &----


    *& Report YITAB_XLS *

    *& *

    &----


    *& DEVELOPER : KIRAN KUMAR.G.A *

    *& PURPOSE : DOWNLOAD INTERNAL TABLE DATA TO XLS FILE *

    *& CREATION DT : 31/12/2007 *

    *& REQUEST : ERPK900035 *

    &----


    REPORT YITAB_XLS.

    ----


    • Internal Table

    ----


    data: begin of gt_data occurs 0,

    vbeln like vbap-vbeln,

    posnr like vbap-posnr,

    netpr like vbap-netpr,

    end of gt_data.

    ----


    • Global Variables

    ----


    data: t_vbeln type vbeln.

    ----


    • Global Structures

    ----


    data: gv_file type string.

    ----


    • Selection Screen

    ----


    selection-screen: begin of block b1 with frame title text-001.

    parameters : p_file(90).

    selection-screen: end of block b1.

    selection-screen: begin of block b2 with frame title text-002.

    select-options : s_vbeln for t_vbeln.

    selection-screen: end of block b2.

    *For Path Selection

    at selection-screen on value-request for p_file.

    perform path_directory.

    *Initilization

    initialization.

    perform initial.

    start-of-selection.

    *Fetching data from the Database Table

    perform fetch_data.

    end-of-selection.

    *Download Data to XLS file

    perform download_data.

    &----


    *& Form initial

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form initial .

    s_vbeln-sign = 'I'.

    s_vbeln-option = 'BT'.

    s_vbeln-low = '4969'.

    s_vbeln-high = '5000'.

    append s_vbeln.

    endform. " initial

    &----


    *& Form fetch_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form fetch_data .

    select vbeln

    posnr

    netpr

    from vbap

    into table gt_data

    where vbeln in s_vbeln.

    endform. " fetch_data

    &----


    *& Form path_directory

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form path_directory .

    CALL METHOD cl_gui_frontend_services=>directory_browse

    EXPORTING

    WINDOW_TITLE = 'SELECT THE PATH'

    INITIAL_FOLDER = 'C:/'

    CHANGING

    selected_folder = gv_file

    EXCEPTIONS

    CNTL_ERROR = 1

    ERROR_NO_GUI = 2

    NOT_SUPPORTED_BY_GUI = 3

    others = 4

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    CALL METHOD cl_gui_cfw=>flush

    EXCEPTIONS

    CNTL_SYSTEM_ERROR = 1

    CNTL_ERROR = 2

    others = 3

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    p_file = gv_file.

    endform. " path_directory

    &----


    *& Form download_data

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    form download_data .

    gv_file = p_file.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    • BIN_FILESIZE =

    filename = gv_file

    FILETYPE = 'ASC'

    • APPEND = ' '

    WRITE_FIELD_SEPARATOR = '~'

    • HEADER = '00'

    • TRUNC_TRAILING_BLANKS = ' '

    • WRITE_LF = 'X'

    • COL_SELECT = ' '

    • COL_SELECT_MASK = ' '

    • DAT_MODE = ' '

    • IMPORTING

    • FILELENGTH =

    tables

    data_tab = gt_data

    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.

    endform. " download_data

    Award points if helpful.

    Kiran Kumar.G

    Have a Nice Day..

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 06:42 AM

    Hi Chetan,

    In Fm: GUI_Download

    for Parameters

    Use WRITE_FIELD_SEPARATOR = 'X'.

    I guess, It may solve u r problem..

    Regards

    Srinivas M

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      HI CHECK THIS.

      REPORT z_sasi_download_upload_table MESSAGE-ID sf.

      • ------------------------------------------------------------------------------------

      • To upload / download a table on the desktop : just change the name of the table

      • eveywhere : ZCTS_ATTRIBUTE

      • in the program

      • ------------------------------------------------------------------------------------

      *

      *

      SELECTION-SCREEN ULINE.

      SELECTION-SCREEN COMMENT /1(80) text-001.

      SELECTION-SCREEN COMMENT /1(80) text-002.

      SELECTION-SCREEN ULINE.

      PARAMETER: p_tab TYPE tabname DEFAULT 'E070'.

      PARAMETERS: p_row TYPE i DEFAULT 200.

      PARAMETER: export RADIOBUTTON GROUP imex DEFAULT 'X'.

      PARAMETER: import RADIOBUTTON GROUP imex.

      PARAMETER: filename TYPE rlgrap-filename DEFAULT 'c:\users\ZCTS_ATTRIBUTE.XLS'.

      DATA:l_v_filename TYPE string.

      DATA: i_tab TYPE REF TO data.

      DATA l_i_fieldcat TYPE lvc_t_fcat. " lvc_t_fcat with header line.

      FIELD-SYMBOLS: <fs_it> TYPE STANDARD TABLE.

      *

      IF export NE space AND import NE space.

      MESSAGE e959.

      ENDIF.

      PERFORM define_internal_table.

      • Check wether table is empty

      IF l_i_fieldcat IS INITIAL.

      • message ....

      WRITE: / 'Invalid table', p_tab.

      EXIT.

      ENDIF.

      l_v_filename = filename.

      • export data to file ... **********************************************

      IF export NE space.

      *

      PERFORM create_export_file.

      *

      CALL FUNCTION 'GUI_DOWNLOAD'

      EXPORTING

      • BIN_FILESIZE =

      filename = l_v_filename

      filetype = 'DAT'

      • 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 = ' '

      • WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE

      • SHOW_TRANSFER_STATUS = ABAP_TRUE

      • IMPORTING

      • FILELENGTH =

      TABLES

      data_tab = <fs_it>

      • 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 EQ 1.

      MESSAGE e981.

      ELSEIF sy-subrc EQ 2.

      MESSAGE e980.

      ENDIF.

      • import data from file..........***************************************

      ELSEIF import NE space.

      CALL FUNCTION 'GUI_UPLOAD'

      EXPORTING

      filename = l_v_filename

      filetype = 'DAT'

      • HAS_FIELD_SEPARATOR = ' '

      • HEADER_LENGTH = 0

      • READ_BY_LINE = 'X'

      • DAT_MODE = ' '

      • CODEPAGE = ' '

      • IGNORE_CERR = ABAP_TRUE

      • REPLACEMENT = '#'

      • CHECK_BOM = ' '

      • NO_AUTH_CHECK = ' '

      • IMPORTING

      • FILELENGTH =

      • HEADER =

      TABLES

      data_tab = <fs_it>

      EXCEPTIONS

      file_open_error = 1

      file_read_error = 2

      no_batch = 3

      gui_refuse_filetransfer = 4

      invalid_type = 5

      no_authority = 6

      unknown_error = 7

      bad_data_format = 8

      header_not_allowed = 9

      separator_not_allowed = 10

      header_too_long = 11

      unknown_dp_error = 12

      access_denied = 13

      dp_out_of_memory = 14

      disk_full = 15

      dp_timeout = 16

      OTHERS = 17

      .

      IF sy-subrc EQ 1.

      MESSAGE i982.

      LEAVE LIST-PROCESSING.

      ELSEIF sy-subrc EQ 2.

      MESSAGE e983.

      ENDIF.

      *

      PERFORM import_table.

      *

      ENDIF.

      *

      FORM: define_internal_table.

      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

      EXPORTING

      i_structure_name = p_tab

      CHANGING

      ct_fieldcat = l_i_fieldcat[].

      *-Create Dynamic Table

      CALL METHOD cl_alv_table_create=>create_dynamic_table

      EXPORTING

      it_fieldcatalog = l_i_fieldcat

      IMPORTING

      ep_table = i_tab

      EXCEPTIONS

      generate_subpool_dir_full = 1

      OTHERS = 2.

      ASSIGN i_tab->* TO <fs_it>.

      SELECT * FROM (p_tab) INTO TABLE <fs_it> UP TO p_row ROWS.

      ENDFORM. "Define_table

      ----


      • FORM create_export_file *

      ----


      FORM create_export_file.

      SELECT * FROM (p_tab) INTO TABLE <fs_it> UP TO p_row ROWS.

      ENDFORM. "CREATE_EXPORT_FILE

      ----


      • FORM IMPORT_DOCU 7777 *

      ----


      • All records with commands SYOH, SYOL, SYOT or SYGH will be selected *

      • from intern table RECORD_TAB and inserted into the extern tables. *

      ----


      FORM import_table.

      INSERT (p_tab) FROM TABLE <fs_it>.

      IF sy-subrc EQ 0.

      WRITE : / 'Error insert', sy-subrc.

      ENDIF.

      ENDFORM. "IMPORT_TABLE

      pLEASE REWARD POINTS IF USEFUL.

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.