Hi SCN community!
Ever wanted to get the line in a table where the max value for a certain field was? I had to last week, and I remembered just how awful it was to do it. Declare an auxiliary table of the same structure, copy the entire contents, sort for the right field, get the first line, correct?
I thought that there had to be a better way to do this, and I searched for it, and couldn’t find it. And I was actually challenged by Manish Kumar to create a class for this, and so I did.
What I’m sharing is a simple class for internal table manipulations. So far it has 5 methods:
- GET_MAX_LINE – Get the line with the maximum value for a certain column
- GET_MIN_LINE – Get the line with the minimum value for a certain column
- GET_MAX_VAL – Get the maximum value for a certain column
- GET_MIN_VAL – Get the minimum value for a certain column
- GET_AVG_VAL – Get the average value for a certain column
I’m trying to set up github so that we can all work on this together, hopefully we will be able to work on other utility classes like this one.
EDIT: Github successfully set up! You can follow this project here:
For revision 3 I have changed the exception throwing strategy (much cleaner now) and taken Shai Sinai‘s suggestion of using the component’s name instead of looking for its index. GREAT catch!!
If you have any suggestions or contributions please feel free to join 🙂