Page 1 of 1

Number logic

PostPosted: Fri Feb 21, 2014 3:33 am
by vinu78
Hi All,

I would like to have a generic logic for the following requirement

We have a points benchmark set as 100. Then the extra points will be awarded for the mentioned sales criteria.
If the Sales is double this benmark we need to assign extra 10 points (so it will be 100 + 10). If the sales is triple this benchmark, then we need to assign extra 25 points (so it will be 100 + 25 = 125 points).
I am finding it difficult to come up with the logic because the sales can be 4 times the benchmark and in that case, we need to assign 100 + 10 + 10 = 120 points.

01 WS-BENCHMARK PIC 9(3).
01 WS-SALES     PIC 9(3).
01 WS-PTS         PIC 9(3).

IF WS-SALES = WS-BENCHMARK * 2
   COMPUTE WS-PTS = 100 + 10
END-IF

IF WS-SALES = WS-BENCHMARK * 3
   COMPUTE WS-PTS = 100 + 25
END-IF


I am not sure how to make this formula generic, if the sales becomes double, triple, 4 times or 6 times the benchmark value.
Please help me.

Thanks
Vinu

Re: Number logic

PostPosted: Fri Feb 21, 2014 3:50 am
by Terry Heinze
Why are the WS-PTS greater for triple than for quadruple? Can the sales be 1 1/2 times the benchmark? 2 1/2 times the benchmark? Your rules need to be more specific.

Re: Number logic

PostPosted: Fri Feb 21, 2014 4:08 am
by Robert Sample
You would be better off using something like this untested logic:
EVALUATE TRUE
WHEN (WS-SALES >= WS-BENCHMARK * 4)
     COMPUTE ...
WHEN (WS-SALES >= WS-BENCHMARK * 3)
    COMPUTE ...
WHEN (WS-SALES >= WS-BENCHMARK * 2)
    COMPUTE ...
END-EVALUATE
EVALUATE goes down the WHEN list and the first TRUE (in this case) becomes the accepted WHEN -- the others will not be evaluated.

Re: Number logic

PostPosted: Fri Feb 21, 2014 4:17 am
by vinu78
Thanks Terry . You are right. I just mentioned sample values.
If doubled, the WS-PTS should be 100 +10 = 110 pts
If tripled, the WS-PTS should be 100 + 15 = 115 pts
If quadrapled, the WS-PTS should be 100 + 10 + 10 = 120 pts

Thanks Robert Sample for the logic. I will try this.

Re: Number logic

PostPosted: Fri Feb 21, 2014 4:34 am
by BillyBoyo
Divide Sales by Benchmark. Multiply that result by five. Add that to 100 and you have your Points.

You haven't asnwered Terry's point about mid-values, which your current code does not deal with. 2 1/2 times Benchmark would only get 100 Points in your code.

If Benchmark is one, no problem. If Benchmark is two, and Sales three, what should happen?

Re: Number logic

PostPosted: Fri Feb 21, 2014 4:43 am
by vinu78
If the sales is 2.5 times benchmark, then it is considered as double only. I think Terry's code satisfies this condition.
So eventhoughn mid values come, we are looking for double the benchmark or triple the benchmark (whole numbers only)

Also your solution gives the answer = "Divide Sales by Benchmark. Multiply that result by five. Add that to 100 and you have your Points". Thanks