       IDENTIFICATION              DIVISION.
      *{Bench}prgid
       PROGRAM-ID. konvert.
       AUTHOR. ulli.
       DATE-WRITTEN. Montag, 12. Mai 2003 10:26:45.
       REMARKS. 
      *{Bench}end

       ENVIRONMENT                 DIVISION.
       CONFIGURATION               SECTION.
       SPECIAL-NAMES.
      *{Bench}activex-def
      *{Bench}end
      *{Bench}decimal-point
           DECIMAL-POINT IS COMMA.
      *{Bench}end
       INPUT-OUTPUT                SECTION.
       FILE-CONTROL.
           select s1-datei assign to disk 
           "d:\fh\cobol\ss05\quizshow.csv"
           organization line sequential.
           select optional i1-datei assign to disk "sdw.dat"
           organization indexed
           access dynamic
           record i1-key1
           alternate record i1-kat with duplicates
           file status f-rc.
      *{Bench}file-control
      *{Bench}end
       DATA                        DIVISION.
       FILE                        SECTION.
       fd s1-datei.
       01 s1-satz pic x(200).
       fd i1-datei.
       01 i1-satz.
          03 i1-key1.
             05 i1-kat       pic 99.
             05 i1-nr        pic 999.
          03 i1-frage        pic x(100).
          03 i1-antwort      pic x(50) occurs 4.

      *{Bench}file
      *{Bench}end

       WORKING-STORAGE             SECTION.
      *{Bench}acu-def
       77 f-rc pic xx.
       77 z-l  pic 999.
       77 s1-lesen pic 9.
          88 s1-ok   value 0.
          88 s1-ende value 1.
       77 i1-lesen pic 9.
          88 i1-ok   value 0.
          88 i1-ende value 1.
       77 w-nr     pic 9(5).
       77 w-pos    pic 9.
       77 w-kat    pic x.
       77 w-text   pic x(100).
       PROCEDURE DIVISION.
       s1.
      *** Dateien öffnen     
           open input s1-datei      | Record-Pointer auf 1.Datensatz
           open i-o i1-datei
           set s1-ok i1-ok to true  | Boolsche Variable setzen
      *** Leseschleife, für die Eingabedatei 
           perform until s1-ende
              initialize w-nr w-pos w-kat w-text

              initialize s1-satz    | Lesepuffer leeren
              read s1-datei next
              end
                 set s1-ende to true
              not end
                 
                 unstring s1-satz delimited by ";" into w-nr w-pos
                 w-kat w-text
                 display w-nr at 0101
                 if w-pos = 0  | Fragesatz aus CSV-Datei
                  evaluate w-kat
                  when "a"
                    move 1 to i1-kat
                  when "b"
                    move 2 to i1-kat
                  when "g"
                    move 3 to i1-kat
                  when "h"
                    move 4 to i1-kat
                  when "l"
                    move 5 to i1-kat
                  when "p"
                    move 6 to i1-kat
                  when "t"
                    move 7 to i1-kat
                  when other
                    move 8 to i1-kat
                  end-evaluate
                  move w-text to i1-frage
                 else  | eine der 4 Antworten aus CSV-Datei
                    move w-text to i1-antwort(w-pos)
                    if w-pos = 4 | letzte Antwort = Satz schreiben
                       move 1 to i1-nr
                       perform schreiben-i1
                    end-if
                 end-if
              end-read
           end-perform
           perform ende.
      *
       schreiben-i1.
      *** Schreib-Schleife, um Schreiben bei identischem PrimärKey durch 
      *** Erhöhen des Zählers sicherzustellen
           perform with test after until i1-ok
              write i1-satz
              invalid              | Schluessel existiert schon
                 add 1 to i1-nr    | Zähler um 1 erhöhen
                 set i1-ende to true
              not invalid
                 set i1-ok to true
              end-write
           end-perform
           initialize i1-satz.
      *
       ende.
           close s1-datei i1-datei | Dateien schliessen
           exit program.
           stop run.
