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

Aggregate functions for internal table.

Former Member
0 Likes
905

Hi Gurus,

I'm just wondering whether we can use aggregate functions for internal table. I wanted to know the max value for a particular column in my internal table. How can I achieve this easily and quickly.

Thanks,

David.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
601

sort the table on which you want the maximum value and read it. Please find below example code.

TYPES : BEGIN OF ty_mvke,

matnr TYPE mvke-matnr,

vkorg TYPE mvke-vkorg,

vtweg TYPE mvke-vtweg,

AUMNG type mvke-AUMNG,

END OF ty_mvke.

DATA : wa_mvke TYPE ty_mvke,

it_mvke TYPE STANDARD TABLE OF ty_mvke.

data : temp_AUMNG type AUMNG.

START-OF-SELECTION.

SELECT matnr vkorg vtweg AUMNG FROM mvke INTO

table it_mvke.

sort it_mvke by AUMNG.

read TABLE it_mvke into wa_mvke INDEX 1.

if sy-subrc = 0.

move wa_mvke-AUMNG to temp_AUMNG.

write : temp_AUMNG.

endif.

Thanks,

Sreekala.

3 REPLIES 3
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
601

if you need it from a itab then sort the itab descending based on the required field, then read the index 1 of itab.

Read only

0 Likes
601

Hello,

Please explain more.

Read only

Former Member
0 Likes
602

sort the table on which you want the maximum value and read it. Please find below example code.

TYPES : BEGIN OF ty_mvke,

matnr TYPE mvke-matnr,

vkorg TYPE mvke-vkorg,

vtweg TYPE mvke-vtweg,

AUMNG type mvke-AUMNG,

END OF ty_mvke.

DATA : wa_mvke TYPE ty_mvke,

it_mvke TYPE STANDARD TABLE OF ty_mvke.

data : temp_AUMNG type AUMNG.

START-OF-SELECTION.

SELECT matnr vkorg vtweg AUMNG FROM mvke INTO

table it_mvke.

sort it_mvke by AUMNG.

read TABLE it_mvke into wa_mvke INDEX 1.

if sy-subrc = 0.

move wa_mvke-AUMNG to temp_AUMNG.

write : temp_AUMNG.

endif.

Thanks,

Sreekala.