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

query in rounded phrase in cobol


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

New User


Joined: 24 Jan 2007
Posts: 28
Location: pune

PostPosted: Fri Oct 02, 2009 5:24 pm
Reply with quote

Hi All,

My requirement is as follows.

i/p fileds are of S9(15)V9(02) COMP-3.
O/p field is 9(6).

o/p = (a+b)* 100

In this case , if the value of a and b are equal to 15225.10 and 30450.25 , then the o/p i'm getting is 49%.

The actual division result should be rounded i.e., the percentage i'm expecting is 50%.

My compute statement which i have used is as follows:
COMPUTE o/p ROUNDED =
((a / b) * 100

ON SIZE ERROR
MOVE ZEROES TO o/p
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: Fri Oct 02, 2009 5:46 pm
Reply with quote

Another case where intermediate results need to be understood to understand what happened to the fields. Sample code:
Code:
           05  VAR-1                   PIC S9(15)V9(02) COMP-3.
           05  VAR-2                   PIC S9(15)V9(02) COMP-3.
           05  VAR-3                   PIC 9(06).
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           MOVE 15225.10               TO  VAR-1.
           MOVE 30450.25               TO  VAR-2.
           DISPLAY 'VAR-1 ' VAR-1.
           DISPLAY 'VAR 2 ' VAR-2.
           COMPUTE VAR-3 ROUNDED = (VAR-1 / VAR-2) * 100 .
           DISPLAY 'VAR 3 ' VAR-3.
           DISPLAY ' ' .
           COMPUTE VAR-3 ROUNDED = (100 * VAR-1) / VAR-2.
           DISPLAY 'VAR 3 ' VAR-3.
produces output of
Code:
 VAR-1 00000000001522510
 VAR 2 00000000003045025
 VAR 3 000049

 VAR 3 000050
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: Sat Oct 03, 2009 7:44 am
Reply with quote

See Appendix A in the Programming Guide for details about intermediate results.
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