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 statement

Former Member
0 Likes
712

Hi all,

I need to retrieve records from mseg for some materials with respect to the lastest document of that particular material.

for example.

table : mseg

_____________

Doc No. Mat

001 a

002 a

011 b

012 b

____________

i need to retrieve doc 002 and 012 for mat a and b.

Thanks for ur suggestion,

Rajesh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
680

SELECT MATNR MAX(mblnr) into table itab

from mseg

group by matnr

where matnr in s_matnr.

Itab should have the required data

6 REPLIES 6
Read only

Former Member
0 Likes
680

Hi,

After retreiving the data from the table, sort the internal table on material document no and material in the descending sequence.

E.g.

sort itab by matnr mblnr descending.

Loop at itab1.

on change of itab-matnr.

read itab with key matnr = itab1-matnr.

endon.

endloop.

P.S. mark all helpful asnwers for points

JLN

Read only

Former Member
0 Likes
680

Hi,

Select MBLNR

MATNR

into table itab.

sort ITAB by MBLNR MATNR DESCENDING.

itab1[] = itab[].

LOOP AT ITAB.

AT NEW ITAB-MATNR.

read table itab1 index sy-tabix.

append itab1 into itfinal.

ENDAT.

ENDLOOP.

ITFINAL will have the req. records.

Best regards,

Prashant

Read only

Former Member
0 Likes
680

Hi,

You can use aggregate function MAX in the select statement.

Ex. select max ( MBLNR ) into table itab where

...

Hope this helps.

Read only

Former Member
0 Likes
680

i think its code help u.:

First sort table on docno & mat

sort T_mseg.

loop at T_mseg.

AT END OF NAME.

WRITE: / T_mseg-Doc, T_mseg-Mat.

ENDAT.

Endloop.

Read only

Former Member
0 Likes
681

SELECT MATNR MAX(mblnr) into table itab

from mseg

group by matnr

where matnr in s_matnr.

Itab should have the required data

Read only

0 Likes
680

Thanks Anurag and everybody for your help.

Rajesh.