‎2008 Mar 05 2:00 PM
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.
‎2008 Mar 05 2:13 PM
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
‎2008 Mar 05 2:07 PM
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
‎2008 Mar 05 2:10 PM
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.
‎2008 Mar 05 2:13 PM
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
‎2008 Mar 05 2:33 PM
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