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

Latest Date Logic

Former Member
0 Likes
1,669

I have an Internal table, with columns Date, Material no(duplicates), Material Document No(unique).

I would like to pick only latest date record with material no, material document, then delete rest for the material no in the internal table.

Any Suggestion or logic using Internal table..

Edited by: Praba KN on Dec 3, 2008 9:37 AM

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,593

Here it is important column order. Use this like below:


data: begin of it occurs 0,
          material type...
          date type d,
          doc type ...
        end of it.
...
sort it by material date doc.

loop at it.
   at new material.   "gets the lates record from material
       continue.         "continue loop leaving this entry
   endat.

   delete it index sy-tabix.   "delete all the others
endloop.

This should work

Marcin

I have an Internal table, with columns Date, Material no(duplicates), Material Document No(unique).

I would like to pick only latest date record with material no, material document, then delete rest for the material no in the internal table.

Any Suggestion or logic using Internal table..

Edited by: Praba KN on Dec 3, 2008 9:37 AM

12 REPLIES 12
Read only

Former Member
0 Likes
1,593

Hi,

First sort your internal table on date field and then select the required fields.

Thanks

Read only

Former Member
0 Likes
1,593

hi,

Sort your internal table in descending order by date,and the rest of the fields, in this way you would get the latest date, and delete the remaining record,

Thanks..

Read only

Former Member
0 Likes
1,593

Hi,

Sort the internal table with descending date and read the first recrod.

e.g.

SORT IT_TAB1 by DATS DESCENDING.

Read table it_tab1 index 1.

Hope this will help.

Regards,

Nitin.

Read only

former_member632729
Contributor
0 Likes
1,593

Hi,

sort the internal table with material number , date and material doc then u can have to use control levels .. pick the last record and place in new internal table ..

do the same process to all the material once you completed then you can procedd with new internal table..

Hope Helpfull

Raghunath.S

Read only

0 Likes
1,593

How to use the control levels?

Read only

Former Member
0 Likes
1,593

Hi,

SORT itab BY datecolumn DESCENDING.

Regards

Read only

Former Member
0 Likes
1,593

Hi ,

Sort the internal table on date in decending order and then read the table index 1. this will give you the latest record.

Raj

Read only

MarcinPciak
Active Contributor
0 Likes
1,594

Here it is important column order. Use this like below:


data: begin of it occurs 0,
          material type...
          date type d,
          doc type ...
        end of it.
...
sort it by material date doc.

loop at it.
   at new material.   "gets the lates record from material
       continue.         "continue loop leaving this entry
   endat.

   delete it index sy-tabix.   "delete all the others
endloop.

This should work

Marcin

Read only

0 Likes
1,593

P:

With this method, i have 4 record with duplicate Material no, different date and materia no., result is zero.It deleted all the record.

111 1/2/2008 123

111 1/3/2008 132

111 2/3/2008 134

111 12/01/2008 135

I want only

111 12/01/2008 135

rest all needs to be delete in the internal table.

Any thoughts.

Read only

0 Likes
1,593

data: begin of it occurs 0,
          material type...
          date type d,
          doc type ...
        end of it.
...
sort it by material date doc.

after these steps using


DELETE ADJACENT DUPLICATES FROM it COMPARING material .

will be better than

 
loop at it.
   at new material.   
       continue.        
   endat.
 
   delete it index sy-tabix.  
endloop.

Read only

0 Likes
1,593

Sorry I think it was due to wrong sorting condition. This code works fine (I checked). Only apply this logic.


data: begin of it occurs 0,
          m type c,
          d type d,
          doc type i,
        end of it.

it-m = 1.
it-d = '20080101'.
it-doc = 123.
append it.

it-m = 1.
it-d = '20080201'.
it-doc = 132.
append it.

it-m = 1.
it-d = '20080301'.
it-doc = 145.
append it.

sort it by m d DESCENDING doc .

loop at it.
   at new m.   "gets the lates record from material
       continue.         "continue loop leaving this entry
   endat.

   delete it index sy-tabix.   "delete all the others
endloop.

Regards

Marcin

Read only

0 Likes
1,593

Thanks Pat, Pathak