10-08-2015 11:30 AM
Hi Friends,
We have a requirment to get closest number from an arry of numers for our requirement quantity to round up.
Example we have numbers 100, 100, 80, 80, 80, 60 as available stock.
Our requirement is 230
System should give us the result 240 which is either 80+80+80 or 100+80+60
We are only interested for the result 240 and not bothered with either of options it uses.
Is there any fucntion module or any other method to achieve this.
Regards,
Malay
10-08-2015 12:36 PM
AFAIK, No, there are not FM to solve every problem in SAP. You could search but don't expect too much. So use some personal thought or google on: "algorithm" "sum of integer" "value " and then Abap coding your algorithm.
Hint: think recursive, or from school memories some Polynomial time approximate algorithm
Regards,
Raymond
10-08-2015 11:57 AM
I think you're looking for a knapsack problem solution. Am I right?
10-08-2015 4:45 PM
It's not like a knapsack problem. In a knapsack problem the objects have two values and you maximize one while limiting the other.
10-08-2015 12:36 PM
AFAIK, No, there are not FM to solve every problem in SAP. You could search but don't expect too much. So use some personal thought or google on: "algorithm" "sum of integer" "value " and then Abap coding your algorithm.
Hint: think recursive, or from school memories some Polynomial time approximate algorithm
Regards,
Raymond
10-08-2015 4:59 PM
Dear Malay
As Mr.Raymond says, you apply the recursive loop - write your own form routine that returns a result table with storage location and stock.
just pseudo code as follows
requirement = 240
loop at your location wise stock iternanl table
if location stock is <= requirement
append this location stock (X) to result table
requirment = requiement - location stock
else
append this (location stock X - requiremnt) to result table
endif.
endloop
return the result table
10-13-2015 6:59 PM
This is an old math problem:
Find minimum number of coins that make a given value - GeeksforGeeks
Thanks,
Juwin