Application Development 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: 

SELECT....FOR ALL ENTRIES

Former Member
0 Kudos

Hi SDN,

I am a BI developer and face the following problem.

I have a statement SELECT.FROM...INTO CORRESPONDING FIELDS OF itab_A..FOR ALL ENTRIES IN itab_B....WHERE.

Due to a certain scenario, there are no records in itab_B and I get an error message from SAP BI system that duplicate keys are being entered into the target itab_A.

For itab_A the dump shows TABLE[initial]. Does it mean it had no records?

If so, how could the statement cause duplicate rows in itab_A? I mean, if FOR ALL ENTRIES IN returns 0, records, shouldn't that cause no records in itab_A, much less an error message of duplicate keys?

Please advise.

Thanks.

SM

1 ACCEPTED SOLUTION

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

FOR ALL ENTRIES automatically deletes duplicates based in selected field list. How u have defined your itab? does your itab has explicit key defined? Try to define your itab as TYPE STANDARD TABLE OF.

Thanks,

Vinod.

5 REPLIES 5

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

FOR ALL ENTRIES automatically deletes duplicates based in selected field list. How u have defined your itab? does your itab has explicit key defined? Try to define your itab as TYPE STANDARD TABLE OF.

Thanks,

Vinod.

0 Kudos

Vinode,

The issue is that FOR ALL ENTRIES itab is empty.

The target itab, itab_A is a sorted table with a key of PO + Item. FOR ALL ENTRIES itab, itab_B is a standard table with the same key.

Please advise.

Thanks.

0 Kudos

Also,

A fellow developer says that due to itab_B having no rows, FOR ALL ENTRIES and the rest of WHERE clause is completely ignored and all the rows of the source table being added to itab_A causing a duplicate rows error.

Is that possible?

If itab_B, which is being used be FOR ALL ENTRIES is empty, shouldn't this return a null from all the WHERE comparisons and then return an empty itab_A?

Please advise.

Thanks.

0 Kudos

Hi,

Yes. What he/she says is correct. If the driver table is empty, FOR ALL ENTRIES retreives all the values from databse. There might be duplicate records from your database based on the key defined for your itab. When you define key you can't have duplicates.

PS: Place the check for driver table is not initial before the select. Define itab_a as standard table instead of sorted table.

Thanks,

Vinod.

0 Kudos

Hi,

If FOR AL ENTRIES internal table is initial, WHERE condition is ignored and all the records will be extracted from the table against which SELECT statement is executed. Before using FOR ALL ENTRIES, it is mandatory to check whether this table is initial or not.

Regards

Vinod