2013 Mar 22 1:18 PM
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.
2013 Mar 23 8:52 AM
Hi,
You can achieve this by taking a temporary table of same type and by sorting differently.
Regards,
Prakash.
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.
2013 Mar 22 1:28 PM
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
2013 Mar 22 2:19 PM
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
2013 Mar 22 7:55 PM
Hi Karthik,
I don't think it is possible without using loops(do, loop, while etc.). If you get something, do share the solution
2013 Mar 23 7:06 AM
Hi Karthik,
It is not possible to do without using loops, because you cannot access each record without knowning its value.
2013 Mar 23 8:59 AM
2013 Mar 23 8:52 AM
Hi,
You can achieve this by taking a temporary table of same type and by sorting differently.
Regards,
Prakash.
2013 Mar 25 5:41 AM
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.
2013 Mar 25 5:50 AM
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
2013 Mar 25 12:54 PM
2013 Mar 25 2:50 PM
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.