Number logic



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Number logic

Postby vinu78 » Fri Feb 21, 2014 3:33 am

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
vinu78
 
Posts: 29
Joined: Sat Sep 27, 2008 4:47 am
Has thanked: 0 time
Been thanked: 0 time

Re: Number logic

Postby Terry Heinze » Fri Feb 21, 2014 3:50 am

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.
.... Terry
Terry Heinze
 
Posts: 239
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 12 times
Been thanked: 11 times

Re: Number logic

Postby Robert Sample » Fri Feb 21, 2014 4:08 am

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Number logic

Postby vinu78 » Fri Feb 21, 2014 4:17 am

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.
vinu78
 
Posts: 29
Joined: Sat Sep 27, 2008 4:47 am
Has thanked: 0 time
Been thanked: 0 time

Re: Number logic

Postby BillyBoyo » Fri Feb 21, 2014 4:34 am

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?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Number logic

Postby vinu78 » Fri Feb 21, 2014 4:43 am

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
vinu78
 
Posts: 29
Joined: Sat Sep 27, 2008 4:47 am
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post