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

Percentage calculation in cobol


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

New User


Joined: 19 Dec 2004
Posts: 23
Location: hyderabad

PostPosted: Sun Sep 16, 2007 11:17 pm
Reply with quote

Hi ,

i need to calculate Not found records percentage in my cobol program.

i have following fields:

not-found-rec-count pic 9(09).
Total-rec-count pic 9(09).
Mis-match-percent pic 9(03).

i have done below computation to get the mis-match percent.

Compute Mis-match-percent = (not-found-rec-count/Total-rec-count) * 100

But some times it is not giving percentage properly.

can any one tell me the solution for this.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sun Sep 16, 2007 11:49 pm
Reply with quote

venkatarao wrote:
But some times it is not giving percentage properly.
Could you give an example of what you consider not proper?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Sep 17, 2007 1:16 am
Reply with quote

Hello,

Please post a few sets of "input", the result of the calculation using that input and what you would rather see as the result. You might create a bit of code to do nothing but process a few sets of "counts" and display the values - no need to actually read the data, especially if the number of records might approach a billion (pic 9(9) is a very large number of possible records which is very, very rare). The size of the accumulators may also cause your calculation problems.

For starters, you should have some decimal positions defined in one or more of the fields used in the calculation. If the final result is to be without decimals, i'd suggest rounding the result.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Sep 17, 2007 8:18 am
Reply with quote

Hello,

While waiting on some longer running processes, i did a little experiment.

If you define the first 2 fields as 9(9) and the percent field as 9(3)v999, you will get better results. When i used your definitions, i got a pct of zero.

This worked
Code:
77  TOTL                PIC S9(9) COMP-3 VALUE 100.         
77  TOTH                PIC S9(9) COMP-3 VALUE  80.         
77  PCT                 PIC S9(3)V999 COMP-3 VALUE  00.     


This failed
Code:
77  TOTL                PIC S9(9) COMP-3 VALUE 100.         
77  TOTH                PIC S9(9) COMP-3 VALUE  80.         
77  PCT                 PIC S9(3)    COMP-3 VALUE  00.     


The computation stayed the same
Code:
COMPUTE PCT = (TOTH / TOTL) * 100       
DISPLAY PCT.                           
Back to top
View user's profile Send private message
logeswarank
Warnings : 1

New User


Joined: 15 Oct 2006
Posts: 22
Location: Chennai

PostPosted: Mon Sep 17, 2007 3:53 pm
Reply with quote

Hi,

Try this one.
If its wrong correct me.

Code:
 000710  3000-PROCESS.                                                         
     READ INFILE-1 AT END GO TO 3500-REC-NOT.                           
       MOVE IN-INPUT-RECORD TO WS-INPUT-RECORD.                           
       IF WS-INP-REC-ID IS EQUAL TO 07                                   
         WRITE OU-INPUT-RECORD FROM WS-INPUT-RECORD                     
       ELSE                                                               
          COMPUTE  REC-COUNT  = REC-COUNT + 1                             
      END-IF.                                                           
                                                                         
        COMPUTE TOT-REC-COUNT = TOT-REC-COUNT + 1.                     
         GO TO 3000-PROCESS.                                             
  3500-REC-NOT.                                                         
       CLOSE INFILE-1.                                                   
        CLOSE OUTFILE-1.                                                 
        COMPUTE REC-COUNT-PRCNT =                                         
                        (REC-COUNT / TOT-REC-COUNT) * 100.               
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Sep 17, 2007 9:30 pm
Reply with quote

Hello,

Quote:
Try this one.
If its wrong correct me.
How are the percent and count fields defined? Did you run this code on your system? What result did you get?
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