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

it values

Former Member
0 Likes
877

Dear Experts,

I have an iternal table like below

F1 F2 F3

1 W 90

2 S 78

3 D 90

4 5 45

5 8 87

My requirement is i need to keep the lines which contains maximum values in F3

in the above example i need only the line F3 = 90. remaining should delete

i need like below

F1 F2 F3

1 W 90

3 D 90

Can anyone send code for this.

thanks in advance

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
845

Hello Karthik

Here is a possible solution for your problem:

DATA:
  ls_entry   LIKE LINE OF it_itab.

SORT it_itab by field_f3 descending.
READ TABLE it_itab INTO ls_entry INDEX 1.

DELETE it_itab WHERE ( field_f3 < ls_entry-field_f3 ).

Regards

Uwe

9 REPLIES 9
Read only

uwe_schieferstein
Active Contributor
0 Likes
846

Hello Karthik

Here is a possible solution for your problem:

DATA:
  ls_entry   LIKE LINE OF it_itab.

SORT it_itab by field_f3 descending.
READ TABLE it_itab INTO ls_entry INDEX 1.

DELETE it_itab WHERE ( field_f3 < ls_entry-field_f3 ).

Regards

Uwe

Read only

0 Likes
845

sort itab by F3 descending.

read table itab into w_area index 1.

delete itab where F3 < w_area -f3.

Read only

Former Member
0 Likes
845

Karthik,

Sort itab by F3 descending.

read itab index 1 into WA.

delete itab where F3 ne WA-F3.

Rgds,

Sarah.

Read only

Former Member
0 Likes
845

Hi,

you can try this:

data:aux_internal like your_table occurs 0 with header line.

sort your_table by F3 descending.

if not your_table[] is initial.

read your_table index 1 into aux_internal.

delete your_table where F3 <> aux_internal-F3.

endif.

Read only

Former Member
0 Likes
845
sort itab by F3 descending.

loop at itab.
  at end of F3.
    flag = 'X'.
  endat.
  if flag eq 'X'.
    delete itab.
  endif.
endloop.
Read only

Former Member
0 Likes
845

delete itab where f3 ne 90.

This code will work for sure.

Pls reward points if its useful.

Regards,

Sujatha.

Read only

Former Member
0 Likes
845

Hi,

Try this

SORT itab descending by F3.

READ TABLE itab WITH index 1.
 IF sy-subrc  = 0.
 v_val = itab-f3.
DELETE itab WHERE f3 NE v_val.
 ENDIF.

Read only

Former Member
0 Likes
845

karthik... i have taken your example.. just copy and see.

DATA: BEGIN OF ITAB OCCURS 0,

F1 TYPE I,

F2(1),

F3 TYPE I,

END OF ITAB.

DATA: SNO TYPE I.

ITAB-F1 = 1.

ITAB-F2 = 'W'.

ITAB-F3 = 90.

APPEND ITAB.

ITAB-F1 = 2.

ITAB-F2 = 'S'.

ITAB-F3 = 78.

APPEND ITAB.

ITAB-F1 = 3.

ITAB-F2 = 'D'.

ITAB-F3 = 90.

APPEND ITAB.

ITAB-F1 = 4.

ITAB-F2 = '5'.

ITAB-F3 = 45.

APPEND ITAB.

ITAB-F1 = 5.

ITAB-F2 = '8'.

ITAB-F3 = 87.

APPEND ITAB.

SORT ITAB BY F3 DESCENDING.

READ TABLE ITAB INDEX 1.

SNO = ITAB-F3.

DELETE ITAB WHERE F3 LT SNO.

LOOP AT ITAB.

WRITE : / ITAB-F1, ITAB-F2, ITAB-F3.

ENDLOOP.

Read only

Former Member
0 Likes
845

Assuming ur internal table as itab1

sort itab1 by F3 descending.

clear l_f3.

loop at itab1 into wa_itab1.

if sy-tabix = 1.

l_F3 = wa_itab2-f3.

else.

if wa_itab2 LT L_F3

l_index = sy-tabix.

exit.

endif.

endif.

endloop.

describe itab1 lines n.

delete itab1 from l_index to n.

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers