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

Simple problem,but not understanding why the program behaves so.

Former Member
0 Likes
1,355

Hi All,

I am facing a peculiar problem while debugging a code which is written long back by someone.I will copy the code n then will explain whats the issue.

-


Code Starts -


select bukrs belnr gjahr bldat xblnr into table i_bkpf

from bkpf where

bukrs = w_bukrs and

gjahr = w_fyear and

budat in w_budat.

if sy-subrc ne 0.

message e034 with 'No records found'.

endif.

clear : i_bseg, i_bseg[].

select bukrs belnr gjahr koart hkont shkzg sgtxt wrbtr lifnr

into table i_bseg from bseg for all entries in i_bkpf where

bukrs = i_bkpf-bukrs and

belnr = i_bkpf-belnr and

gjahr = i_bkpf-gjahr and

koart = 'S' and

hkont in w_hkont.

-


Code End -


Now the problem is

the belnr fetched from bkpf for the i/p give are

5000000158

5100000112

5000000159

5100000113

while selecting from bseg table(the second select stmnt) the BELNR coming in the program based on i_bkpf are

5100000112

5100000113

5100000113 ,

where as thru se16,BSEG table giving the following o/p for the same input fields

5100000112

5100000112

5100000112

5100000113

5100000113

What i mean to say is , 5100000112 is appearing only once in the program o/p and actually 3 line items are ter in the table. i put same condition in table as of in the program to fetch the data.only difference i found is out of 3 line items of 5100000112 ,2 have same ETTAX value.But tat is not at all a criteria for selection in the select statemnet.

Hope u may have understood the problem.Can any body help me.

Thanks ,

Nithin

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,306

Hello,

while selecting data from BSEG select field BUZEI (Number of Line Item Within Accounting Document) also.

Your code should be like this:

select bukrs belnr gjahr bldat xblnr into table i_bkpf

from bkpf where

bukrs = w_bukrs and

gjahr = w_fyear and

budat in w_budat.

if sy-subrc ne 0.

message e034 with 'No records found'.

endif.

clear : i_bseg, i_bseg[].

If not i_bkpf[] is initial.

select bukrs belnr gjahr BUZEI koart hkont shkzg sgtxt wrbtr lifnr

into table i_bseg from bseg for all entries in i_bkpf where

bukrs = i_bkpf-bukrs and

belnr = i_bkpf-belnr and

gjahr = i_bkpf-gjahr and

koart = 'S' and

hkont in w_hkont.

endif.

Edited by: Arindam Ganguly on Dec 10, 2008 8:18 AM

Hi All,

I am facing a peculiar problem while debugging a code which is written long back by someone.I will copy the code n then will explain whats the issue.

-


Code Starts -


select bukrs belnr gjahr bldat xblnr into table i_bkpf

from bkpf where

bukrs = w_bukrs and

gjahr = w_fyear and

budat in w_budat.

if sy-subrc ne 0.

message e034 with 'No records found'.

endif.

clear : i_bseg, i_bseg[].

select bukrs belnr gjahr koart hkont shkzg sgtxt wrbtr lifnr

into table i_bseg from bseg for all entries in i_bkpf where

bukrs = i_bkpf-bukrs and

belnr = i_bkpf-belnr and

gjahr = i_bkpf-gjahr and

koart = 'S' and

hkont in w_hkont.

-


Code End -


Now the problem is

the belnr fetched from bkpf for the i/p give are

5000000158

5100000112

5000000159

5100000113

while selecting from bseg table(the second select stmnt) the BELNR coming in the program based on i_bkpf are

5100000112

5100000113

5100000113 ,

where as thru se16,BSEG table giving the following o/p for the same input fields

5100000112

5100000112

5100000112

5100000113

5100000113

What i mean to say is , 5100000112 is appearing only once in the program o/p and actually 3 line items are ter in the table. i put same condition in table as of in the program to fetch the data.only difference i found is out of 3 line items of 5100000112 ,2 have same ETTAX value.But tat is not at all a criteria for selection in the select statemnet.

Hope u may have understood the problem.Can any body help me.

Thanks ,

Nithin

8 REPLIES 8
Read only

Former Member
0 Likes
1,306

Hi,

For second select Quary ur using for all enries

So use

if i_bkpf is not initial.

Select for bseg

end if.

and also put all primary key in where condition i.e bseg table bkpf common field compare all fields.

And ur giving Hard code value "S" check this value is in all field

try this.

Edited by: upender verma on Dec 10, 2008 8:08 AM

Read only

Former Member
0 Likes
1,306

hi,,,,,

In your code it is not written any where that same values should come only once, if 5100000112 is coming once then all the values are different in bseg table and your selection condition matches with only one record but in case of 5100000113 your selection condition matches with 2 records simple. you must be making some mistake in checking otherwise it is not possible.

just check

bukrs = i_bkpf-bukrs and

belnr = i_bkpf-belnr and

gjahr = i_bkpf-gjahr and

koart = 'S' and

hkont in w_hkont.

these values in se16 for 5100000112 & 5100000113 you will find the answer.

Thanks

Saurabh

Read only

Former Member
0 Likes
1,306

Check the KOART values and of course Fiscal year...

You might be having same document numbers for different fiscal years(gjahr)

pk

Read only

vinod_vemuru2
Active Contributor
0 Likes
1,306

Hi Nitin,

FOR ALL ENTRIEs automatically deletes the duplicates based on selected fields.

*So select all the primary Keys of BSEG.

What does range w_hkont contains? May be this condition or KOART condition might be failing. Check this in BSEG.

Thanks,

Vinod.

Read only

Former Member
0 Likes
1,307

Hello,

while selecting data from BSEG select field BUZEI (Number of Line Item Within Accounting Document) also.

Your code should be like this:

select bukrs belnr gjahr bldat xblnr into table i_bkpf

from bkpf where

bukrs = w_bukrs and

gjahr = w_fyear and

budat in w_budat.

if sy-subrc ne 0.

message e034 with 'No records found'.

endif.

clear : i_bseg, i_bseg[].

If not i_bkpf[] is initial.

select bukrs belnr gjahr BUZEI koart hkont shkzg sgtxt wrbtr lifnr

into table i_bseg from bseg for all entries in i_bkpf where

bukrs = i_bkpf-bukrs and

belnr = i_bkpf-belnr and

gjahr = i_bkpf-gjahr and

koart = 'S' and

hkont in w_hkont.

endif.

Edited by: Arindam Ganguly on Dec 10, 2008 8:18 AM

Read only

0 Likes
1,306

Hi Arindam Ganguly n all,

I did the change by including BUZEi ,now its working properly.

But i didn't exactly understood y the program was not able to identify the 3 line items with the provided selection criteria ,where as table was able to do,even without providing the value for filed BUZEI.

If possible plz tell it.

Thanks a Lot.

Thank u all.

Nithin

Read only

0 Likes
1,306

Hi,

The reason is you have used FOR ALL ENTRIES.

With for all entries, you always have to select all key fields from the target table. This statement will automatically remove the duplicates from the selected data by comparing the selected fields. That is the reason you were getting only one record instead of 3. BUZEI field value differentiates the 3 records.

If you don't use all key fields, FOR ALL ENTRIES will not give the expected result because of the above reason. Hope this is clear to you.

Thanks,

Lakshmi

Read only

Former Member
0 Likes
1,306

hi nitin,

ur code is behaving in this peculiar manner because ur using for all entries.

when we are using for all entries, what happens ( in ur case for example)

ur fetching values from bseg for all entreis in i_bkpf.

so when there are multiple records in the bseg (multiplicity will be checked only on the keys that u have given in as the filter criteria), it will only fetch the top most value (the most recent entry in the table).

so if u want all the records from bseg as given by se16, provide as many fields in the selection as possible.

better - check which fields are different amongts the multiple recods and then use those filds in the filter criteria.

let me know if this answer was helpful.