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

Why it is doing this?

Former Member
0 Likes
1,256

I have this piece of code:

select bukrs

hkont

belnr

waers

shkzg

wrbtr

prctr

into corresponding fields of table t_bsis

from bsis

for all entries in t_bukrs_rbeln

where bukrs eq t_bukrs_rbeln-bukrs

and zuonr eq p_sys

and gjahr eq p_gjahr.

When the table t_bukrs_rbeln has items, the select is correct but, I noticed that, when the table t_bukrs_rbeln is empty, then the select brings ALL the entries from the table bsis.

I can nest this code in an "if bsis is not empty then ....", but I want to know why this select is doing this.

TIA

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,225

Hi,

If the for all entries table is empty, it will bring all the records. u need to implement a check that that itab should not be empty before executing select.

<b>IF NOT t_bukrs_rbeln[] IS INITIAL.</b>

select bukrs

hkont

belnr

waers

shkzg

wrbtr

prctr

into corresponding fields of table t_bsis

from bsis

for all entries in t_bukrs_rbeln

where bukrs eq t_bukrs_rbeln-bukrs

and zuonr eq p_sys

and gjahr eq p_gjahr.

<b>ENDIF.</b>

Sreedhar

I have this piece of code:

select bukrs

hkont

belnr

waers

shkzg

wrbtr

prctr

into corresponding fields of table t_bsis

from bsis

for all entries in t_bukrs_rbeln

where bukrs eq t_bukrs_rbeln-bukrs

and zuonr eq p_sys

and gjahr eq p_gjahr.

When the table t_bukrs_rbeln has items, the select is correct but, I noticed that, when the table t_bukrs_rbeln is empty, then the select brings ALL the entries from the table bsis.

I can nest this code in an "if bsis is not empty then ....", but I want to know why this select is doing this.

TIA

10 REPLIES 10
Read only

Former Member
0 Likes
1,226

Hi,

If the for all entries table is empty, it will bring all the records. u need to implement a check that that itab should not be empty before executing select.

<b>IF NOT t_bukrs_rbeln[] IS INITIAL.</b>

select bukrs

hkont

belnr

waers

shkzg

wrbtr

prctr

into corresponding fields of table t_bsis

from bsis

for all entries in t_bukrs_rbeln

where bukrs eq t_bukrs_rbeln-bukrs

and zuonr eq p_sys

and gjahr eq p_gjahr.

<b>ENDIF.</b>

Sreedhar

Read only

Former Member
0 Likes
1,225

Hi,

All entries selects all data when table is empty.

use

if not t_bukrs_rbeln is initial.

endif.

Regards

Amole

Read only

Former Member
0 Likes
1,225

that is because you are missing this..

<b>if not t_bukrs_rbeln[] is initial.</b>
select bukrs 
hkont 
belnr 
waers 
shkzg 
wrbtr 
prctr 
into corresponding fields of table t_bsis 
from bsis 
for all entries in t_bukrs_rbeln 
where bukrs eq t_bukrs_rbeln-bukrs 
and zuonr eq p_sys 
and gjahr eq p_gjahr.

<b>endif.</b>

Read only

Former Member
0 Likes
1,225

Hi,

When using FOR ALL ENTRIES in a select query, always check whether the internal table is empty or not.

eg.

if not itab is initial.

select bukrs

hkont

from bsis

into table it_bsis

for all entries in itab.......

endif.

This would skip the scenario which you are facing.

Best regards,

Prashant

Read only

0 Likes
1,225

Scott,

When ever you use 'for all entries' with an internal table, the select statement tries to pick up all records matching with the records in the internal table. If the internal table is empty then it will pick up all entries from the table you are selecting. So you always check whether the internal table is initial or not.

Thanks,

Message was edited by: Naren Somen

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,225

You must check that the table has entries before doing the SELECT FOR ALL ENTRIES. Its a good idea to make sure that it is sorted by the key.



check NOT t_bukrs_rbeln[] is initial.
sort t_bukrs_rbeln ascending by bukrs.

select bukrs 
hkont 
belnr 
waers 
shkzg 
wrbtr 
prctr 
into corresponding fields of table t_bsis 
from bsis 
for all entries in t_bukrs_rbeln 
where bukrs eq t_bukrs_rbeln-bukrs 
and zuonr eq p_sys 
and gjahr eq p_gjahr.

Regards,

Rich Heilman

Read only

0 Likes
1,225

FOR ALL ENTRIES IN itab always brings in all entries if itab is empty. Check this <a href="http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/content.htm">link</a>.

Read only

Former Member
0 Likes
1,225

Hi,

when <b>t_bukrs_rbeln</b> is initial

the select eliminates the where clause for the table

if u wnat to cross check

1) just put the break point before the select query. execute till there and stop

2) go to ST05

3) activate trace

4) again come back execute the select query

5) go back again to ST05 deactive the trace and see the log u will fine the selct query prepaid by the ABAP which run on the database.

Regards

Please mark Helpful Answers

4) come to the

Read only

Former Member
0 Likes
1,225

Hi Scott,

If you execute Table BSIS in SE16 without giving any field for selection, it will display all the BSIS records. Hence you need to check t_bukrs_rbeln internal table before selection from BSIS.

IF not t_bukrs_rbeln[] is initial.

select bukrs

hkont

belnr

waers

shkzg

wrbtr

prctr

into corresponding fields of table t_bsis

from bsis

for all entries in t_bukrs_rbeln

where bukrs eq t_bukrs_rbeln-bukrs

and zuonr eq p_sys

and gjahr eq p_gjahr.

endif.

Cheers,

Vikram

Pls reward for helpful replies!!

Read only

Former Member
0 Likes
1,225

Hi Scott

first u check this IF NOT t_bukrs_rbeln[] IS INITIAL.

if u dont have any values in t_bukrs_rbeln table then select will be skipped.i think this will help u...

IF NOT t_bukrs_rbeln[] IS INITIAL.

select bukrs

hkont

belnr

waers

shkzg

wrbtr

prctr

into corresponding fields of table t_bsis

from bsis

for all entries in t_bukrs_rbeln

where bukrs eq t_bukrs_rbeln-bukrs

and zuonr eq p_sys

and gjahr eq p_gjahr.

if sy-subrc = 0.

sort t_bukrs_rbeln by bukrs hkont belnr

endif.

Thanks

Vikranth Khimavath