‎2009 Nov 04 6:21 AM
Hi,
can anybody tell the how to implement the logic to split the data from internal table based on number of records into another internal table.
this is done because the first internal table containing huge amount of data and i don't want to loop into that internal table. so split the records into small amount of records into another table and use that small internal table for loop.
for ex: i have selected all the records from mast table into internal table i_mast. it has around 2 lakh records. the volume of data can increase in quality system. so i have to write a code in such a way that it will split the total records by 20,000 into one more internal table i_tab and process all the logic for first 20,000 record from itab. then again take 20, 000 record from i_mast into itab and process again for 20,000 records like that..
the code should not be restricted for volume of data in i_mast. it can be any number of records in qulaity/production system. so i can not put the logic for specific number of data.
Please provide the logic to implement it.
thanks,
‎2009 Nov 04 6:32 AM
Use package size in you select query.
Refer:
link:[http://help.sap.com/abapdocu_70/en/ABAPINTO_CLAUSE.htm]
link:[http://www.sap-img.com/abap/package-size.htm]
‎2009 Nov 04 6:34 AM
hi,
Get the number of records in internal table by using DESCRIBE TABLE...LINES lin statement and divide the number of lines lin by a conatant like 100 or 1000 depending on expected volume of data. Calculate the index everytime by adding the value got from above division and Fill the internal tables from the main internal tables using index.
Regards,
Srilatha
‎2009 Nov 04 7:22 AM
Hi Srilatha,
Can you please elaborate with code so that it will be easy to understand, what u mean to say.
Thanks,
‎2009 Nov 04 7:27 AM
Instead of fetching 2 lakh records into internal table and then manipulating the records.
You can fetch using package size from table itself.
‎2009 Nov 04 7:39 AM
Hi,
can you provide me the code how it will go again and again to fectch pack size and put it into another internal table.
Its getting tough for me to understand fully without code. It would be really helpful if you could have provided the code logic entirely.
Thanks.
‎2009 Nov 04 7:41 AM
Did you refer the link i provided ?
Below code fetches 1000 records from mara in each hit.
data:it_mara type table of mara.
data:it_marc type table of marc.
select * from mara into table it_mara package size 1000.
if it_mara[] is not initial.
select * from marc into table it_marc for all entries in it_mara
where matnr = it_mara-matnr.
if it_marc[] is not initial.
"Here do the required manipulation.
endif.
endif.
clear it_mara[].
endselect.
‎2009 Nov 04 6:37 AM
HI,
try to use....
*get 490 materials from the itab
LOOP AT itab.
APPEND itab TO gt_itab.
DELETE itab.
count = count + 1.
IF count = 490.
EXIT.
ENDIF.
ENDLOOP.
thnx
RK
‎2009 Nov 04 7:08 AM
Hi Rahul,
Can you code with description how to use splitting logic??
u have written the code, which have total records in first internal table is 490 and its putting the whole records from first internal table into second internal table. i don't see any splitting concept.
Please elaborate
Thanks,
‎2009 Nov 04 7:43 AM
Hi,
sorry Reena B i forgot the DO.....ENDDO.
my code...
*get 490 materials from the itab
DO.
LOOP AT itab.
APPEND itab TO gt_itab.
DELETE itab.
count = count + 1.
IF count = 490.
EXIT.
ENDIF.
ENDLOOP.
.
.
do what ever you want to do with the gt_itab.
.
.
ENDDO.
e.g.
if itab has 1000 records, it will get first 490 records from itab into gt_itab and delete the records from itab.
then process the gt_itab(which will containg only 490 records)
after you have to return to this block again and that time it itab will be having only 1000-490 = 510 records only..
it will get next 490 records into gt_iteb again and process it as per your requirement..
Edited by: Rahul Keshav on Nov 4, 2009 1:14 PM
‎2023 Jun 29 1:01 PM
Hi,
Also, you forgot to check gt_itab if it has a value after the endloop.
And clear counter after DO.
The last version should be:
DO.
CLEAR: count.
LOOP AT itab.
APPEND itab TO gt_itab.
DELETE itab.
count = count + 1.
IF count = 490.
EXIT.
ENDIF.
ENDLOOP.
IF gt_itab is initial.
exit. " exit from the DO..ENDDO loop.
ENDIF.
.
do what ever you want to do with the gt_itab.
.
.
ENDDO.
‎2009 Nov 04 8:02 AM
Hi,
There is no point in splitting the data into another internal table then processing the data. This will give no gain performance wise, infact it will further reduce the performance of the program.
What you should do is use PACKAGE SIZE addition of the select query and then process the data.
Have a look at demo program: demo_select_into_package in your system.
Br,
Advait
‎2009 Nov 04 9:00 AM
I recommend this in the other posting, and I thought it is obvious, it is for testing!!!
LOOP AT itab INTO wa.
count = count + 1.
if ( count > limit ).
exit.
endif.
APPEND wa TO gt_itab.
ENDLOOP.
Please use workarea and no implicit header lines which are outdated, because they are confusing!
‎2009 Nov 04 11:16 AM
Hello Everybody,
>
> this is done because the first internal table containing huge amount of data and i don't want to loop into that internal table. so split the records into small amount of records into another table and use that small internal table for loop.
,
The poster has clearly stated she doesn't want to loop at the huge internal table. However, everyone seems to be giving a solution to loop at the bigger table and split it into small table until a certain records are reached.
?
Br,
Advait
‎2009 Nov 04 12:41 PM
you are right and with an EXIT condition it is also no problem.
However, there is even an ABAP command which can do it directly:
APPEND LINES OF itab1 FROM 1 TO 1001 TO itab2.
Siegfried
‎2009 Nov 04 4:01 PM
Hi Reena,
Instead of selecting all the data into an internal table and then processing it use the clause PACKAGE SIZE. The following example processes data from table MAST, 20,000 records per iteration.
SELECT <field 1>
<field 2>
.
.
.
<field n>
FROM mast
INTO TABLE t_mast
PACKAGE SIZE 20000
WHERE <selection criteria>.
* the internal table i_mast will always have <= 20,000 records
LOOP AT i_mast INTO w_mast.
* process the data in the internal table
ENDLOOP.
ENDSELECT.
‎2009 Dec 30 10:07 AM
Since you already have records in your internal table what is the harm in looping at the internal table even if it contains large amount of data. It just that you are playing with the internal table and not with the database table.
Please let me know the exact requirement.
Regards,
Lalit Mohan Gupta.
‎2010 Jan 01 8:16 AM
There are two ways you can handle this scenario.
1. First one as mentioned by others use package size in your select query and do all the processing on fetched records within select and endselect.
2. Other way is to fetch all the records into one internal table and process the records in batches by inserting them into another
internal table itab_temp.
index2 = 1
do.
index1 = index2.
index2 = index1 + 20000.
APPEND LINES OF ITAB FROM index1 TO index2 TO itab_temp.
IF itab_temp[] is initail.
exit.
endif.
* Process all the records of itab_temp.
refresh itab_temp.
enddo.I hope above helps. From the performance perspective second method wd be little faster unless untill you have too many columns in ITAB which may consume ABAP memory.
‎2023 Dec 22 11:34 AM
CONSTANTS lc_packagesize TYPE i VALUE 499.<br>
DATA: ls_matnr TYPE mara-matnr,<br>
lt_matnr LIKE TABLE OF ls_matnr,<br>
lt_matnr_package LIKE TABLE OF ls_matnr,<br>
lt_matnr_final LIKE TABLE OF ls_matnr,<br>
lv_no_lines TYPE i,<br>
index1 TYPE i VALUE 1,<br>
index2 TYPE i VALUE 0.<br>
<br>
SELECT matnr<br>
FROM mara<br>
INTO TABLE lt_matnr<br>
WHERE mtart = 'ROH'.<br>
<br>
lv_no_lines = lines( lt_matnr ).<br>
<br>
WRITE / lv_no_lines.<br>
<br>
DO.<br>
index2 = index1 + lc_packagesize.<br>
<br>
APPEND LINES OF lt_matnr FROM index1 TO index2 TO lt_matnr_package.<br>
IF lt_matnr_package[] IS INITIAL.<br>
EXIT.<br>
ENDIF.<br>
lv_no_lines = lines( lt_matnr_package ).<br>
write: / ' index 1= ',index1,' index 2= ',index2.<br>
* WRITE / lv_no_lines.<br>
APPEND LINES OF lt_matnr_package TO lt_matnr_final.<br>
index1 = index2 + 1.<br>
REFRESH lt_matnr_package.<br>
<br>
ENDDO.<br>
lv_no_lines = lines( lt_matnr_final ).<br>
WRITE / lv_no_lines.