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

select

Former Member
0 Likes
864

i am using this piece of code to fetch data from bseg.

but for a aprticular record of t_final it is not picking all the records ofrm bseg,can u tell me why

for example there is record 1 in t_final and for record 1 there are 8 records in bseg

but it iselectin only 4 records out of 8

IF t_final IS NOT INITIAL.

SELECT bukrs

belnr

gjahr

augdt

koart

shkzg

dmbtr

kostl

aufnr

saknr

hkont

kunnr

lifnr

zfbdt

projk

FROM BSEG INTO TABLE t_bseg

FOR ALL ENTRIES IN t_final

WHERE bukrs = t_final-bukrs

AND belnr = t_final-belnr

AND gjahr = t_final-gjahr

AND koart NE 'K'.

ENDIF.

8 REPLIES 8
Read only

Former Member
0 Likes
838

Hi,

refer to the below mentioned code....

tables: vbak, vbap.

select-options: s_vbeln for vbak-vbeln.

types:

begin of t_vbak,

vbeln like vbak-vbeln,

erdat like vbak-erdat,

ernam type vbak-ernam,

netwr type vbak-netwr,

end of t_vbak,

begin of t_vbap,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

arktx type vbap-arktx,

matnr like vbap-matnr,

meins like vbap-meins,

end of t_vbap,

begin of lt_report,

vbeln like vbak-vbeln,

erdat like vbak-erdat,

ernam type vbak-ernam,

netwr type vbak-netwr,

posnr like vbap-posnr,

arktx type vbap-arktx,

matnr like vbap-matnr,

meins like vbap-meins,

end of lt_report.

data:

li_vbak type t_vbak occurs 0 with header line,

li_vbap type t_vbap occurs 0 with header line,

t_report type lt_report occurs 0 with header line.

at selection-screen.

start-of-selection.

select vbeln erdat ernam netwr

from vbak

into table li_vbak package size 10 where vbeln in s_vbeln.

if not li_vbak[] is initial.

sort li_vbak by vbeln.

  • DELETE ADJACENT DUPLICATES FROM li_vbak.

select vbeln posnr arktx matnr meins

from vbap

into table li_vbap

for all entries in li_vbak

where vbeln = li_vbak-vbeln.

endif.

loop at li_vbap.

t_report-vbeln = li_vbap-vbeln.

t_report-posnr = li_vbap-posnr.

t_report-arktx = li_vbap-arktx.

t_report-matnr = li_vbap-matnr.

t_report-meins = li_vbap-meins.

read table li_vbak with key vbeln = li_vbap-vbeln.

if sy-subrc = 0.

t_report-vbeln = li_vbak-vbeln.

t_report-erdat = li_vbak-erdat.

t_report-ernam = li_vbak-ernam.

t_report-netwr = li_vbak-netwr.

endif.

append t_report.

clear li_vbap.

endloop.

refresh: li_vbak, li_vbap.

sort t_report by vbeln.

  • DELETE ADJACENT DUPLICATES FROM t_report.

endselect.

end-of-selection.

sort t_report by vbeln.

loop at t_report.

write: / t_report-vbeln, t_report-erdat, t_report-ernam,

t_report-netwr, t_report-posnr, t_report-arktx,

t_report-matnr, t_report-meins.

endloop.

loop at t_bseg.
.................................
...........................
Read table t_final........................

This will solve ur prob. Reward all helpful answers,

Thanks

Edited by: Sagar@MM on May 30, 2008 2:58 PM

Read only

Former Member
0 Likes
838

Hi,

the 4 records which are not picked might not be satisfying the conditions:

bukrs = t_final-bukrs

AND belnr = t_final-belnr

AND gjahr = t_final-gjahr

AND koart NE 'K'.

make sure those 4 records are havign the values same as the compared record from t_final.

Read only

vinod_vemuru2
Active Contributor
0 Likes
838

Hi,

First check the data of BSEG in se16 for these conditions.

bukrs = t_final-bukrs

AND belnr = t_final-belnr

AND gjahr = t_final-gjahr

AND koart NE 'K'.

Problem will be because of hilighted condition. Out of 8 records may be only 4 records will be matching(For which koart NE K.) If this is not the case the the problem will be because of duplicates.

For all entries will automatically filters duplicates Check this also.

Apart from above i dont thing there will be any problem.

Thanks,

Vinod.

Read only

Former Member
0 Likes
838

Hi,

Try to retrieve complete primary key combination when use FOR ALL ENTRIES addition to the SELECT statement. So u need to change the declaration of internal table and select query as like below.

IF t_final IS NOT INITIAL.

SELECT bukrs

belnr

gjahr

BUZEI <add this field in your internal table declarion>

augdt

koart

shkzg

dmbtr

kostl

aufnr

saknr

hkont

kunnr

lifnr

zfbdt

projk

FROM BSEG INTO TABLE t_bseg

FOR ALL ENTRIES IN t_final

WHERE bukrs = t_final-bukrs

AND belnr = t_final-belnr

AND gjahr = t_final-gjahr

AND koart NE 'K'.

ENDIF.

Because the for all entries addition always returns the records from table and also will do the delete adjacent duplicates from the internal table.

Rgds,

Bujji

Read only

Former Member
0 Likes
838

Hi as you sed is not fetching for other 4 records ..

It is due to this statement which u wrote ..

for all entires

Have a look at that once..

and second the where clause..

Regards

Basheer

Read only

Former Member
0 Likes
838

Pls check the records by giving the value of the internal table in se16 and see how many records are gettting for that values .

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
838

I too agree madhumitha's comment

Read only

Former Member
0 Likes
838

DO Debuging n check in table t_final how many records are comming. If it is having four records only den it will display those four records.

n also check ds condition koart NE 'K'.

Regards,

Mehul.