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: 

urgent pls help me

Former Member
0 Kudos

Hi,

I wanted suggestion from you experts. I need to write one select query but that is very much

complicated.

Actually I have to fetch the records from table MARA, MBEW, MARC & MAKT table. The fields I

needed are MARA-MATNR, MEINS, EXTWG, MTART (from mara table) & MBEW-SPRAS, MAKT-MAKTX.

I need to select the records based on p_werks & material no should be start with '12'.

Could anybody will suggest me the query for this??

4 REPLIES 4

Former Member
0 Kudos

HI,

Use this

select * from mara into table itab where werks = p_werks and matnr like '12%'.

Thansk

mahesh

Former Member
0 Kudos

MBEW does not cojntain SPRAS. Did you want that from MAKT?

Additionally, MATNR has a conversion exit. So, when you say "start with '12''", do you mean that the first characters are '12' or do you mean the first non-zero characters are '12'? It's a big difference.

Rob

Message was edited by:

Rob Burbank

Former Member
0 Kudos

See the below code :

tables : mara,

makt,

marc,

mbew.

data : begin of itab occurs 0,

matnr like mara-matnr,

meins like mara-meins,

extwg like mara-extwg,

mtart like mara-mtart,

stprs like mbew-stprs,

end of itab.

data : begin of i_final occurs 0,

matnr like mara-matnr,

meins like mara-meins,

extwg like mara-extwg,

mtart like mara-mtart,

stprs like mbew-stprs,

maktx like makt-maktx,

end of i_final.

parameters p_werks like marc-werks.

start-of-selection.

select amatnr ameins aextwg amtart b~stprs into table itab

from mara as a inner join mbew as b on amatnr = bmatnr

inner join marc as c on cmatnr = amatnr

where a~matnr like '12%'

and c~werks = p_werks.

if sy-subrc ne 0.

  • message

endif.

loop at itab.

select single maktx from makt into makt

where matnr = itab-matnr

and spras = 'EN'.

if sy-subrc eq 0.

i_final-maktx = makt-maktx.

endif.

move itab-matnr to i_final-matnr.

move itab-meins to i_final-meins.

move itab-extwg to i_final-extwg.

move itab-mtart to i_final-mtart.

move itab-stprs to i_final-stprs.

append i_final.

endloop.

MBEW does not have spras,i guess it should be STPRS,and also while selection MBEW Table,we need to have key fields like valuation related field

Thanks

Seshu

Former Member
0 Kudos

You should go to MARC first with p_werks and get all the materials for that plant. Removing the materials that start with 12 is little tricky as they may start with 12 in their output format but they will have leading zeros within the database. So you will have to do that in a loop.

data: v_matnr_ext like mara-matnr.

loop at marc_matnrs.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'

EXPORTING

input = marc_matnrs-matnr

IMPORTING

output = v_matnr_ext.

if v_matnr_ext+0(2) = '12'.

delete marc_matnrs.

continue.

endif.

*-- Now get the rest of the information from MARA, MAKT and MBEW as they all will be SELECT SINGLEs except that MBEW-BWTAR may not be blank in your case. BWKEY will be same as your plant.

once you get all the necessary information, fill in the output table and append.

endloop.