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

Sorting and deleting internal table

Former Member
0 Likes
1,388

Hello,

I have a senario like this. I have internal table with 3 fields and my internal table is papulated like

A B C

123 X1 01/02/2007

123 X3 02/01/2007

126 X1 02/01/2007

123 X1 04/02/2007

123 X1 06/02/2007

123 X3 06/01/2007

126 X1 08/01/2007

Now I wanted have a output like

A B C

123 X1 06/02/2007

123 X3 06/01/2007

126 X1 08/01/2007

Any body tell me how can I achive this output.

Thanks & Regards

Venkat

Hello,

I have a senario like this. I have internal table with 3 fields and my internal table is papulated like

A B C

123 X1 01/02/2007

123 X3 02/01/2007

126 X1 02/01/2007

123 X1 04/02/2007

123 X1 06/02/2007

123 X3 06/01/2007

126 X1 08/01/2007

Now I wanted have a output like

A B C

123 X1 06/02/2007

123 X3 06/01/2007

126 X1 08/01/2007

Any body tell me how can I achive this output.

Thanks & Regards

Venkat

7 REPLIES 7
Read only

Former Member
0 Likes
1,146

SORT itab BY A B ascending C descending.
DELETE ADJACENT DUPLICATES FROM itab COMPARING A B.
Read only

Former Member
0 Likes
1,146

Hello

SORT TABLE BY A B Ascending and C Descending.

delete adjacent duplicates from TABLE COmapring A B C.

Praveen

Read only

0 Likes
1,146

mistake!!

Edited by: Jürgen Hartwig on Aug 27, 2008 11:17 PM

Read only

Former Member
0 Likes
1,146

Hello Venkat,

The method provided by Alvaro and Praveen is not bad. But the main question is: what TYPE is your field C? When it is a date type, the recommended sort and delete works. But when C is a character field, it doesn't work. Let's say you have a table record looking like 126 X1 09/01/2006, the you will get an output

A B C
123 X1 06/02/2007
123 X3 06/01/2007
126 X1 09/01/2006

And I guess that's not what you want!?

When your C field is not of TYPE D, you have to convert it first and then the recommended statements work.

Cheers,

Heinz

Read only

Former Member
0 Likes
1,146

it seemed that you want the latest data.

in this case, sort data and compare date.

do like this.


data: wa_itab like line of itab,
         l_check.

sort itab by a b c.

loop at itab,
  at new c.
   l_check = 'X'.
  endat.

  if l_check = 'X'.
   move-corresponding itab to wa_itab.
   clear: l_check.
  endif.

  if itab-c LE wa_itab-c.
   delete itab.
  endif.  

 endloop.

I hope this would help you

Read only

Former Member
0 Likes
1,146

Hi Venkat,

SORT t_itab BY A B ascending.

DELETE ADJACENT DUPLICATES FROM t_itab COMPARING A B.

DELETE ADJACENT DUPLICATES delete the duplicate adjacent records by comparing the values of A and B with the previous record.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,146

Hi Venkat,

Use the below code to fulfill your requirement

.


SORT it_fina BY A B ascending C descending.
delete adjacent duplicate comparing A.