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: 

Downloading dynamic internal table to excel

Former Member
0 Kudos

Hi All,

I have posted thread regarding this problem earlier and i got following code as solution to download field-symbol data

DATA: i_itab type standard table of mara.

FIELD-SYMBOLS : <fs> TYPE STANDARD TABLE .

ASSIGN i_itab to <fs>.

select * from mara into table i_itab up to 100 rows.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = 'C:\testfile.xls'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

data_tab = <fs>

This code is working fine , when we define statement:

DATA: i_itab type standard table of mara

But, i am defining internal table dynamically and my data resides in table <FS> .

Can anyone please tell how to define internal table i_itab like table <FS>. ?

1 ACCEPTED SOLUTION

former_member705122
Active Contributor
0 Kudos

Hi,

check this sample code,

DATA:
  o_ref TYPE REF TO data.
FIELD-SYMBOLS:
  <lt_table> TYPE STANDARD TABLE,
  <fs>       TYPE ANY,
  <field>    TYPE ANY,
  <field1>   TYPE ANY.
PARAMETERS:
  p_tab       TYPE tabname.       " Table name (eg: MARA)
*  p_field(20) TYPE c.                 " Field name (eg: MATNR)
 
START-OF-SELECTION.
  CREATE DATA o_ref TYPE TABLE OF (p_tab).
 
  ASSIGN p_field TO <field1>.
  ASSIGN o_ref->* TO <lt_table>.
 
  SELECT *
    FROM (p_tab) 
    INTO TABLE <lt_table> upto 100 rows.
IF sy-subrc eq 0.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename = 'C:\testfile.xls'
    WRITE_FIELD_SEPARATOR = 'X'
  TABLES
    data_tab = <lt_table>.
endif.

Regards

Adil

8 REPLIES 8

Former Member
0 Kudos

Hi Deepika,

If you say ASSIGN i_itab to <fs>.

<fs> vl be having the same structure as i_itab.

<fs> is meant for dynamic internal table

Regards,

Sujatha

Former Member
0 Kudos

check below code...

  • Using the above data dynamic internal table is been created

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gf_ifc

IMPORTING

ep_table = gf_table2.

  • The dynamic internal table which is created is been assigned to

  • field-symbol which holds the data of the columns of X-axis

ASSIGN gf_table2->* TO <fs_dyn_table2>.

  • Dynamic work area is been created usng the reference to the

  • field-symbol which has the data and the line item is been assign to

  • field-symbol to hold line item data for reading purposes line by line

CREATE DATA gf_line2 LIKE LINE OF <fs_dyn_table2>.

ASSIGN gf_line2->* TO <fs_dyn_wa2>.

Former Member
0 Kudos

Hi Deepika ,

Go through with this simple example.

REPORT ztest1.

data: l_tabname type tabname,

plt_tab type ref to data,

pla_tab type ref to data,

l_str type string,

lt_where type table of string,

lt_fields type table of string.

l_str = 'PROFIT_CTR'.

append l_str to lt_fields.

concatenate 'PROFIT_CTR = '

''''

'ENTRY'

''''

into l_str.

append l_str to lt_where.

field-symbols: <lt_tab> type table,

<la_tab> type any,

<field> type any.

l_tabname = '/BI0/PPROFIT_CTR'.

create data plt_tab type table of (l_tabname).

assign plt_tab->* to <lt_tab>.

create data pla_tab type (l_tabname).

assign pla_tab->* to <la_tab>.

select (lt_fields)

into corresponding fields of table <lt_tab>

from (l_tabname)

where (lt_where).

break-point.

loop at <lt_tab> assigning <la_tab>.

assign component 'PROFIT_CTR' of structure <la_tab> to <field>.

Write: <field>.

endloop.

Former Member
0 Kudos

Hi Sujatha,

Actually i have defined <FS> first and it has structure of table which i have passed dynamically in parameter using

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = itab_display

IMPORTING

ep_table = d_ref.

ASSIGN d_ref->* TO <F_FS>.

now, i want to move <FS> data into normal internal table i_itab

Problem is that i_itab should also have stucture like <FS>.

but i am not able to define :

i_itab like <FS>

or

i_itab like ( ptab ) .

ptab is parameter containing table name

can you please tell how can i move <FS> data to i_itab ?

Former Member
0 Kudos

Hi All,

Is anybody have a way to define itab like <FS> ?

Please help..

thanks.

Hi

Declare as

FIELD-SYMBOLS: <FS> TYPE STANDARD TABLE.

Refer the below code.

REPORT  zak_test                                .

TABLES: mara.

TYPE-POOLS: slis.

DATA: it_fieldcat TYPE lvc_t_fcat,
      is_fieldcat LIKE LINE OF it_fieldcat.

DATA: new_table TYPE REF TO data.

DATA: new_line TYPE REF TO data.

FIELD-SYMBOLS: <l_table> TYPE STANDARD TABLE,
               <l_line>  TYPE ANY,
               <l_field> TYPE ANY.

*     Build fieldcat

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
    i_structure_name = 'MARA'
  CHANGING
    ct_fieldcat      = it_fieldcat[].


*    Create a new Table

CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog = it_fieldcat
  IMPORTING
    ep_table        = new_table.

ASSIGN new_table->* TO <l_table>.

* craete Work Area

CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.

*    Populate Data

DO 30 TIMES.
  ASSIGN COMPONENT 'MATNR' OF STRUCTURE <l_line> TO <l_field>.
  <l_field> = sy-index.
  INSERT <l_line> INTO TABLE <l_table>.
ENDDO.

* Download

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename                       = 'C:\TEST.TXT'
   FILETYPE                        = 'ASC'
  tables
    data_tab                        = <l_table>
 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.

former_member705122
Active Contributor
0 Kudos

Hi,

check this sample code,

DATA:
  o_ref TYPE REF TO data.
FIELD-SYMBOLS:
  <lt_table> TYPE STANDARD TABLE,
  <fs>       TYPE ANY,
  <field>    TYPE ANY,
  <field1>   TYPE ANY.
PARAMETERS:
  p_tab       TYPE tabname.       " Table name (eg: MARA)
*  p_field(20) TYPE c.                 " Field name (eg: MATNR)
 
START-OF-SELECTION.
  CREATE DATA o_ref TYPE TABLE OF (p_tab).
 
  ASSIGN p_field TO <field1>.
  ASSIGN o_ref->* TO <lt_table>.
 
  SELECT *
    FROM (p_tab) 
    INTO TABLE <lt_table> upto 100 rows.
IF sy-subrc eq 0.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename = 'C:\testfile.xls'
    WRITE_FIELD_SEPARATOR = 'X'
  TABLES
    data_tab = <lt_table>.
endif.

Regards

Adil

0 Kudos

This is cool. But as I know: GUI_DOWNLOAD cannot use in background process. GUI_DOWNLOAD only can handle size up to 2Gb.