Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
venkatarao

New User

Joined: 19 Dec 2004
Posts: 24

 Posted: Sun Sep 16, 2007 11:17 pm    Post subject: Percentage calculation in cobol 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.

CICS Guy

Senior Member

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

Posted: Sun Sep 16, 2007 11:49 pm    Post subject: Re: Percentage calculation in cobol

 venkatarao wrote: But some times it is not giving percentage properly.
Could you give an example of what you consider not proper?
dick scherrer

Site Director

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

 Posted: Mon Sep 17, 2007 1:16 am    Post subject: 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.
dick scherrer

Site Director

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

Posted: Mon Sep 17, 2007 8:18 am    Post subject:

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.
logeswarank
Warnings : 1

New User

Joined: 15 Oct 2006
Posts: 22
Location: Chennai

Posted: Mon Sep 17, 2007 3:53 pm    Post subject: Percentage

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.
dick scherrer

Site Director

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

Posted: Mon Sep 17, 2007 9:30 pm    Post subject:

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?
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us