       IDENTIFICATION DIVISION.
       PROGRAM-ID. PRTEST.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER. P3500.
       OBJECT-COMPUTER. P3500.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
		SELECT ADATEI ASSIGN TO RANDOM, "ADATEI.DAT"
		ORGANIZATION IS INDEXED,
		ACCESS MODE IS DYNAMIC,
		RECORD KEY IS A-KEY,
		ALTERNATE RECORD KEY IS AI2 WITH DUPLICATES,
		FILE STATUS IS FS.
		SELECT BDATEI ASSIGN TO RANDOM, "BDATEI.DAT"
		ORGANIZATION IS RELATIVE,  
		ACCESS MODE IS DYNAMIC,   
		RELATIVE KEY IS B-KEY,
		FILE STATUS IS FS.
		SELECT PROT ASSIGN TO PRINT, "PRINTER".
       DATA DIVISION.
       FILE SECTION.
       FD ADATEI
		LABEL RECORD STANDARD.
       01	ASATZ.
		03 A-KEY	PIC X(5).
		03 AI2		PIC X(5).
		03 AI3		PIC 9(5).
		03 AI4		PIC X(5).
		03 AI5		PIC 9(5).
		03 AI6		PIC X(5).
		03 AI7		PIC 9.
		03 AI8		PIC X.
		03 AREST	PIC X(38).
       FD	BDATEI
                BLOCK CONTAINS 3 RECORDS
		LABEL RECORD STANDARD.
       01	BSATZ.
		03 BI1		PIC 9(5).
		03 BI2		PIC X(5).
		03 BI3		PIC 9(5).
		03 BI4		PIC X(5).
		03 BI5		PIC 9(5).
		03 BI6		PIC X(5).
		03 BI7		PIC 9.
		03 BI8		PIC X.
		03 BREST		PIC X(38).
       FD	PROT
		LABEL RECORD OMITTED.
       01	PSATZ.
		03 PP1		PIC ZZZ9(7).
		03 PP2		PIC X(7).  
		03 PP3		PIC ZZ9(5)BB.
		03 PP4.
			05 PP5	PIC X(12).
			05 PP6  PIC XX.
			05 PP7  PIC XX.
			05 PP8  PIC XX.
			05 PP9  PIC X(52).

       WORKING-STORAGE SECTION.
       01      END-OF-PRINT    PIC 999 COMP-1 VALUE 127.
       01	B-KEY		PIC 9(5).
       01	FS		PIC XX.
       01	FS1		PIC XX.
       01	FS2		PIC XX.
       01	BUF		PIC X(70).
       01	EING.
		03 S		PIC 9.
		03 DAT		PIC 9.
		03 NR		PIC 9(5).
       PROCEDURE DIVISION.
       DECLARATIVES.
       FEHLER SECTION.
		USE AFTER ERROR PROCEDURE ON ADATEI, BDATEI.
       FFA.
		DISPLAY " FEHLER ", DAT, " ", A-KEY, " ", B-KEY,
		        " ", FS.
		MOVE DAT TO PP1, MOVE A-KEY TO PP2
		MOVE B-KEY TO PP3
		MOVE "FILE-STATUS " TO PP5, MOVE FS TO PP6.
		MOVE SPACES TO PP7.         
		MOVE SPACES TO PP8.
		MOVE SPACES TO PP9.
      *  	WRITE PSATZ.
       END DECLARATIVES.
       ABLAUF SECTION.
       ANF.
		OPEN I-O ADATEI, BDATEI.
		OPEN OUTPUT PROT.
		MOVE SPACES TO A-KEY.
                MOVE ZEROES TO B-KEY, FS, FS1, FS2, S, DAT, NR.
		MOVE SPACES TO BUF.
       AAA.
                DISPLAY "Eingabe nmkkkkk,(n=aktion,m=datei,kkkkk=key)" 
                DISPLAY "n=1:read,2:rewrite,3:unlock,5:stop,6:write,"
                "7:delete; m=1:ADAT,2:BDAT".       
		ACCEPT EING NO BEEP.
		GO TO A1A, A2A, A3A, A4A, A5A, A6A, A7A DEPENDING ON S.
		GO TO AAA.
       A1A.
      *		READ SATZ
		IF DAT = 1 PERFORM A1B.
		IF DAT = 2 PERFORM A1C.
		GO TO A1D.
       A1B.
		MOVE NR TO A-KEY.
		READ ADATEI INTO BUF.
       A1C.
		MOVE NR TO B-KEY.
		READ BDATEI INTO BUF.
       A1D.
		DISPLAY BUF.
       A1E.
		GO TO A9A.
       A2A.
                DISPLAY BUF.
		DISPLAY "AENDERUNG EINGEBEN:".
		ACCEPT BUF NO BEEP.
		IF DAT NOT EQUAL 1 GO TO A2B.
		MOVE BUF TO ASATZ REWRITE ASATZ.
		GO TO A9A.
       A2B.
		MOVE BUF TO BSATZ REWRITE BSATZ.
		GO TO A9A.
       A3A.
		IF DAT = 1 UNLOCK ADATEI RECORD GO TO A9A.
		IF DAT = 2 UNLOCK BDATEI RECORD GO TO A9A.
		UNLOCK ADATEI RECORD.
		UNLOCK BDATEI RECORD.
		GO TO A9A.
       A4A.
		MOVE SPACES TO ASATZ.
		IF DAT = 1 START ADATEI KEY > A-KEY.
                IF DAT = 3 START ADATEI KEY > AI2.
       A4B.      
                READ ADATEI NEXT RECORD INTO BUF AT END GO TO AAA.
                DISPLAY BUF DISPLAY "weiter (J,N)? " ACCEPT S NO BEEP.
                IF S = "N" OR S = "n" GO TO AAA ELSE GO TO A4B.
       A5A.
      *         WRITE PSATZ FROM END-OF-PRINT.
		CLOSE PROT NO REWIND, ADATEI, BDATEI. 
                DISPLAY "FILE CLOSED, WEITER? " ACCEPT S NO BEEP.
                IF S = "N" OR S= "n" STOP RUN.
                GO TO ANF.
       A6A.
		DISPLAY "SATZ EINGEBEN:".
		ACCEPT BUF.
		IF DAT NOT EQUAL 1 GO TO A6B.
		MOVE BUF TO ASATZ WRITE ASATZ.
		GO TO A9A.
       A6B.
		MOVE BUF TO BSATZ.
		MOVE NR TO B-KEY WRITE BSATZ.
		GO TO A9A.
       A7A.
		IF DAT NOT EQUAL 1 GO TO A7B.
		MOVE NR TO A-KEY.
		DELETE ADATEI.
		GO TO A9A.
       A7B.
		MOVE NR TO B-KEY.
		DELETE BDATEI.
		GO TO A9A.
       A9A.
		MOVE EING TO PP1.
		MOVE A-KEY TO PP2.
		MOVE B-KEY TO PP3.
		MOVE BUF TO PP4.
      *         WRITE PSATZ.
		MOVE SPACES TO BUF.
		GO TO AAA.
