home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l360 / 3.ddi / EXTFILE.@BL / EXTFILE.CBL
Encoding:
Text File  |  1991-04-08  |  4.8 KB  |  153 lines

  1.       $set ans85 mf noosvs
  2.       ************************************************************
  3.       *                                                          *
  4.       *              (C) Micro Focus Ltd. 1989                   *
  5.       *                                                          *
  6.       *                     EXTFILE.CBL                          *
  7.       *                                                          *
  8.       *    This program demonstrates how to use EXTERNAL files.  *
  9.       *    It calls WRITEFIL to write some records to a data     *
  10.       *    file and READFILE to read the same records back       *
  11.       *    (without opening or closing the file between calls).  *
  12.       *    READFILE displays the output.                         *
  13.       *                                                          *
  14.       ************************************************************
  15.        identification division.
  16.        program-id. extfile.
  17.        environment division.
  18.        input-output section.
  19.        file-control.
  20.            select finfile assign to "isamfil.dat"
  21.                organization is indexed
  22.                record key is fd-tran-date
  23.                access mode is dynamic.
  24.  
  25.        file section.
  26.        fd finfile
  27.           is external
  28.           record contains 50 characters.
  29.        01 fd-finfile-record.
  30.            05 fd-tran-date     pic x(4).
  31.            05 fd-with-or-dep   pic x(2).
  32.            05 fd-amount        pic 9(5)v99.
  33.  
  34.  
  35.        procedure division.
  36.        main-line.
  37.            perform open-file
  38.            perform write-to-the-file
  39.            perform start-file
  40.            perform read-the-file
  41.            perform close-file
  42.            stop run.
  43.  
  44.        open-file.
  45.            open i-o finfile.
  46.  
  47.        start-file.
  48.            move 1111 to fd-tran-date
  49.            start finfile key = fd-tran-date.
  50.  
  51.        write-to-the-file.
  52.            call "writefil".
  53.  
  54.        read-the-file.
  55.            call "readfile".
  56.  
  57.        close-file.
  58.            close finfile.
  59.        end program extfile.
  60.       ************************************************************
  61.        identification division.
  62.        program-id. readfile.
  63.        environment division.
  64.        input-output section.
  65.        file-control.
  66.            select finfile assign to "isamfil.dat"
  67.                organization is indexed
  68.                record key is fd-tran-date
  69.                access mode is dynamic.
  70.  
  71.        file section.
  72.        fd finfile
  73.           is external
  74.           record contains 50 characters.
  75.        01 fd-finfile-record.
  76.            05 fd-tran-date     pic x(4).
  77.            05 fd-with-or-dep   pic x(2).
  78.            05 fd-amount        pic 9(5)v99.
  79.  
  80.        working-storage section.
  81.        01 ws-end-of-file       pic 9       value 0.
  82.        01 ws-subtotal          pic s9(5)v99 value 0.
  83.        01 ws-total             pic -(4)9.99.
  84.  
  85.        procedure division.
  86.        main-line.
  87.            perform read-the-file.
  88.            perform until ws-end-of-file = 1
  89.                perform calculate-totals
  90.                perform read-the-file
  91.            end-perform.
  92.            perform display-output.
  93.            exit program.
  94.            stop run.
  95.  
  96.        read-the-file.
  97.            read finfile next record at end move 1 to ws-end-of-file.
  98.  
  99.        calculate-totals.
  100.            evaluate fd-with-or-dep
  101.              when "WI"
  102.                  subtract fd-amount from ws-subtotal
  103.              when "DE"
  104.                  add fd-amount to ws-subtotal
  105.            end-evaluate.
  106.  
  107.        display-output.
  108.            move ws-subtotal to ws-total
  109.            display "account balance = ", ws-total.
  110.  
  111.        end program readfile.
  112.       ************************************************************
  113.        identification division.
  114.        program-id. writefil.
  115.        environment division.
  116.        input-output section.
  117.        file-control.
  118.            select finfile assign to "isamfil.dat"
  119.                organization is indexed
  120.                record key is fd-tran-date
  121.                access mode is dynamic.
  122.  
  123.        file section.
  124.        fd finfile
  125.           is external
  126.           record contains 50 characters.
  127.        01 fd-finfile-record.
  128.            05 fd-tran-date     pic x(4).
  129.            05 fd-with-or-dep   pic x(2).
  130.            05 fd-amount        pic 9(5)v99.
  131.  
  132.        procedure division.
  133.        main-line.
  134.            perform write-records
  135.            exit program
  136.            stop run.
  137.  
  138.        write-records.
  139.  
  140.       * write a WIthdrawal record
  141.            move 1111 to fd-tran-date.
  142.            move 'WI' to fd-with-or-dep.
  143.            move 23.55 to fd-amount.
  144.            write fd-finfile-record.
  145.  
  146.       * write a DEposit record
  147.            move 2222 to fd-tran-date.
  148.            move 'DE' to fd-with-or-dep.
  149.            move 123.55 to fd-amount.
  150.            write fd-finfile-record.
  151.  
  152.        end program writefil.
  153.