Skip to Content
author's profile photo
Former Member

Itab formation for download to Excel

Hi Friends,

I need to create an excel file from an internal table (say itab) which contains header and lower portion data of excel.

I need to create excel like this:

<b>Vendor : itab-lifnr</b> -spaces- <b>Plant : itab-werks</b>

<b>User Name : itab-usr01</b> - spaces - <b>Date : itab-date</b>

Under above, the column headers for the line items

<b>Vendor</b> -space- <b>Name</b> -space- <b>Material</b> -space- <b>Mail ID</b> -space- <b>Delivery Status</b>

And here the line items (can be more than one)

<b>itab-lifnr</b> -space- <b>itab-name1</b> -space- <b>itab-matnr</b> -space- <b>itab-email</b> -space- <b>itab-stewn</b>

How to go about it:

- is using con_cret and con_tab the only option ? if so, how should the internal table to be sent to gui_download be declared ?

Advance Thanks

Aadarsh

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 04, 2005 at 06:01 AM
    data: imakt type table of makt.
    start-of-selection.
     select * into corresponding fields of table imakt
                 from makt up to 100 rows
                         where spras = sy-langu.
     
      call method cl_gui_frontend_services=>gui_download
        exporting
    *    BIN_FILESIZE            =
          filename                = 'C:text.txt'
    <b>     FILETYPE                = 'DAT'</b>
    *    APPEND                  = SPACE
    <b>     WRITE_FIELD_SEPARATOR   = SPACE</b>
    *    HEADER                  = '00'
    *    TRUNC_TRAILING_BLANKS   = SPACE
    *    WRITE_LF                = 'X'
    *    COL_SELECT              = SPACE
    *    COL_SELECT_MASK         = SPACE
    *  IMPORTING
    *    FILELENGTH              =
        changing
          data_tab                = imakt
    *  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.
    

    Try this out.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 04, 2005 at 06:06 AM

    Hi,

    I am giving you a sample code you can use it.

    loop at itab.

    move: itab-lifner to excel_it-lifner.

    concatenate 'vendor'itab-lifner into variable separate by space.

    endloop.

    data: fname like rlgrap-filename value 'vendor_details/Meaning full name.xls'.

    *********

    perform fill_titles.

    ***********

    check not excel_it[] is initial.

    call function 'DOWNLOAD'

    EXPORTING

    filename = fname

    filetype = 'DAT'

    TABLES

    data_tab = excel_it

    fieldnames = titles_it

    EXCEPTIONS

    invalid_filesize = 1

    invalid_table_width = 2

    invalid_type = 3

    no_batch = 4

    unknown_error = 5

    gui_refuse_filetransfer = 6

    customer_error = 7

    others = 8.

    **********

    form fill_titles.

    refresh titles_it.

    concatenate text-h05 text-h18 into titles_it-title

    separated by space.

    append titles_it.

    .........

    .........

    Here Text-h05......will be your Header texts.....

    ************

    You can use this example to format your Excel sheet from Itab.

    I hope this will help you.

    Any issues be back or if it is clear kindly award points and close the thread.

    CHEERS

    Message was edited by: Deepak333 k

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 04, 2005 at 06:03 AM

    u can try writing the file using two different internal tables...one each for header and line item data...

    of course ur file will be written in append mode after the first table is written.

    the first table could have the structure of a single line of characters (eg: EDPLINE). here u can pass the Vendor, Plant in one line and user,Date in the second.

    Call GUI_DOWNLOAD to write this table to file.

    after this use another table for the line item data...

    this could have the structure u want...

    use GUI_DOWNLOAD again but this time give 'X' in the APPEND parameter...

    hope it helps...

    rgds,

    PJ

    Add comment
    10|10000 characters needed characters exceeded