       IDENTIFICATION DIVISION.
      *************************

       PROGRAM-ID. INVENTUR.

       ENVIRONMENT DIVISION.
      **********************

       CONFIGURATION SECTION.
      *----------------------

       SOURCE-COMPUTER. P3500.
       OBJECT-COMPUTER. P3500.

       INPUT-OUTPUT SECTION.
      *---------------------

       FILE-CONTROL.    
           SELECT ADATEI ASSIGN TO INPUT "ADATEI".
           SELECT DDATEI ASSIGN TO PRINT "PRINTER".

       DATA DIVISION.
      ***************

       FILE SECTION.
      *-------------

       FD  ADATEI LABEL RECORD IS STANDARD.
       01  ASATZ.
           05 ASA            PIC      9.
           05 ANR.
              07 REGAL       PIC     99.
              07 EBENE       PIC      9.
              07 FACH        PIC     99.
              07 WGR         PIC      9.
              07 ALFD        PIC     99.
           05 ABEZ           PIC  X(25).
           05 AMG            PIC    999.
           05 AEPR           PIC 999V99.
           05 AKS            PIC     99.
           05 AKSTS          PIC     99.
           05 AMBTA          PIC    999.
           05 AME            PIC     99.
           05 FILLER         PIC  X(29).

       FD  DDATEI LABEL RECORD IS OMITTED.
       01  UNI-ZEILE         PIC  X(80).
    
       WORKING-STORAGE SECTION.
      *------------------------
 
       01  DSATZ.
           05 FILLER         PIC  X(12).
           05 DREGAL         PIC     ZZ.
           05 FILLER         PIC   X(5).
           05 DEBENE         PIC      Z.
           05 FILLER         PIC   X(5).
           05 DFACH          PIC     ZZ.
           05 FILLER         PIC   X(8).
           05 DAMG           PIC ZZZZZ9.
           05 FILLER         PIC      X.
           05 DSTERN         PIC   X(6).
           05 FILLER         PIC  X(32).

       01  KOZ.
           05 FILLER         PIC  X(11).
           05 REG            PIC   X(5);    VALUE "REGAL".
           05 FILLER         PIC     XX.
           05 EBNE           PIC   X(5);    VALUE "EBENE".
           05 FILLER         PIC    XXX.
           05 FCH            PIC   X(4);    VALUE  "FACH".
           05 FILLER         PIC  X(11).
           05 MNGE           PIC   X(5);    VALUE "MENGE".
           05 FILLER         PIC     XX.
           05 STRN           PIC   X(6).
           05 FILLER         PIC  X(26).
       01  FILE-ENDE         PIC    XXX;    VALUE  SPACES.
       01  ART-MENGE.
           02 AMG-REGAL                     OCCURS     10.
              03 AMG-EBENE                  OCCURS      3.
                 04 AMG-FACH PIC    999;    OCCURS     10.
       01  SREGAL            PIC     99;    VALUE    ZERO.
       01  SEBENE            PIC      9;    VALUE    ZERO.
       01  SFACH             PIC     99;    VALUE    ZERO.
       01  GES-SUMME         PIC   9(6);    VALUE    ZERO.
       01  REG-SUMME         PIC   9(6);    VALUE    ZERO.
       01  EBN-SUMME         PIC   9(6);    VALUE    ZERO.
       01  ZEIZAE            PIC     99;    VALUE       3.
                                             	
       PROCEDURE DIVISION.
      ********************

       ANF.
           OPEN INPUT ADATEI, OUTPUT DDATEI.
           PERFORM TAB-LOESCH
               VARYING SREGAL FROM 1 BY 1
               UNTIL SREGAL > 10 
           AFTER SEBENE FROM 1 BY 1
               UNTIL SEBENE > 3
           AFTER SFACH FROM 1 BY 1
               UNTIL SFACH > 10.
       
           READ ADATEI RECORD
               AT END MOVE "EOF" TO FILE-ENDE.

           PERFORM TAB-FUELL          
               UNTIL FILE-ENDE = "EOF".
           
           PERFORM TAB-DRUCK.               
           CLOSE ADATEI, DDATEI.
           STOP RUN.

       TAB-LOESCH.
           MOVE ZEROS TO AMG-FACH(SREGAL, SEBENE, SFACH).

       TAB-FUELL.   
           MOVE REGAL TO SREGAL.
           MOVE EBENE TO SEBENE.
           MOVE FACH  TO SFACH.
           MOVE AMG   TO AMG-FACH(SREGAL, SEBENE, SFACH).
           READ ADATEI RECORD
               AT END MOVE "EOF" TO FILE-ENDE.

       TAB-DRUCK.
           WRITE UNI-ZEILE FROM KOZ 
               BEFORE ADVANCING 2 LINES.
           MOVE SPACES TO UNI-ZEILE.

           PERFORM UP-REGAL
               VARYING SREGAL FROM 1 BY 1
               UNTIL SREGAL >  2.
           MOVE GES-SUMME TO DAMG.
           MOVE "***" TO DSTERN
           IF ZEIZAE > 64 PERFORM FORM-FEED.
           WRITE UNI-ZEILE FROM DSATZ
               AFTER ADVANCING 3 LINES.
           ADD 3 TO ZEIZAE.

       UP-REGAL.
           PERFORM UP-EBENE
               VARYING SEBENE FROM 1 BY 1
               UNTIL SEBENE > 3.
           ADD REG-SUMME  TO GES-SUMME.
           MOVE REG-SUMME TO DAMG. 
           MOVE "**"   TO DSTERN.
           IF ZEIZAE > 64 PERFORM FORM-FEED.
           WRITE UNI-ZEILE FROM DSATZ
               AFTER ADVANCING 2 LINES.
           ADD 2 TO ZEIZAE.
           MOVE ZEROS  TO REG-SUMME.
           MOVE SPACES TO UNI-ZEILE.
           MOVE SPACES TO DSATZ.
  
       UP-EBENE.
           PERFORM UP-FACH
               VARYING SFACH FROM 1 BY 1
               UNTIL SFACH > 10.
           ADD EBN-SUMME TO REG-SUMME.
           MOVE EBN-SUMME TO DAMG.
           MOVE "*" TO DSTERN.        
           IF ZEIZAE > 64 PERFORM FORM-FEED.
           WRITE UNI-ZEILE FROM DSATZ
               AFTER ADVANCING 2 LINES. 
           ADD 2 TO ZEIZAE.
           MOVE ZEROS TO EBN-SUMME.
           MOVE SPACES TO UNI-ZEILE.
           MOVE SPACES TO DSATZ.
       
       UP-FACH.
           ADD AMG-FACH(SREGAL, SEBENE, SFACH) TO EBN-SUMME.
           MOVE AMG-FACH(SREGAL, SEBENE, SFACH) TO DAMG.
           MOVE SFACH TO DFACH.
           IF SFACH = 1 PERFORM UP1-FACH.
           IF ZEIZAE > 64 PERFORM FORM-FEED.
           WRITE UNI-ZEILE FROM DSATZ.
           ADD 1 TO ZEIZAE.
           MOVE SPACES TO UNI-ZEILE.
           MOVE SPACES TO DSATZ.

       UP1-FACH.
           MOVE SREGAL TO DREGAL.
           MOVE SEBENE TO DEBENE.
     
       FORM-FEED.
           WRITE UNI-ZEILE FROM KOZ
               AFTER ADVANCING PAGE.    
           MOVE SPACES TO UNI-ZEILE.
           WRITE UNI-ZEILE 
               AFTER ADVANCING 1 LINES.
           MOVE ZEROS  TO ZEIZAE.
           ADD  3 TO ZEIZAE.