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

Incremental read on DB table

Former Member
0 Likes
1,197

Hello,

I’m looking for a way to define the ‘

entry point

’ at the

incremental read

using select clause like:

Select * from {table} up to {m} rows
               where key-field1 = field1
               and     key-field2 = field2
               …
               and     key-fieldn = fieldn.

I will read rows, after next rows and so on.

How can I determine the correct where-condition to do realize an

incremental read

?

Thanks and best regards,

Kurt.

Hello,

I’m looking for a way to define the ‘

entry point

’ at the

incremental read

using select clause like:

Select * from {table} up to {m} rows
               where key-field1 = field1
               and     key-field2 = field2
               …
               and     key-fieldn = fieldn.

I will read rows, after next rows and so on.

How can I determine the correct where-condition to do realize an

incremental read

?

Thanks and best regards,

Kurt.

9 REPLIES 9
Read only

Former Member
0 Likes
1,163

HI,

Why dont u use PACKAGE SIZE in the select query?

Thanks and Best Regards,

Vikas Bittera.

Read only

0 Likes
1,163

Hello Vikas Bittera,

Thank you for your reply.

That’s clear; I can use <b>package size</b> as well as <b>up to n rows</b>, but I’m looking for the right way how to formulate the where-condition; if I have only one key, so I just can use <b>where key > key</b>. But if I have more key elements so I need a (complex) logical expression.

Do you have any idea?

Thanks and best regards,

Kurt

Read only

0 Likes
1,163

Hi,

you need not to do so, as the records will come sorted by the primary key when u will use package size..

Thanks and Best Regards,

Vikas Bittera.

Read only

0 Likes
1,163

Do you have any example?

Thanks & best regards,

Kurt.

Read only

0 Likes
1,163

Hi,

SELECT vbeln erdat

FROM vbak

INTO TABLE li_vbak PACKAGE SIZE 50.

SELECT posnr matnr meins

FROM vbap

INTO TABLE li_vbap

FOR ALL ENTRIES IN li_vbak

WHERE vbeln = li_vbak-vbeln.

IF sy-subrc = 0.

  • Now you have the two internal tables li_vbak and li_vbap filled

  • with data.

  • Do something with the data - remember to reinitialize internal

  • tables

ENDIF.

ENDSELECT.

Thanks and Best Regards,

Vikas Bittera.

Read only

0 Likes
1,163

Unfortunately I cannot use <b>select…endselect</b>, because I need a set of data to process IDOCs and posting data, I guess I cannot perform commit while select… endselect.

Is there another method to realize this?

Thanks and best regards,

Kurt

Read only

0 Likes
1,163

Hi,

You are absolutely correct!! in this case you cannot use package size..

you can do one thing... take one of the main key fields, and fetch the data for a range of this key field at a time and process...

suppose that i want to process the data for 1 to 100 comany codes, i will process 10 company codes at a time..

Thanks and Best Regards,

Vikas Bittera.

Read only

Former Member
0 Likes
1,163

If you use Packet size, you do not need to specify number of rows or special keys - just give the full select and it returns a new packet of record each time it loops between the select and endselect statements.

Andrew

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,163

You should define a CURSOR and then read the data package via this cursor.

* Declare cursor
DATA s_cursor TYPE cursor.
* Open Cursor (select)
      OPEN CURSOR WITH HOLD s_cursor FOR
        Select * from {table} 
               where key-field1 = field1
               and     key-field2 = field2
               …
               and     key-fieldn = fieldn.
* Then Fetch the data 
DO.
  FETCH NEXT CURSOR s_cursor
               INTO TABLE t_data
               PACKAGE SIZE package_size.
  IF SY-SUBRC <> 0. " No more data
    EXIT.
  ELSE.
    " Work with the data read
  ENDIF.
ENDDO.
* When you have read all the data, close the cursor
      CLOSE CURSOR s_cursor.

Regards