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

divide statement in cobol


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

New User


Joined: 20 Apr 2007
Posts: 13
Location: chennai

PostPosted: Mon Oct 26, 2009 5:22 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 26, 2009 5:32 pm
Reply with quote

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

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Mon Oct 26, 2009 6:04 pm
Reply with quote

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

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Oct 26, 2009 7:50 pm
Reply with quote

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
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top