subprog2.cob

 

       identification division.
       program-id. testing2.

       data division.
       working-storage section.
  
       01 table-data pic 9(18)
               value 886578929882830000.
              
       01 table-info redefines table-data.
          05 table-averages occurs 9 times pic 99.
        
       01 num-recs pic 99 value 7.
      
       01 test-avg pic 99v99.
       01 test-avg-ed pic z9.99.
      
       procedure division.
       100-main.
         
           call "avgtable" using table-info num-recs
               test-avg.

           move test-avg to test-avg-ed.   
           display "average is " test-avg-ed.

           accept omitted.

           stop run.

 

avgtable.cob

 

       identification division.

       program-id. testing.

 

       data division.

       working-storage section.

       01 a pic 99.

       01 total-test pic 9999.

      

       linkage section.

       01 num-recs pic 99.

       01 table-values.

           05 table-data occurs 9 times pic 99.

       01 avg-value pic 99v99.

      

       procedure division using table-values num-recs avg-value.

       100-main.

           perform varying a from 1 by 1 until a > num-recs

               add table-data (a) to total-test

           end-perform.

           compute avg-value = total-test / num-recs.

          

           exit program.