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: 

Experts modify this code

Former Member
0 Kudos

Hello Experts please solve this

select mblnr into table itab1

from mkpf

where budat in s_budat

and vgart = 'WE'.

select mblnr into table itab2

from mkpf

where budat in s_budat

and vgart = 'WO'.

I modified the above query as

select mblnr into table itab1

from mkpf

where budat in s_budat

and ( vgart = 'WE'or vgart = 'WO').

Now please tell me how to modify the below query because we have to select data only from itab1 entrieswhere vgart= we only.But in above we selected vgart = 'wo' into itab1.

select mblnr matnr bwart menge into table lt_menge

from mseg

for all entries in itab1.

where mblnr = lt_we-mblnr

and matnr = it_temp-matnr

and werks = p_werks

and bwart in ('501', '502').

5 REPLIES 5

Former Member
0 Kudos

Hi Shiva,

You need to create another internal table with the same type of itab1 and move the data corresponding to WE and use that for querying MSEG.

Regards,

Atish

gopi_narendra
Active Contributor
0 Kudos

loop at itab1 where vgart = 'WE'.

move itab1 to itab2.

append itab2.

endloop.

now use itab2 in the for all entries.

Regards

Gopi

Former Member
0 Kudos

select mblnr into table itab1 from mkpf where budat in s_budat

and vgart = 'WE'.

select mblnr into table itab2 from mkpf where budat in s_budat

and vgart = 'WO'.

I modified the above query as

select mblnr into table itab1 from mkpf

where budat in s_budat

and vgart in ('WE' , 'WO').

Now please tell me how to modify the below query because we have to select data only from itab1 entrieswhere vgart= we only.But in above we selected vgart = 'wo' into itab1.

decleare another internal table move it.

itab3

itab3 = itab2.

select mblnr matnr bwart menge into table lt_menge

from mseg for all entries in itab1.

where mblnr = lt_we-mblnr

and matnr = it_temp-matnr

and werks = p_werks

and bwart in ('501', '502').

Former Member
0 Kudos

Hi,

best way use only one query as :

select a~mblnr a~mjahr b~matnr b~bwart b~menge
from mkpf as a inner join mseg as b
into table itab_mseg
on a~mblnr = b~mblnr and a~mjahr = b~mjahr
where a~budat in s_budat and
(a~vgart = 'WE' or a~vgart = 'WO') and
and b~werks = p_werks
and b~bwart in ('501', '502').

this is most optimised format i think ...

in for all entries u can not give criteria on internal table.

Jogdand M B

*Reward pts if helpful

Message was edited by:

Jogdand M B

Former Member
0 Kudos

Hi Shiva,

This is very simple

> Hello Experts please solve this

>

<b>Don't use this. Select both of them in the same table as you did but with some correction.</b>

> select mblnr into table itab1

> from mkpf

> where budat in s_budat

> and vgart = 'WE'.

> select mblnr into table itab2

> from mkpf

> where budat in s_budat

> and vgart = 'WO'.

>

> I modified the above query as

select mblnr VGART into table itab1
 from mkpf
 where budat in s_budat
   and VGART in ( 'WE' , 'WO' )

<b> modified the line</b>

> and ( vgart = 'WE'or vgart = 'WO').

> Now please tell me how to modify the below query

> because we have to select data only from itab1

> entrieswhere vgart= we only.But in above we selected

> vgart = 'wo' into itab1.

For this what you can do is simpler now.

Create another table itab2 with field MBLNR and VGART.

Write

   
   Loop at itab1 where VGART =  'WE'.
     MOVE itab2 = itab1.
     APPEND itab2.
   Endloop.

> select mblnr matnr bwart menge into table lt_menge

> from mseg

> for all entries in itab1.

> where mblnr = lt_we-mblnr

> and matnr = it_temp-matnr

> and werks = p_werks

> and bwart in ('501', '502').

Now you can re-write this as :


 select mblnr matnr bwart menge into table lt_menge
 from mseg
 for all entries in ITAB2
 where mblnr = ITAB2-mblnr
 and matnr = it_temp-matnr
 and werks = p_werks
 and bwart in ('501', '502').

<b>hope the above solves your issue</b>

Regards

Nishant