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
 

 

Percentage calculation in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
venkatarao

New User


Joined: 19 Dec 2004
Posts: 24
Location: hyderabad

PostPosted: Sun Sep 16, 2007 11:17 pm    Post subject: Percentage calculation in cobol
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: 2150
Location: At my coffee table

PostPosted: Sun Sep 16, 2007 11:49 pm    Post subject: Re: Percentage calculation in cobol
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

Site Director


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

PostPosted: Mon Sep 17, 2007 1:16 am    Post subject:
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

Site Director


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

PostPosted: Mon Sep 17, 2007 8:18 am    Post subject:
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    Post subject: Percentage
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

Site Director


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

PostPosted: Mon Sep 17, 2007 9:30 pm    Post subject:
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    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 Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm
No new posts Submit job from Cobol with input data abdulrafi COBOL Programming 4 Wed Feb 01, 2017 12:41 pm


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