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

splitting the internal table

Former Member
0 Likes
967

Hey folks,

I have a requirement where i have to split the data in one internal table into 3 internal tables when it reaches a record limit how do i do it.

suppose i have 1000 records in itab i need to divide these into 4 internal tables containing 250 each .. how wud i do it.

Can somebody provide me with the sample code.

Regards

Rock.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
734

Describe table itab lines records.
records = records / 4.
one = records.
two = records * 2.
three = records * 3.
four = records * 4.
Loop at itab.
if sy-tabix LE one.
append itab to itab1.
elseif sy-tabix LE two.
append itab to itab2.
elseif sy-tabix LE three.
append itab to itab3.
elseif sy-tabix LE four.
append itab to itab4
endif.
Endloop.

I'm sure there's a more dynamic way to do it, but is the first that came to my mind

4 REPLIES 4
Read only

Former Member
0 Likes
734

YOU CAN COUNT NO OF INTERNAL TABLE ENTRIES BY USING SY-DBCNT AND THEN LOOP IT ACCORDINGLY..

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Mar 5, 2008 9:33 AM

Read only

Former Member
0 Likes
734

Hi,

Try This Sample Code.

Suppose There are 3 internal Tabales itab,

ITAB1,itab2,itab3,itab4..

Loop at Itab.

If Sy-tabix Le '250'.

move :itab-f1 to Itab1-f1.

endif.

If Sy-tabix gt '250' and le '500'..

move :itab-f1 to Itab2-f1.

endif.

If Sy-tabix gt '500' and le '700'..

move :itab-f1 to Itab3-f1.

endif.

If Sy-tabix gt '700'.

move :itab-f1 to Itab4-f1.

endif.

endloop.

Read only

Former Member
0 Likes
735

Describe table itab lines records.
records = records / 4.
one = records.
two = records * 2.
three = records * 3.
four = records * 4.
Loop at itab.
if sy-tabix LE one.
append itab to itab1.
elseif sy-tabix LE two.
append itab to itab2.
elseif sy-tabix LE three.
append itab to itab3.
elseif sy-tabix LE four.
append itab to itab4
endif.
Endloop.

I'm sure there's a more dynamic way to do it, but is the first that came to my mind

Read only

Former Member
0 Likes
734

Hi,

see this sample code...

Report ytest.

data : itab type table of ekko with header line,

jtab type table of ekko with header line,

jtab1 type table of ekko with header line,

jtab2 type table of ekko with header line,

jtab3 type table of ekko with header line,

cpy type i,

a1 type i,

a2 type i.

data : cnt type i,

min type i.

select * from ekko into table itab up to 1000 rows.

describe table itab lines cnt.

if cnt ge 1000.

min = cnt / 4.

cpy = min.

append lines of itab from 1 to min to jtab.

a1 = min + 1.

a2 = min + cpy.

append lines of itab from a1 to a2 to jtab1.

a1 = a2 + 1.

a2 = a2 + cpy.

append lines of itab from a1 to a2 to jtab2.

a1 = a2 + 1.

a2 = a2 + cpy.

append lines of itab from a1 to a2 to jtab3.

endif.

<REMOVED BY MODERATOR>

Regards,

Shanthi.

Edited by: Alvaro Tejada Galindo on Mar 5, 2008 9:36 AM