‎2013 Oct 09 5:32 PM
I have a table with 8000 records and i want select 1000 records and work with it.
But I want select again of table and select 1000 after of 1000 records selected in past.
EX
I have
1
2
3
4
5
6
I select 1 to 3
I want select now 4 to 6.
How I can DO?
Thanks Comunitty.
‎2013 Oct 10 1:56 AM
For your example:
first method: Define package size as SELECT stament's extension option, It Works like ... INTO wa, except that the selected data is not placed in the internal table itab line by line, but in one single operation. In this case, SELECT does not introduce a processing loop, so there can be no ENDSELECT statement.
To see more detail: http://scn.sap.com/thread/172050
DATA: packageSize = 1000.
lt_wa TYPE TABLE OF ANY WITH HEADER LINE.
SELECT * FROM <your_table> INTO TABLE lt_wa PACKAGE SIZE packageSize.
LOOP AT lt_wa.
ENDLOOP.
ENDSELECT.
The second method, it might be stupid and low performance, but it works exactly for what you want.
DATA: itab TYPE TABLE OF ANY WITH HEADER LINE,
cuiserIndexStart TYPE i,
cuiserIndexEnd TYPE i,
totalNum TYPE i,
loopCounter TYPE i.
loopCounter = totalNum / 1000 .
cuiserIndexStart = 0.
DO.
cuiserIndexEnd = cuiserIndexStart + 1000.
SELECT * FROM <your_table> INTO TABLE ltab UP TO cuiserIndexEnd
* delete previous index records.
DATA: idx TYPE i,
idxt TYPE i.
idx = sy-loopc * 1000.
IF idx NE 0.
idxt = idx + 1000.
DELETE TABLE ltab FROM idx TO idxt.
ENDIF.
LOOP AT itab.
PERFORM <your processing> CHANGING ltab.
ENDLOOP
loopCounter = loopCounter - 1.
WHILE loopCounter EQ 0.
Mehtod 3:
FIELD-SYMBOLS: <fs_itab> TYPE ANY.
DATA: idx TYPE i,
idxt TYPE i.
DATA: itab TYPE TABLE OF ANY.
SELECT * FROM <your_table> INTO TABLE itab.
idx = 1.
idxt = idx + idxt.
loop at itab assigning <fs_itab> from idx to idxt.
move <fs_itab> to wa_final.
append wa_final to itab_final.
clear wa_final.
endloop.
‎2013 Oct 09 5:49 PM
Hi Ronaldo,
I am not sure if I have got your requirement correctly but this may help:
Select * from <table_name> package size 1000 appending table i_tab where <where conditions>.
<logic to process the 1000 fetched retrieved records. Within this you can move the processed records to another internal table and refresh i_tab to get the new set of 1000 records>
Endselect.
Let me know if it helped.
Thanks,
Anupam
‎2013 Oct 10 1:56 AM
For your example:
first method: Define package size as SELECT stament's extension option, It Works like ... INTO wa, except that the selected data is not placed in the internal table itab line by line, but in one single operation. In this case, SELECT does not introduce a processing loop, so there can be no ENDSELECT statement.
To see more detail: http://scn.sap.com/thread/172050
DATA: packageSize = 1000.
lt_wa TYPE TABLE OF ANY WITH HEADER LINE.
SELECT * FROM <your_table> INTO TABLE lt_wa PACKAGE SIZE packageSize.
LOOP AT lt_wa.
ENDLOOP.
ENDSELECT.
The second method, it might be stupid and low performance, but it works exactly for what you want.
DATA: itab TYPE TABLE OF ANY WITH HEADER LINE,
cuiserIndexStart TYPE i,
cuiserIndexEnd TYPE i,
totalNum TYPE i,
loopCounter TYPE i.
loopCounter = totalNum / 1000 .
cuiserIndexStart = 0.
DO.
cuiserIndexEnd = cuiserIndexStart + 1000.
SELECT * FROM <your_table> INTO TABLE ltab UP TO cuiserIndexEnd
* delete previous index records.
DATA: idx TYPE i,
idxt TYPE i.
idx = sy-loopc * 1000.
IF idx NE 0.
idxt = idx + 1000.
DELETE TABLE ltab FROM idx TO idxt.
ENDIF.
LOOP AT itab.
PERFORM <your processing> CHANGING ltab.
ENDLOOP
loopCounter = loopCounter - 1.
WHILE loopCounter EQ 0.
Mehtod 3:
FIELD-SYMBOLS: <fs_itab> TYPE ANY.
DATA: idx TYPE i,
idxt TYPE i.
DATA: itab TYPE TABLE OF ANY.
SELECT * FROM <your_table> INTO TABLE itab.
idx = 1.
idxt = idx + idxt.
loop at itab assigning <fs_itab> from idx to idxt.
move <fs_itab> to wa_final.
append wa_final to itab_final.
clear wa_final.
endloop.
‎2013 Oct 15 12:29 PM
‎2013 Oct 10 4:03 AM
Hello Ronaldo.
I would suggest you to go for fetching all 8000 records from Database table at one shot into internal table.
Then you can process the internal table every 1000 records.
For instance,
loop at itab from 1 to 1000.
"YOUR BUSINESS LOGIC
endloop.
Regards.
‎2013 Oct 10 4:19 AM
Hello As Arun, Suggested that's a great idea, Fetch all the record by Select * from in a local internal table. Now after this we will work on the internal table only so no DB hit again and again. now if you want you can create some sub internal table with 1000 record each.
Just Loop at the main internal table and append 1000 record in new sub itab. and use it according to your requirement and modify your internal table only, of you want to modify some data in DB also.
Once all modification is done in the itab, Update/modify your DB table by Internal table.
‎2013 Oct 10 4:41 AM
Hi Ronaldo Aparecido,
Fetch all 8000 records from data base table to internal table at single select statement. from internal table you can do as follow as suggested by Arun prabhu.
DATA : it_sflight TYPE TABLE OF sflight,
wa_sflight type sflight.
SELECT * FROM sflight INTO TABLE it_sflight UP TO 100 ROWS.
Loop at it_sflight into wa_sflight from 1 to 10.
Write : / wa_sflight-CARRID, wa_sflight-CONNID, wa_sflight-FLDATE, wa_sflight-PRICE.
endloop.
Uline.
Loop at it_sflight into wa_sflight from 11 to 20.
Write : / wa_sflight-CARRID, wa_sflight-CONNID, wa_sflight-FLDATE, wa_sflight-PRICE.
endloop.
‎2013 Oct 10 4:56 AM
Hi,
select *
from
<database table name >
into table
<internal table>
Then append the value to internal table by using loop statement
loop at <internal table> INTO <work area> FROM 1 to 1000.
"insert the value into your internal table
endloop.
‎2013 Oct 10 5:01 AM
Hii Ronaldo,
fetch all the 8000 records in single shot database fetch into internal table.
Then process or filter ur internal table according to ur requirement.it will also increase ur performance by only one databse fetch.
Go through the solution provided by Arun, Chandra and Ramesh.
For ur first 1000 records processing do like,
field-symbols <fs_itab> like line of itab.
if itab_final is initial and not itab is initial.
loop at itab assigning <fs_itab> from 1 to 1000.
move <fs_itab> to wa_final.
append wa_final to itab_final.
clear wa_final.
endloop.
unassign <fs_itab>.
endif.
Now do what u want to do with internal table itab_final having first 1000 records.
regards
Syed
‎2013 Oct 10 5:39 AM
Hi Ronaldo ,
Select complete database into internal table using select * statement .
You need two internal table it_tab_comp (which contains complete records in the table ) and it_tab_1000 (to hold the thousand records )
REPORT ZTEST_SCN_09.
DATA : it_tab_comp type table OF EKBE ,
it_tab_1000 TYPE TABLE OF EKBE ,
w_tab_comp type EKBE ,
w_tab_1000 type EKBE .
DATA COUNTER TYPE i .
START-OF-SELECTION . FETCH ALL THE RECORDS INTO
INTERNAL TABLE
select *
from EKBE
into table it_tab_comp .
PERFORM 1000_fetch . First 1000 record fetched
PERFORM 1000_FETCH . Next thousand record fetched .(Like this you can fetch entire record ,i tested with 59000 records)
FORM 1000_FETCH .
COUNTER = 1 .
CLEAR IT_TAB_1000 .
THOUSAND RECORDS ARE MOVED FROM COMPLETE INTERNAL TO
INTERNAL TABLE HOLDING ONLY 1000
RECORDS .
EACH TIME YOU CALL THE PERFORM LIKE YOUR REQUIREMENT
1-1000 IN FIRST CALL
1001-2000 IN SECOND CALL WILL BE FETCHED
IF it_tab_comp is not INITIAL .
WHILE COUNTER LE 1000 .
READ TABLE it_tab_comp INTO w_tab_comp INDEX COUNTER .
if sy-subrc = 0 .
COUNTER = COUNTER + 1 .
APPEND w_tab_comp TO IT_tab_1000.
else .
exit .
endif .
CLEAR : W_TAB_1000 ,
W_TAB_COMP .
ENDWHILE .
LOOP AT IT_TAB_1000 INTO W_TAB_1000.
DELETE TABLE IT_TAB_COMP FROM W_TAB_1000 .
ENDLOOP.
CLEAR COUNTER .
ENDIF.
ENDFORM. " 1000_FETCH
With regards ,
Juneed K Manha
‎2013 Oct 10 6:28 AM
Hi Ronaldo,
You can use in this way:
SELECT matnr
FROM mara
APPENDING TABLE lt_mara
PACKAGE SIZE 1000
WHERE matnr CP 'l*'.
IF sy-subrc = 0.
* Do operation
APPEND LINES OF lt_mara to lt_mara1[].
refresh lt_mara[].
ENDIF.
endselect.
‎2013 Oct 10 6:20 PM
Hello,
Try to use PACKAGE SIZE statement, just like below:
SELECT <f1> <f2> <fn>
FROM <table>
INTO TABLE <itable>
PACKAGE SIZE<n>
Regards,