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

Logic required for a Internal table issue

Former Member
0 Likes
698

Hi Experts,

I want to take the maximum amount(stprs) according to my stlnr value. That means in my internal table having lots of entries. its contain stlnr and stprs. i want to pick only the maximum stprs value for each and every stlnr.

my internal table like below, for example from the internal table i required 17238 and its 0.32 , 17210 and its 0.21, 162178 and its 6.21.



STLNR	MATNR	STPRS
17238	1021208	0.01
17238	1339526	0.32
15028	1330026	5
17210	7376973	0.21
17210	7379263	0.01
162178	1574231	3.21
162178	814661	6.21

Gowri sankar

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
659

Try this code:

SORT ITAB BY STLNR STPRS DESCENDING.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING STLNR.

Resulting ITAB has the required records.

5 REPLIES 5
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
660

Try this code:

SORT ITAB BY STLNR STPRS DESCENDING.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING STLNR.

Resulting ITAB has the required records.

Read only

Former Member
0 Likes
659

Hi,


Data:
  flag type i.
sort t_tab by stlnr STPRS descending.
Loop at t_tab into fs_tab.

at new of stlnr.
flag = 1.
endat.

if flag = 0.
delete t_tab index sy-tabix.
endif.
flag = 0.
endloop.

If stlnr is first field in the table use as above at new or replace that with

on cgange ....endon statement.

Regards and Best wishes.

Read only

Former Member
0 Likes
659

Hi,

SORT ITAB BY STLNR ASCENDING STPRS DESCENDING.

AND

Read itab for first STLNR in each STLNR.

Regards,

Moon

Read only

Former Member
0 Likes
659

hi

if you want to fetch max amount records from a database table

then

select STLNR MATNR STPRS from (table name) into corresponding fields of table (internal table) order by STPRS descending.

Read only

Former Member
0 Likes
659

Hi,

SORT ITAB BY STLNR STPRS DESCENDING.

READ TABLE ITAB INDEX 1.

WRITE:/ ITAB-STPRS.

Regards,

Raj.