Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Itab formation for download to Excel

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
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.

3 REPLIES 3

Former Member
0 Kudos
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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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