Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 8165
Location: East Dubuque, Illinois, USA

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 IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am
No new posts WER268A OUTREC STATEMENT : SYNTAX E... frozenblood87 SYNCSORT 12 Sat Aug 26, 2017 9:45 pm
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us