Application Development and Automation 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: 
Read only

internal table

Former Member
0 Likes
536

hi experts,

i wan to fetch records from a big internal table into another internal table where the number of records to be fetched is entered by the user in the selectioon screen.

after fetching the records into internal table i want to download this table to excel sheet.

Could any one help me in this case. as soon as possible.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
515

first of all

declare the internal table (jtab) u want to fill from the internal table(big = itab ) with the fileds u want to append .

second to append the records u need to append like this.

loop at itab.
jtab-f1 = itab-f1.
jtab-f2 = itab-f2.
jtab-f3 = itab-f3.
jtab-f4 = itab-f4.

append jtab.
clear jtab.

endloop

this way u will fetch all the records into ur jtab with the desired fields.

third .to download this into an excel sheet .

use this fm .

DATA : v_length TYPE p.
p_pcfile will he the location to where u will drop the excel sheet .

declare this as 

parameters :  p_pcfile LIKE rlgrap-filename DEFAULT text-001 .

in the text  give the pathname this will do.

CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
            filename   = p_pcfile          " ur path file .
            filetype   = 'DAT'                "this is for excel 
       IMPORTING
            filelength = v_length
       TABLES
            data_tab   = jtab.             " this is ur contents
*              fieldnames = it_fieldnames.

also u can use GUI_DOWNLOAD with the same effect.

regards,

vijay

6 REPLIES 6
Read only

Former Member
0 Likes
515

Hi Ali

You can try this logic,


DATA: V_COUNT TYPE I VALUE 1.

DO.

* Read Table 1
READ TABLE <I_TAB1> INTO <W_TAB1> INDEX V_COUNT.
* Append to Second Table
APPEND <W_TAB1> TO <I_TAB2>.

V_COUNT = V_COUNT + 1.
* limit is reached is then exit
IF V_COUNT > <No of Records>.
EXIT.
ENDIF.

ENDDO.

<b>You can find the code sample for downloading ot excel here</b>

Regards

Kathirvel

Read only

0 Likes
515

hi Kathirvel Balakrishnan ,

i really appreciate your fast reply.

after i get the second internal table how i could download it into more than one excel sheets.

with consideration of maximum limite of record could excel sheet could have.

best regared

Ali

Read only

0 Likes
515

Hi Ali

Excel has a limitation around 64 thousand records/rows.

Besides if you are planning to create multiple worksheets then you should opt for Excel ole.

The codes for the same are here,

http://www.sapdevelopment.co.uk/ms/ms_excel.htm

The logic is that after creating an Excel OLE object,

Loop into the internal table and start moving the contents to the sheet1 until 64K entries are reached as shown below


* Create first Excel Sheet
  CALL METHOD OF application 'Worksheets' = sheet
                               EXPORTING #1 = 1.
  CALL METHOD OF sheet 'Activate'.
  SET PROPERTY OF sheet 'Name' = 'Sheet1'.
  LOOP AT itab1.
    index = row_max * ( sy-tabix - 1 ) + 1. " 1 - column name
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    SET PROPERTY OF cells 'Value' = itab1-first_name.
  ENDLOOP.

Once it reaches the limit then you can add another sheet similarly as shown above and continues the same.

You just need to put a logic inside loop for creating the work sheets as you reach the 64K entries.

Hope this solves your problem.

Regards

Kathirvel

Read only

0 Likes
515

sorry Kathirvel Balakrishnan

.

i could not understand.

Could you simplify the code in such a way ?

Until now i download the internal table with entered No. of record.

But i have to use multiple sheet because the data so huge .

best regareds.

Ali

Read only

Former Member
0 Likes
515

Use this function module..

GUI_DOWNLOAD.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\TEST.XLS'

TABLES

DATA_TAB = IT.

Read only

Former Member
0 Likes
516

first of all

declare the internal table (jtab) u want to fill from the internal table(big = itab ) with the fileds u want to append .

second to append the records u need to append like this.

loop at itab.
jtab-f1 = itab-f1.
jtab-f2 = itab-f2.
jtab-f3 = itab-f3.
jtab-f4 = itab-f4.

append jtab.
clear jtab.

endloop

this way u will fetch all the records into ur jtab with the desired fields.

third .to download this into an excel sheet .

use this fm .

DATA : v_length TYPE p.
p_pcfile will he the location to where u will drop the excel sheet .

declare this as 

parameters :  p_pcfile LIKE rlgrap-filename DEFAULT text-001 .

in the text  give the pathname this will do.

CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
            filename   = p_pcfile          " ur path file .
            filetype   = 'DAT'                "this is for excel 
       IMPORTING
            filelength = v_length
       TABLES
            data_tab   = jtab.             " this is ur contents
*              fieldnames = it_fieldnames.

also u can use GUI_DOWNLOAD with the same effect.

regards,

vijay