IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Issue with COMP-3 computation calc


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kumarvis
Warnings : 1

New User


Joined: 31 Mar 2007
Posts: 14
Location: Chennai

PostPosted: Wed Apr 04, 2007 10:54 am
Reply with quote

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
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Wed Apr 04, 2007 1:41 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Apr 04, 2007 10:04 pm
Reply with quote

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
View user's profile Send private message
kumarvis
Warnings : 1

New User


Joined: 31 Mar 2007
Posts: 14
Location: Chennai

PostPosted: Thu Apr 05, 2007 4:55 am
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Apr 05, 2007 5:24 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Apr 05, 2007 6:27 am
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
kumarvis
Warnings : 1

New User


Joined: 31 Mar 2007
Posts: 14
Location: Chennai

PostPosted: Thu Apr 05, 2007 6:50 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Apr 05, 2007 7:37 am
Reply with quote

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
View user's profile Send private message
monga

New User


Joined: 18 Apr 2006
Posts: 13

PostPosted: Thu Apr 05, 2007 10:31 am
Reply with quote

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
View user's profile Send private message
monga

New User


Joined: 18 Apr 2006
Posts: 13

PostPosted: Thu Apr 05, 2007 10:33 am
Reply with quote

Just one correction - Read the resultant value as 0.001 (and not 0.999 as stated above)
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Apr 05, 2007 12:22 pm
Reply with quote

Is is just me who got confused? icon_confused.gif
WS20-STODAT-TOTAL-READ and WS20-PRT-CNTER both are +0.
why you guys are taking 1 at WS20-STODAT-TOTAL-READ icon_question.gif

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 icon_lol.gif
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Thu Apr 05, 2007 12:25 pm
Reply with quote

Folks,
I guess it is turning from a Mainframe Forum to Maths Forum icon_lol.gif
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Apr 05, 2007 12:29 pm
Reply with quote

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! icon_lol.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Apr 05, 2007 8:47 pm
Reply with quote

Hi Abhijit,

As has been said, "Sometimes you get the bear, sometimes the bear gets you" icon_smile.gif

Now, if kumarvis comes back with more info, we may be able to offer some suggestions. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Facing ABM3 issue! CICS 3
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
Search our Forums:

Back to Top