       IDENTIFICATION DIVISION.
       program-id. oefening-13D.
       author. Levy De Vos.
       date-written. 03-november-04.

       environment division.
        configuration section.
         source-computer. pc.
         object-computer. pc.
       input-output section.
       file-control.
           select productbestand
               assign to
               "D:\School\Back-End programmeren\product.dat"
               organization sequential
               access sequential
               file status product-status.

           select productbewegingbestand
               assign to
               "D:\School\Back-End programmeren\productbeweging.dat"
               organization sequential
               access sequential
               file status prodbew-status.


       DATA DIVISION.
        file section.
           fd productbestand.
           01 p-productrecord.
               03 p-prodnummer pic x(6).
               03 p-prodaard pic x.
               03 p-prodhoev pic 999.
           fd productbewegingbestand.
           01 pb-prodbewrecord.
               03 pb-prodnummer pic x(6).
               03 pb-prodaard pic x.
               03 pb-prodhoev pic 999.

       WORKING-STORAGE SECTION.
           01 product-status pic xx.
               88 eof-product-status value "10".
           01 prodbew-status pic xx.
               88 eof-prodbew-status value "10".
           01 ui-prodgeg.
               03 ui-prodnummer pic x(6).
               03 ui-prodaard pic x.
               03 ui-prodhoev pic 999.
           01 vorigprodnr pic x(6).
           01 vorigprodaard pic x.

       PROCEDURE DIVISION.

           perform b-prog
           perform m-o-body
           perform e-prog
           stop run
           .

           b-prog.
               open input productbestand
               open output productbewegingbestand
               read productbestand at end continue
               end-read.

           m-o-body.
               perform v-p-groep-m-o-prodbewrecord with test before
               until eof-product-status.

           e-prog.
               close productbestand
               close productbewegingbestand.

           v-p-groep-m-o-prodbewrecord.
               perform b-groep
               perform m-o-body2
               perform e-groep.

           b-groep.
               move p-prodnummer to vorigprodnr
               move p-prodnummer to ui-prodnummer
               initialize ui-prodhoev
               .

           m-o-body2.
               perform m-o-body3 with test before until
               eof-product-status or (p-prodnummer not= vorigprodnr)
               .

           e-groep.
               write pb-prodbewrecord from ui-prodgeg
               .

           m-o-body3.
               perform b-groep2.
               perform m-o-body4 with test before until
               eof-product-status or (p-prodnummer not= vorigprodnr) or
               (p-prodaard not= vorigprodaard)
               .

           b-groep2.
               move p-prodaard to vorigprodaard
               .

           m-o-body4.
               if p-prodaard = "+"
                   perform optellen
               else
                   perform aftrekken
               end-if
               .

           optellen.
               compute ui-prodhoev = ui-prodhoev + p-prodhoev
               read productbestand at end continue
               end-read
               .                                                        .

           aftrekken.
               compute ui-prodhoev = ui-prodhoev - p-prodhoev
               read productbestand at end continue
               end-read
               .                                                        .
