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

Continue selection

ronaldo_aparecido
Contributor
0 Likes
1,568

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.

1 ACCEPTED SOLUTION
Read only

former_member186413
Participant
0 Likes
1,525

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

  • Global Declaration Section

                    DATA: packageSize = 1000.

                               lt_wa TYPE TABLE OF ANY WITH HEADER LINE.    

  • Proceesing Section.

                   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.

  •      Global Delaration Section.

                    DATA: itab TYPE TABLE OF ANY WITH HEADER LINE,

                              cuiserIndexStart TYPE i,

                              cuiserIndexEnd TYPE i,

                              totalNum  TYPE i,

                              loopCounter TYPE i.

  •      Processing Section.

                   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.

11 REPLIES 11
Read only

anupam_anand
Participant
0 Likes
1,525

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

Read only

former_member186413
Participant
0 Likes
1,526

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

  • Global Declaration Section

                    DATA: packageSize = 1000.

                               lt_wa TYPE TABLE OF ANY WITH HEADER LINE.    

  • Proceesing Section.

                   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.

  •      Global Delaration Section.

                    DATA: itab TYPE TABLE OF ANY WITH HEADER LINE,

                              cuiserIndexStart TYPE i,

                              cuiserIndexEnd TYPE i,

                              totalNum  TYPE i,

                              loopCounter TYPE i.

  •      Processing Section.

                   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.

Read only

0 Likes
1,525

thanks HAI WONG.

Thanks Guys.

Read only

Arun_Prabhu_K
Active Contributor
0 Likes
1,525

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.

Read only

Former Member
0 Likes
1,525

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.

Read only

former_member209120
Active Contributor
0 Likes
1,525

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.

Read only

Former Member
0 Likes
1,525

Hi,

  • First fetch all records from databse table

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.

Read only

Former Member
0 Likes
1,525

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

Read only

Former Member
0 Likes
1,525

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

Read only

Former Member
0 Likes
1,525

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

Read only

Arthur_Silva
Participant
0 Likes
1,525

Hello,

Try to use PACKAGE SIZE statement, just like below:

SELECT <f1> <f2> <fn>

  FROM <table>

  INTO TABLE <itable>

  PACKAGE SIZE<n>

Regards,