View previous topic :: View next topic
|
Author |
Message |
inbasekarmani Warnings : 2 New User
Joined: 20 Apr 2007 Posts: 13 Location: chennai
|
|
|
|
hi,
WORKING-STORAGE SECTION.
77 FIELD1 PIC 9(2)V9.
77 FIELD2 PIC 9V9.
PROCEDURE DIVISION.
….
DIVIDE 5 BY 4 GIVING FIELD1 REMAINDER FIELD2.
when i execute this ,iam getting the following value
Field1 is 012
field2 is 02
when i execute the same coding with field1 pic 9(4)v9(4), then iam getting field2 as 00.
why this is happening? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You need to find the manuals (link at the top of the page), pull up the COBOL Language Reference, and read up -- intensively -- on both intermediate results and COBOL division.
4 times 1<.>2 is 4.8; 5.0 minus 4.8 is 0<.>2 -- the results you got are what you should have gotten based upon your field definitions.
With a field of PIC 9(4)V9(4), the division gives 0001<.>2500 so there is no remainder so the remainder should be 00.
So why are you surprised about these results (other than you not understanding COBOL division, intermediate results and final results)? |
|
Back to top |
|
|
bhairon singh rathore
New User
Joined: 19 Jun 2008 Posts: 91 Location: banglore
|
|
|
|
Hi
5/4 = 1.2 as field1 can take only one decimal ...so remainder would be 0.2 which is field2
if you increase field1 to 9(4)v9(4) then value is 1.25 but then there is no remainder
Regards
|
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Before posting your reply, did you take Robert's advice about reading about intermediate results, final result, and the DIVIDE statement in the Language Reference Manual? |
|
Back to top |
|
|
|