MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Median function for a numeric field in a large file

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Sun Dec 01, 2002 10:48 pm    Post subject: Median function for a numeric field in a large file Reply with quote

Code:

IDENTIFICATION DIVISION.                                         
 PROGRAM-ID.    MEDIAN.                                             
 AUTHOR.        KOLUSU.                                           
 DATE-WRITTEN.  12/01/2002                                       
 DATE-COMPILED.                                                   
******************************************************************
 ENVIRONMENT DIVISION.                                           
******************************************************************
 CONFIGURATION SECTION.                                           
                                                                 
 SPECIAL-NAMES.                                                   
                                                                 
 INPUT-OUTPUT SECTION.                                           
                                                                 
 FILE-CONTROL.                                                   
                                                                 
      SELECT INPUT-PARM-FILE                                     
             ASSIGN TO INPARM                                     
             ORGANIZATION IS SEQUENTIAL.                         
                                                                 
******************************************************************
 DATA DIVISION.                                                   
******************************************************************
                                                                 
 FILE SECTION.                                                   
                                                                 
 FD  INPUT-PARM-FILE                                             
     RECORDING MODE F                                             
     LABEL RECORDS ARE STANDARD                                   
     BLOCK CONTAINS 0 RECORDS                                     
     DATA RECORD IS INPUT-PARM-REC.                               
                                                                 
 01  INPUT-PARM-REC.                                             
     05  I-DMD           PIC S9(9) COMP.                         
                                                                 
******************************************************************
 WORKING-STORAGE SECTION.                                         
******************************************************************
 01 T-MED-TABLE.                                                 
    05 T-COUNT                   PIC S9(4) COMP.                 
    05 T-MED-REC                 OCCURS 0 TO 100000 TIMES         
                                 DEPENDING ON T-COUNT.           
       10 T-NUM                  PIC S9(9) COMP.                 
                                                                 
                                                                 
 01 S-INPUT-PARM-EOF             PIC X(01)  VALUE 'N'.           
                                                                 
 01 W-MEDIAN                     PIC S9(9) COMP.                 
 01 W-SUB                        PIC S9(9) COMP.                 
                                                                 
******************************************************************
 PROCEDURE DIVISION.                                             
******************************************************************
                                                                 
 0000-MAINLINE.                                                   
                                                                 
     PERFORM 1000-INITIALIZE                                     
                                                                 
     COMPUTE W-MEDIAN  = FUNCTION MEDIAN(T-NUM(ALL))             
                                                                 
     DISPLAY 'THE MEDIAN IS :' W-MEDIAN                           
                                                                 
     GOBACK                                                       
     .                                                           
                                                                 
 1000-INITIALIZE.                                                 
******************************************************************
* THIS PARAGRAPH IS PERFOMED TO OPEN THE INPUT FILE AND          *
* PRIMER READ OF THE FILE.                                       *
******************************************************************
                                                                 
      OPEN INPUT  INPUT-PARM-FILE                                 
                                                                 
      PERFORM 2000-READ-PARM-FILE                                 
                                                                 
      PERFORM 1200-LOAD-TABLE.                                   
                                                                 
      CLOSE  INPUT-PARM-FILE                                     
      .                                                           
                                                                 
 1200-LOAD-TABLE.                                                 
******************************************************************
* THIS PARA LOADS INPUT FILE TO INTERNAL TABLE                   *
******************************************************************
                                                                 
      PERFORM VARYING W-SUB FROM 1 BY 1                           
        UNTIL S-INPUT-PARM-EOF = 'Y'                             
           OR W-SUB   > 100000                                   
         MOVE I-DMD               TO T-NUM(W-SUB)                 
                       
         PERFORM 2000-READ-PARM-FILE                             
      END-PERFORM                                                 
      .                                                           
                                                                 
 2000-READ-PARM-FILE.                                             
******************************************************************
* THIS PARAGRAPH IS PERFORMED TO READ THE INPUT FILE.            *
******************************************************************
                                                                 
      READ INPUT-PARM-FILE                                       
         AT END                                                   
             MOVE 'Y'           TO S-INPUT-PARM-EOF               
         NOT AT END                                               
           ADD +1               TO T-COUNT                       
      END-READ                                                   
      .
                                                           
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group