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

find max value from internal table

Former Member
39,480

DATA : BEGIN OF SUBVBPLP OCCURS 10,

vendprodid like mara-mfrpn ,

CUMQUANTITY TYPE I ,

PACKLISTID LIKE VBRK-VBELN,

mfr_id(3) ,

debtorid(27),

END OF SUBVBPLP.

SUBVPLP-CUMQUANTITY = 10.

APPEND .

SUBVPLP-CUMQUANTITY = 20.

APPEND.

I WANT TO FIND THE MAX VALUE FORM CUMQUANTITY . AND RESULT INTO ONE VARIBALE . PLS GIVE SUGGESTION TO GET MAX VALUE

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
12,856

declare two workareas wa1 and wa2 of the same type SUBVBPLP

loop at itab into wa1.

read table itab into wa2 with index sy-index + 1.

if wa2-CUMQUANTITY > wa1-CUMQUANTITY.

maxval = wa2-CUMQUANTITY.

endif.

endloop.

This wil give max in variable maxval.

Hope dis solves ur query

Reward points if helpful

7 REPLIES 7
Read only

Former Member
0 Likes
12,856

Hi,

data : test type i.

Sort subvbplp by cumquantity descending.

read table subvbplp index 1.

test = subvbplp-cumquantity.

Regards,

Himanshu

Read only

Former Member
0 Likes
12,857

declare two workareas wa1 and wa2 of the same type SUBVBPLP

loop at itab into wa1.

read table itab into wa2 with index sy-index + 1.

if wa2-CUMQUANTITY > wa1-CUMQUANTITY.

maxval = wa2-CUMQUANTITY.

endif.

endloop.

This wil give max in variable maxval.

Hope dis solves ur query

Reward points if helpful

Read only

0 Likes
12,856

loop at subvbplp.

sort subvbplp by cumquantity descending.

read table subvbplp into w_subvbplp with index sy-index+1.

if w_subvbplp > subvbplp.

maxval = w_subvbplp-cumquantity.

endif.

endloop.

NO I GETTING SOME ERROR " KEY = ....","JEY...= "OR TABLE KEY ...=" EXPECTED AFTER WITH

Read only

0 Likes
12,856

Hi Anil.

There is no need to Loop the Internal table in this case .

This is the better way.

Check this which i gave in my prev post.

Hi.

This is the code to get the Max CUMQUANTITY.

<b>Sort SUBVBPLP by CUMQUANTITY DESCENDING.

READ TABLE SUBVBPLP INDEX 1.

WRITE: / SUBVBPLP-CUMQUANTITY .

</b>

REWARD IF HELPFUL

Read only

12,856

The logic is not complete. If the max value is the first one, it will not be saved to maxval. This would be the proper solution:

loop at itab into wa1.

     maxval = wa1-cumquantity.

     read table itab into wa2 index sy-index + 1.

          if wa2-CUMQUANTITY > wa1-CUMQUANTITY.

               maxval = wa2-CUMQUANTITY.

          endif.

endloop.

Read only

Former Member
0 Likes
12,856

use this select statement...

Select max ( <fieldname in itab> ) from table <i_tab> into <f_name> where .........

Read only

varma_narayana
Active Contributor
0 Likes
12,856

Hi.

This is the code to get the Max CUMQUANTITY.

Sort SUBVBPLP by CUMQUANTITY DESCENDING.

READ TABLE SUBVBPLP INDEX 1.

WRITE: / SUBVBPLP-CUMQUANTITY .

<b>Reward if Helpful.</b>