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

Lost data in a Select with INTO TABLE

silvio_messias
Participant
0 Likes
1,275

Hi gurus!

I have the following code:

SELECT knumv kposn kschl lifnr kwert

FROM konv

INTO TABLE l_i_konv

FOR ALL ENTRIES IN l_i_dv_knumv

WHERE knumv = l_i_dv_knumv-table_line

AND kappl = 'M'.

The internal table l_i_konv was defined as following:

TYPES:

BEGIN OF ty_konv,

knumv TYPE knumv,

kposn TYPE kposn,

kschl TYPE kscha,

lifnr TYPE lifnr,

kwert TYPE kwert,

END OF ty_konv.

DATA: l_i_konv TYPE TABLE OF ty_konv.

When I execute this code 20 occurs is filled in my internal table. However if I select data by TC SE16 I obtain 21 records.

I have noticed the lost data is duplicated if I see by SE16, as following:

knumv kposn kschl lifnr kwert

1003450881 00010 YMFX 0100128136 318,18

1003450881 00010 YMFX 0100128136 318,18

My question is… When I use the clause “INTO TABLE” does the system delete this kind of data like “DELETE ADJACENT DUPLICATES FROM itab”?

Thanks and regards,

Silvio Messias.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,217

Hi Silvio,

It does delete duplicates when you use the "FOR ALL ENTRIES" clause, not "INTO TABLE" - this is your problem.

Hi gurus!

I have the following code:

SELECT knumv kposn kschl lifnr kwert

FROM konv

INTO TABLE l_i_konv

FOR ALL ENTRIES IN l_i_dv_knumv

WHERE knumv = l_i_dv_knumv-table_line

AND kappl = 'M'.

The internal table l_i_konv was defined as following:

TYPES:

BEGIN OF ty_konv,

knumv TYPE knumv,

kposn TYPE kposn,

kschl TYPE kscha,

lifnr TYPE lifnr,

kwert TYPE kwert,

END OF ty_konv.

DATA: l_i_konv TYPE TABLE OF ty_konv.

When I execute this code 20 occurs is filled in my internal table. However if I select data by TC SE16 I obtain 21 records.

I have noticed the lost data is duplicated if I see by SE16, as following:

knumv kposn kschl lifnr kwert

1003450881 00010 YMFX 0100128136 318,18

1003450881 00010 YMFX 0100128136 318,18

My question is… When I use the clause “INTO TABLE” does the system delete this kind of data like “DELETE ADJACENT DUPLICATES FROM itab”?

Thanks and regards,

Silvio Messias.

9 REPLIES 9
Read only

Former Member
0 Likes
1,217

Check whether there are any duplicates in the table l_i_dv_knumv.

INTO TABLE does NOT do any delete adjacent duplicates.

For more perfect answer paste your code here.

Rds,

Naren

Read only

Former Member
0 Likes
1,218

Hi Silvio,

It does delete duplicates when you use the "FOR ALL ENTRIES" clause, not "INTO TABLE" - this is your problem.

Read only

former_member194669
Active Contributor
0 Likes
1,217

Hi,


loop at  l_i_dv_knumv.
SELECT knumv kposn kschl lifnr kwert
FROM konv
appending table TABLE l_i_konv
WHERE knumv = l_i_dv_knumv-table_line
AND kappl = 'M'.
endloop.

If your l_i_dv_knumv < 500 use select inside loop. otherwise please don't use this. it has performance impact.

aRs

Message was edited by:

aRs

Read only

0 Likes
1,217

> Hi,

>

>


> loop at  l_i_dv_knumv.
> SELECT knumv kposn kschl lifnr kwert
> FROM konv
> appending table TABLE l_i_konv
> WHERE knumv = l_i_dv_knumv-table_line
> AND kappl = 'M'.
> endloop.
> 
> 

>

> aRs

This is not a good pratice because you will do lots of acces to the database server, and your programa performance will get worse.

You should avoid using select statements inside loops.

Regards

Read only

Former Member
0 Likes
1,217

Hi Silvio,

"My question is… When I use the clause “INTO TABLE” does the system delete this kind of data like “DELETE ADJACENT DUPLICATES FROM itab”?"

No it doesn't. If you are using a normal select statement it will select all data found.

The system will delete duplicate data when you use the clause "SELECT DISTINCT" or the adition "FOR ALL ENTRIES"

Reward points if helpful please.

Regards

Read only

Former Member
0 Likes
1,217

Silvio,

Have you ever used a range?

You can set a range with your internal table values and declare your where clause as

WHERE <FIELD> IN <RANGE> .

I think this would solve your problem.

Read only

Former Member
0 Likes
1,217

Hi Silvio,

I also faced the same problem long back, But I dont know the reson why its behaving like this.

Some times it will not fetch all the records, you can resolve this by specify all the key fields in select query and the target internal table.

Read only

Former Member
0 Likes
1,217

Hi Silvo,

The reason for this is that you are not selecting all the key fields of the table KONV.

YOu should select all the Keu fields of the table KONV when you are using a for all entries statement.

SELECT knumv

kposn

<b>STUNR

ZAEHK</b>

kschl lifnr kwert

FROM konv

INTO TABLE l_i_konv

FOR ALL ENTRIES IN l_i_dv_knumv

WHERE knumv = l_i_dv_knumv-table_line

AND kappl = 'M'.

Change the declaration of your in tab like this:

TYPES:

BEGIN OF ty_konv,

knumv TYPE knumv,

kposn TYPE kposn,

<b>STUNR type STUNR,

ZAEHK type ZAEHK,</b>

kschl TYPE kscha,

lifnr TYPE lifnr,

kwert TYPE kwert,

END OF ty_konv.

DATA: l_i_konv TYPE TABLE OF ty_konv.

Regards,

Ravi

Read only

0 Likes
1,217

Hi Naren, DanielY, aRs, Felipe Gelme, Mugnthan Kasipa, Ravi Kanth Tala!

Thanks for your answers!

Really the problem was happened because the clause "FOR ALL ENTRIES". I change the code and now is perfect!

Regards,

Silvio Messias