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

internal table max,min for particular value

Former Member
0 Likes
3,353

Hi all,

I need to select max and min value from an internal table.

the internal table values are

objectid     value_new      value_old

   290               1                     25

   290               17                    1

   291               768                 50

   291              100000          768 

   341               15                    0

my output should be

objectid     value_new     value_old

290               17                    1

291               100000            50

341               15                    0

(i.e) for objectid 290, value-new should be maximum value and value_old should be minimum value.

Pls give me suggestions.

Thanks,

karthik.

1 ACCEPTED SOLUTION
Read only

prakashjasti
Contributor
0 Likes
1,967

Hi,

You can achieve this by taking a temporary table of same type and by sorting differently.

Regards,

Prakash.

Prakash J
10 REPLIES 10
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,967

If you actually want min/max value, just SORT and LOOP AT itab with AT statements, only basic statements. Check documentation of statements via F1 or online documentation.

Are you sure of the requirement, not looking for oldest and newest values ?

objectid     value_new     value_old

290               17                    25

291               100000            50

341               15                    0

Same kind of statements also.

What did you try before posting, read  Rules of Engagement.

Regards,

Raymond

Read only

0 Likes
1,967

Hi raymond,

       I know the basic statements. But i should not use loop statements for this output. because this is not the final output. By getting the MIn & max values I need to proceed further for my report. So give me suggestions other than loop statement. I am sure about my requiremnt.

Thanks,

Karthik

Read only

0 Likes
1,967

Hi Karthik,

I don't think it is possible without using loops(do, loop, while etc.). If you get something, do share the solution

Read only

0 Likes
1,967

Hi Karthik,

  It is not possible to do without using loops, because you cannot access each record without knowning its value.

Read only

0 Likes
1,967

Your

But I should not use loop statements for this output. because this is not the final output.

puzzled me, can you elaborate?

Regards,

Raymond

Read only

prakashjasti
Contributor
0 Likes
1,968

Hi,

You can achieve this by taking a temporary table of same type and by sorting differently.

Regards,

Prakash.

Prakash J
Read only

0 Likes
1,967

Hi

Do like this

Step 1 : Take a temporary table of same type.

Step 2 :Now you move the same data to temp table.

Step 3 : You have two tables now with same data.

Step 4 : Sort the original table by object id and value_new  descending.(Max value on Top)

Step 5 : Sort the temporary table by object id and value_old  ascending.(Min Value on Top)

If you use read statements of both the internal tables you can get the required output.

Regards,

Prakash.

Prakash J
Read only

Former Member
1,967

Hi,

Please check this code,

   sort itab by objectid ASCENDING value_new  DESCENDING  value_old ASCENDING.

   delete ADJACENT DUPLICATES FROM  itab comparing objectid.

Regards,

Suman

Read only

0 Likes
1,967

awesome..!!

Read only

Former Member
0 Likes
1,967

Hi all,

Check this code. Its working.

Copy the internal table to another another internal table.

LT_CDPOS = GT_CDPOS.



SORT GT_CDPOS BY VALUE_NEW DESCENDING.

DELETE ADJACENT DUPLICATES FROM GT_CDPOS COMPARING OBJECTID.



SORT LT_CDPOS BY VALUE_OLD ASCENDING.

DELETE ADJACENT DUPLICATES FROM LT_CDPOS COMPARING OBJECTID.



LOOP AT GT_CDPOS INTO WA_CDPOS.



  READ TABLE LT_CDPOS INTO WA_LT_CDPOS WITH KEY OBJECTID = WA_CDPOS-OBJECTID.



     WA_CDPOS_FINAL-OBJECTID = WA_LT_CDPOS-OBJECTID.

    WA_CDPOS_FINAL-VALUE_NEW = WA_CDPOS-VALUE_NEW.

    WA_CDPOS_FINAL-VALUE_OLD = WA_LT_CDPOS-VALUE_OLD.



    APPEND WA_CDPOS_FINAL TO GT_CDPOS_FINAL.


ENDLOOP.