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

regarding select statement

Former Member
0 Likes
1,224

select belnr " to get the data from bkpf for the given compnay code date range and for the particular user

bukrs

budat

gjahr

bstat

budat

from bkpf

into corresponding fields of table ig_bkpf

for all entries in ig_ypctrusr

where bukrs = p1 and

budat in budat and

usnam = ig_ypctrusr-usnam.

select belnr

bukrs

gjahr

dmbtr

prctr

pprct

sgtxt

hkont

from bseg

into corresponding fields of table ig_bseg

for all entries in ig_bkpf

where belnr = ig_bkpf-belnr and

bukrs = ig_bkpf-bukrs and

gjahr = ig_bkpf-gjahr and

prctr in prctr and

pprct in pprct and

hkont = '0000150203'.

i am using this code

now there is no data in ig_bkpf

but when it is selectig data from bseg it is selecting all the data from bseg

can any body tell why this is hapening.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,204

Hi

Write

<b>if not ig_bkpf[] is initial.</b>

select belnr

bukrs

gjahr

dmbtr

prctr

pprct

sgtxt

hkont

from bseg

into corresponding fields of table ig_bseg

for all entries in ig_bkpf

where belnr = ig_bkpf-belnr and

bukrs = ig_bkpf-bukrs and

gjahr = ig_bkpf-gjahr and

prctr in prctr and

pprct in pprct and

hkont = '0000150203'.

<b>endif.

Reward points for useful Answers</b>

Regards

Anji

13 REPLIES 13
Read only

Former Member
0 Likes
1,205

Hi

Write

<b>if not ig_bkpf[] is initial.</b>

select belnr

bukrs

gjahr

dmbtr

prctr

pprct

sgtxt

hkont

from bseg

into corresponding fields of table ig_bseg

for all entries in ig_bkpf

where belnr = ig_bkpf-belnr and

bukrs = ig_bkpf-bukrs and

gjahr = ig_bkpf-gjahr and

prctr in prctr and

pprct in pprct and

hkont = '0000150203'.

<b>endif.

Reward points for useful Answers</b>

Regards

Anji

Read only

0 Likes
1,204

hi anji can oyu please tell m,e why this was happening even after the table ig_bkpf is empty why it is selecting all the data from bseg when we are using FOR ALL ENTRIES statement

it should look into bseg only for those records which are in ig_bkpf .

and since it is empty why it is taking al the records from bseg

can you please clear this doubt

Read only

Former Member
0 Likes
1,204

hi,

check like this,

if not ig_bkpf[] is initial.

select belnr

bukrs

gjahr

dmbtr

prctr

pprct

sgtxt

hkont

from bseg

into corresponding fields of table ig_bseg

for all entries in ig_bkpf

where belnr = ig_bkpf-belnr and

bukrs = ig_bkpf-bukrs and

gjahr = ig_bkpf-gjahr and

prctr in prctr and

pprct in pprct and

hkont = '0000150203'.

endif.

regards,

seshu.

Read only

Former Member
0 Likes
1,204

Hi Ashish,

That is normal.

The rule for using "For all entries" is that on which internal table you are using For all entries that should not be empty so put your second select in The condition

If not it_bseg[] is iinitial.

Put your select here.

Endif.

Read only

Former Member
0 Likes
1,204

Hi Ashish ,

This is one very important point we need to consider when we use FOR ALL ENTRIES , if there are no records in the internal table then it will ignore the internalt table in the where clause and consider all other options .

In your case it will get all records which satisfy the condition

prctr in prctr and

pprct in pprct and

hkont = '0000150203'..

So it is always said to check if the internal table has records before we actually process for all entries.

if there are no entries the select statement must not be processed .

Use an IF condition to implement it.

Regards

Arun

Read only

Former Member
0 Likes
1,204

Hi Ashish,

Select data from BSEG only if ig_bkpf is not initial.

Use

if ig_bkpf[] is not initial.

select ....from BSEG

endif.

Regards,

Suruchi

Read only

Former Member
0 Likes
1,204

while using for all entries statement,first u have to check weather the table is empty or not.if the first itab is initial it will return all records from second table.

use this code.

if not ig_bseg[] is initial.

select statement.

endif.

Read only

Former Member
0 Likes
1,204

Hi,

Just remember that whenever you are using FOR ALL ENTRIES,make sure to check whether the internal table is empty or not.

Only when the table is not empty proceed to do the select.

Hope this will solve your problem.

Thanks,

Sandeep.

Read only

Former Member
0 Likes
1,204

You need to check that the internal table is not initial before running for all entries.

Else it gives all the data from the table.

regards,

Read only

Former Member
0 Likes
1,204

Hi,

Whenever u use FOR ALL ENTRIES for selecting data, then if ITTAB is initial check has to be done .

In ur case,

For the 2nd select query,

If ig_bkpf is not initial.

select belnr

bukrs

gjahr

dmbtr

prctr

pprct

sgtxt

hkont

from bseg

into corresponding fields of table ig_bseg

for all entries in ig_bkpf

where belnr = ig_bkpf-belnr and

bukrs = ig_bkpf-bukrs and

gjahr = ig_bkpf-gjahr and

prctr in prctr and

pprct in pprct and

hkont = '0000150203'.

endif.

Now, this wil select the required records as per ur query.

****reward points if useful.

All the best

Read only

Former Member
0 Likes
1,204

Hi ashish,

SELECT query is fetching all the data from BSEG as the internal in FOR ALL ENTRIES is empty.

When this table is empty it assumes to fetch all the data hence....the result.

Just make the necessary changes as shown and your problem will be solved.



select belnr " to get the data from bkpf for the given compnay code date range and for the particular user
bukrs
budat
gjahr
bstat
budat
from bkpf
into corresponding fields of table ig_bkpf
for all entries in ig_ypctrusr
where bukrs = p1 and
budat in budat and
usnam = ig_ypctrusr-usnam.

<b>if not ig_bkpf is initial.</b>

select belnr
bukrs
gjahr
dmbtr
prctr
pprct
sgtxt
hkont
from bseg
into corresponding fields of table ig_bseg
for all entries in ig_bkpf
where belnr = ig_bkpf-belnr and
bukrs = ig_bkpf-bukrs and
gjahr = ig_bkpf-gjahr and
prctr in prctr and
pprct in pprct and
hkont = '0000150203'.

<b>endif.</b>

Thanks and Regards,

Kunjal Patel

Read only

Former Member
0 Likes
1,204

HI.

Before use " for all entries itab" we should check first table (ig_bkpf

)should not be initial. if its initial it will go to DUMP.so we need to check initial condition.

If use all entries in your slelect quary it will fecth all records based on first internal table (ig_bkpf) to second internal table (ig_bseg)

Rewards all helpfull ansewrs .

Regrads.

Jay

Read only

Former Member
0 Likes
1,204

Hi

Write

if not ig_bkpf[] is initial.

select belnr

bukrs

gjahr

dmbtr

prctr

pprct

sgtxt

hkont

from bseg

into corresponding fields of table ig_bseg

for all entries in ig_bkpf

where belnr = ig_bkpf-belnr and

bukrs = ig_bkpf-bukrs and

gjahr = ig_bkpf-gjahr and

prctr in prctr and

pprct in pprct and

hkont = '0000150203'.

endif.

if your first internal table is not filled then the second internal table will be filled with the records which satisfy the condition mentioned in the selec quaery.