View previous topic :: View next topic
|
Author |
Message |
kumarvis Warnings : 1 New User
Joined: 31 Mar 2007 Posts: 14 Location: Chennai
|
|
|
|
Hi,
I did xpeditor test on program. During testing I am not clear with the following statement.
THIS IS HOW THE BELOW VARIABLES ARE DEFINED.
WORKING STORAGE SECTION.
05 WS20-PRT-CNTER PIC S9(09) COMP VALUE +0.
05 WS20-STODAT-TOTAL-READ PIC S9(09) COMP VALUE +0.
COMPUTE WS20-PRT-CNTER
= 1
+ (WS20-STODAT-TOTAL-READ
- (WS20-STODAT-TOTAL-READ / 1000) * 1000)
END-COMPUTE
In xpeditor, it shows the value of WS20-PRT-CNTER after computation is 2. Can u explain how is this possible? |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Quote: |
In xpeditor, it shows the value of WS20-PRT-CNTER after computation is 2. |
Are you sure ?
If not, put some displays before and after compute statement to check what your output variable gets. As your compute statement doesnt seem other than increament by 1. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Where is the WS20-STODAT-TOTAL-READ field incrememnted?
Before the "problem" calculation, the WS20-STODAT-TOTAL-READ field may have been incremented to 1 from the first record read. |
|
Back to top |
|
|
kumarvis Warnings : 1 New User
Joined: 31 Mar 2007 Posts: 14 Location: Chennai
|
|
|
|
This is for to give u the detailed explaination of the above comp-3 computation issue with screen shots mentioned in the attachment doc. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
The way I read the compute:
(WS20-STODAT-TOTAL-READ / 1000) * 1000) truncates to zero, so
WS20-PRT-CNTER = 1 + 1 - 0 = 2 |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If the result was not 2, that would be a surprise.
From your original post
Code: |
COMPUTE WS20-PRT-CNTER
= 1
+ (WS20-STODAT-TOTAL-READ
- (WS20-STODAT-TOTAL-READ / 1000) * 1000)
END-COMPUTE
|
and in your attachment, you provide
Quote: |
Before coming to the below computation, WS20-STODAT-TOTAL-READ was
Incremented by 1.
|
so, the calculation is as Jack said 1 + 1 - 0 = 2.
We're here if this is not clear |
|
Back to top |
|
|
kumarvis Warnings : 1 New User
Joined: 31 Mar 2007 Posts: 14 Location: Chennai
|
|
|
|
Hi,
Thanks for ur respoce. I do have another concern on this issue.
May I know under what circumstances does the
(WS20-STODAT-TOTAL-READ/1000) * 1000 = zero. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello kumarvis,
With the code as it is written, i believe this
Quote: |
(WS20-STODAT-TOTAL-READ/1000) * 1000 |
will be zero until WS20-STODAT-TOTAL-READ becomes greater than 1000.
Rather than focus on this particular calculation, please explain the use of the WS20-PRT-CNTER? As coded, it will increase at an increasing rate as the number of records reaches each successive thousand.
If we understand what this accomplishes, we may be able to offer better suggestions. |
|
Back to top |
|
|
monga
New User
Joined: 18 Apr 2006 Posts: 13
|
|
|
|
WS20-STODAT-TOTAL-READ = 1
The code says
Code: |
COMPUTE WS20-PRT-CNTER
= 1
+ (WS20-STODAT-TOTAL-READ
- (WS20-STODAT-TOTAL-READ / 1000) * 1000)
END-COMPUTE |
which is
Code: |
COMPUTE WS20-PRT-CNTER = 1 + ( 1 - (1/1000) * 1000) |
But as COMPUTE WS20-PRT-CNTER is declared as a COMP variable and not a COMP-3
the resultant 0.999 would be equivalent to 0
Code: |
WS20-PRT-CNTER = 1 + ( 1 - (0) * 1000)
WS20-PRT-CNTER = 1 + ( 1 - 0)
WS20-PRT-CNTER = 2 |
I hope this would clear your doubts. Also let me know if my understanding is not correct here.
Thanks,
monga |
|
Back to top |
|
|
monga
New User
Joined: 18 Apr 2006 Posts: 13
|
|
|
|
Just one correction - Read the resultant value as 0.001 (and not 0.999 as stated above) |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Is is just me who got confused?
WS20-STODAT-TOTAL-READ and WS20-PRT-CNTER both are +0.
why you guys are taking 1 at WS20-STODAT-TOTAL-READ
Quote: |
COMPUTE WS20-PRT-CNTER = 1 + ( 1 - (1/1000) * 1000) |
If i have learnt my fifth grade maths correct then answer should be 1.
Because of Dick's comment, I even gave it a try.
Surprise! I am correct! answer is 1 |
|
Back to top |
|
|
muthuvel
Active User
Joined: 29 Nov 2005 Posts: 217 Location: Canada
|
|
|
|
Folks,
I guess it is turning from a Mainframe Forum to Maths Forum |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Sorry Folks!
I missed reading the attachment! Till then 'original post' was my Bible.
The attachement enlightened me about incrementing value.
But my maths is good! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Abhijit,
As has been said, "Sometimes you get the bear, sometimes the bear gets you"
Now, if kumarvis comes back with more info, we may be able to offer some suggestions. . . |
|
Back to top |
|
|
|