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 max from internal table

Former Member
0 Likes
1,006

Hi,

i have the following internal table :

Matnr werks lgort year period

|000000000007000007|3010 |100 |2008 | 04

|000000000007000007|3010 |100 |2008 | 05

|000000000007000007|3010 |500 |2008 | 05

|000000000007000008|3010 |100 |2008 | 05

|000000000007000008|3010 |500 |2006 | 05

|000000000007000008|3010 |500 |2008 | 05

i need the following result :

000000000007000007|3010 |100 |2008 | 05

000000000007000007|3010 |500 |2008 | 05

000000000007000008|3010 |100 |2008 | 05

000000000007000008|3010 |500 |2008 | 05

it means that i need the max "period" for each matnr werks lgort year.

i can sort the table by matnr werks lgort year period DESCENDING.

An then, what is the step ?

thanks a lot, full points if helpul,

Mário.

1 ACCEPTED SOLUTION
Read only

former_member491305
Active Contributor
0 Likes
584

Hi Mario,

Here it is...

1.First you have to sort itab by all the 5 field with period alone as descending.

2.While Deleting adjacent duplicates remove "period" field.

sample code:

Sort itab by matnr werks lgort year period descending.*

Delete Adjacent duplicates from itab comparing matnr werks lgort year.

Regards,

Vigneswaran S

4 REPLIES 4
Read only

Former Member
0 Likes
584

Hi,

The best way would be in selection with MAX and GROUP BY.

You wrote right, using sort, after using loop with comparing the fields changes.

Hope it helps.

Read only

0 Likes
584

thanks for your answer !!

but can i put the code to check the changes ? i tryed but with no success !!

thanks in advance,

Mário.

Read only

Former Member
0 Likes
584

After your sort use:


DELETE ADJACENT DUPLICATES FROM itab COMPARING matnr werks lgort year.

and you will have the result you want.

Greetings,

Gert

Read only

former_member491305
Active Contributor
0 Likes
585

Hi Mario,

Here it is...

1.First you have to sort itab by all the 5 field with period alone as descending.

2.While Deleting adjacent duplicates remove "period" field.

sample code:

Sort itab by matnr werks lgort year period descending.*

Delete Adjacent duplicates from itab comparing matnr werks lgort year.

Regards,

Vigneswaran S