Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

divide statement in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: divide statement in cobol
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: 8002
Location: Bellevue, IA

PostPosted: Mon Oct 26, 2009 5:32 pm    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 5 Wed Mar 29, 2017 12:47 am
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts ROUNDED Problem with COMPUTE statement shalem COBOL Programming 11 Thu Feb 09, 2017 8:16 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us