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: 

How can i get just one row for every material no(MATNR) from MM tables?

Former Member
0 Kudos

Hi experts;

I want to get data form mara,mbew,mard tables. But i am getting one more rows for material no. How can i get just one row for every material no.

My query and internal table

DATA : BEGIN OF gv_itab OCCURS 0,

   matnr LIKE mara-matnr,"Malzeme Numarası

   bwkey LIKE mbew-bwkey,"Değerleme birimi

   bwtar LIKE mbew-bwtar,"Değerleme türü

   werks LIKE mard-werks,"Üretim yeri

   lgort LIKE mard-lgort,"Depo yeri

   maktx LIKE makt-maktx,"Malzeme kısa metni

   END OF gv_itab.

SELECT m~matnr mw~bwkey mw~bwtar md~werks mt~maktx mt~spras

       INTO CORRESPONDING FIELDS OF TABLE gv_itab

       FROM mara AS m

       JOIN mbew AS mw

       ON m~matnr = mw~matnr

       JOIN mard AS md

       ON m~matnr = md~matnr

       JOIN makt AS mt

       ON m~matnr = mt~matnr

       WHERE m~matnr   IN s_matnr AND

             mw~bwkey  IN s_bwkey AND

             mw~bwtar  IN s_bwtar AND

             md~werks  IN s_werks AND

             md~lgort  IN s_lgort AND

             mt~spras EQ 'TR'       .

Thanks for your help.

1 ACCEPTED SOLUTION

nabheetscn
Active Contributor
0 Kudos

You can sort gv_itab by matnr and delete adjacent duplicates. Please note that each line in your screenshot has UY column different value..do you want to delete them

Nabheet

14 REPLIES 14

former_member184569
Active Contributor
0 Kudos

Use select distinct matnr.

SELECT DISTINCT t2~field
  
FROM table1 AS t1
  
INNER JOIN table2 AS t2
  
ON t1~id = t2~id
  
INTO TABLE lt
  
WHERE (lv_where).

0 Kudos

I have used but i have same problem

Former Member
0 Kudos

Hi,

Don't understand the requirement, can you elaborate more! what exactly you want to display in the output!

Former Member
0 Kudos

You can write select distinct, but that is now obsolete from performance point of view.

Why don't you select all as updated above and the delete adjacent duplicates comparing MATNR.

Regards

Ansumesh

0 Kudos

My educator want to different way. He said me dont use distinct or adjent duplicates.

JL23
Active Contributor
0 Kudos

What is the purpose of this exercise?

How can you ask for a way without knowing the target?

Isn't it just stupid to pick randomly a plant out of many?

What meaning will the report have in that case?

nabheetscn
Active Contributor
0 Kudos

You can sort gv_itab by matnr and delete adjacent duplicates. Please note that each line in your screenshot has UY column different value..do you want to delete them

Nabheet

0 Kudos

LOOP AT gv_itab.

      DELETE ADJACENT DUPLICATES FROM gv_itab COMPARING werks.

     MODIFY gv_itab.

       ENDLOOP.


I used but i have same problem

0 Kudos

Hi Omer

As Jurgen correctly pointed out what is the purpose of which you are doing..? It will be good if you can provide the detail for the same..

BTW above code should look like below no loop..

sort gv_itab by matnr.

DELETE ADJACENT DUPLICATES FROM gv_itab COMPARING MATNR.

Nabheet

0 Kudos

I am trying to learn. They are saying it is your exercise then i am starting to do it. Jürgen is right absolutely but it is not solve my problem.

Thanks for your help.

former_member184569
Active Contributor
0 Kudos

Yes as mentioned above, from the performance point, it is not very efficient to use select distinct.

Rather, it would be better to filter the output internal table of the select statement.

loop at itab into wa_itab.

  at new matnr.

    continue.

  endat.

  delete itab from wa_itab .

endloop.

(Just make sure that matnr is the first field of your internal table. )

0 Kudos

how to set f4 help input field in webdynpro

0 Kudos

This message was moderated.

sivaprasad_paruchuri
Active Participant
0 Kudos

if u need sum of the quantities just collect after the query


LOOP AT gv_itab.

     collect gv_itab into gv_itab1.

       ENDLOOP.