       IDENTIFICATION DIVISION.
       PROGRAM-ID.  SOFCRGET.
       AUTHOR.      LIMES DATENTECHNIK GMBH.
      *
      *           EXAMPLE FOR USING FLUC RECORD INTERFACE
      *
      *  SOFCRGET READS WITH THE FLUC-RECORD-INTERFACE A TEXT FILE. THE
      *           THE FILE CAN BE COMPRESSED (GZIP/BZIP2/XZ(LZMA)) OR
      *           NOT AND MUST BASED ON TEXT DELIMITER
      *
      *  DD-NAMES USED IN THIS EXAMPLE:
      *
      *    INPUT  THE FILE FLUC HAS TO READ
      *    OUTPUT OUR OUTPUT DATA SET
      *
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER.                IBM-370.
       OBJECT-COMPUTER.                IBM-370.
       SPECIAL-NAMES.
           CLASS CLASS-DSN                                              PG
           'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.#'                     PG000018
      *    *************************************************************
      *    ORG: ORIGINAL FILE
      *    *************************************************************
      * *** SECTION GENERATED BY $APS-SPECIAL-NAMES ***
           CURRENCY SIGN IS '$'
           DECIMAL-POINT IS COMMA
           .
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT OUTDAT ASSIGN TO OUTDAT
           STATUS OX-FSTAT
           ACCESS MODE IS SEQUENTIAL.
      *
       DATA DIVISION.
      *   BLOCK CONTAINS 0 CHARACTERS
       FILE SECTION.
       FD  OUTDAT
           LABEL RECORD STANDARD
           RECORD IS VARYING IN SIZE FROM 1 TO 2040 CHARACTERS
           DEPENDING ON OUTLEN
           RECORDING MODE IS V.
       01  OUTDAT-RECORD.
           05 FILLER   PIC X(2040).
      *
       WORKING-STORAGE SECTION.
      *
       01  W-RECBUF    PIC X(2040).

       01  OPERATION   PIC  X(6).
       01  MAXLEN      PIC  9(5) VALUE 2040.
      *
       01  HELLO       PIC  X(08)
                       VALUE 'HELLO'.
       01  FLUC-PARAMETER.
      *    
      *  USED FOR ALL FLUC-CALLS
      *
           05 F-ID     PIC S9(8)  COMP
                       SYNCHRONIZED.
           05 F-RETCO  PIC S9(8)  COMP
                       SYNCHRONIZED.
              88 FLUCOK            VALUE  0.
              88 END-OF-FILE       VALUE  43.
      *
      *  USED FOR FLUC OPEN
      *
           05  F-FILELEN  PIC S9(8)  COMP SYNC VALUE 60.
           05  F-FILE     PIC X(60)  VALUE
               'READ.TEXT(FILE=''DD:INPUT'' RECLEN=2040)'.
      *         'READ.BIN(FILE=''DD:INPUT'')'.
           05  F-FORMLEN  PIC S9(8)  COMP SYNC VALUE 20.
           05  F-FORM     PIC X(20)  VALUE
               'CCSID=default'.
           05  F-STATLEN  PIC S9(8)  COMP SYNC VALUE 512.
           05  F-STAT     PIC X(512) VALUE ' '.
      *
      *  USED FOR FLUC GET
      *
           05  F-INLEN   PIC S9(8) COMP SYNC.
           05  F-RECBUF  PIC X(32752).
      *
      *  USED FOR FLUC MSG
      *
           05  MSGRC     PIC S9(8) COMP SYNC.
           05  MSGLEN    PIC S9(8) COMP SYNC VALUE 8000.
           05  MSGBUFF   PIC X(8000) VALUE SPACES.
      *
      *  USED FOR FLUC CLS
      *
           05  C-DELETE  PIC S9(8) COMP SYNC VALUE 0.
           05  C-STATFMT PIC S9(8) COMP SYNC VALUE 1.
           05  C-STATLEN PIC S9(8) COMP SYNC VALUE 4096.
           05  C-STATBUF PIC X(4096) VALUE SPACES.

           05  FCROPN      PIC  X(08)
                           VALUE 'fcropn'.
           05  FCRGET      PIC  X(08)
                           VALUE 'fcrget'.
           05  FCRCLS      PIC  X(08)
                           VALUE 'fcrcls'.
           05  FCRMSG      PIC  X(08)
                           VALUE 'fcrmsg'.
           05  FCRTRC      PIC  X(08)
                           VALUE 'fcrtrc'.

           05  PTR         USAGE POINTER.

       01  OX-P.
           05  OX-FSTAT    PIC X(02) VALUE SPACES.
           05  DBEFORE     PIC 9(05) VALUE ZERO.
           05  OUTLEN      PIC 9(05) VALUE ZERO.
           05  DAFTER      PIC 9(05) VALUE ZERO.
           05  COUNTER     PIC 9(05) VALUE 0.

       PROCEDURE DIVISION.
      *
      * MAIN SECTION.
      *
       OPEN-OUTPUT-DATA.
      *
      *  OPEN DATA SET TO WRITE RECORDS
      *
           DISPLAY 'open output ...' OX-FSTAT UPON CONSOLE
           OPEN OUTPUT OUTDAT
           IF OX-FSTAT NOT = ZEROES
               DISPLAY 'open output failed' OX-FSTAT UPON CONSOLE
               GO TO CLOSE-DATA.
      *
       OPEN-FLUC.
      *
      *  CALL THE FLAM UNIVERSAL CONVERTER MODULE FOR OPEN
      *
           DISPLAY 'call FCROPN ... ' F-FILE FCROPN UPON CONSOLE
      *    CALL HELLO USING F-FILE
           MOVE  0 TO F-RETCO
           CALL  FCROPN USING F-ID, F-RETCO,
                                F-FILELEN, F-FILE,
                                F-FORMLEN, F-FORM,
                                F-STATLEN, F-STAT.
           IF  NOT FLUCOK
              THEN  MOVE 'OPEN' TO OPERATION
                    PERFORM FLUC-ERROR
                    GO TO CLOSE-DATA.

      *     DISPLAY 'FSTAT:' F-STAT UPON CONSOLE.
           DISPLAY 'init recbuf ...' UPON CONSOLE
           MOVE SPACES TO W-RECBUF.

       READ-RECORD.
      *
      *  READ A RECORD WITH FLAM IN OUTPUT AREA
      *
           ADD 1 TO COUNTER
      *     DISPLAY 'COUNTER = ' COUNTER UPON CONSOLE
           MOVE MAXLEN TO F-INLEN
      *     SET PTR TO ADDRESS OF F-RECBUF
      *     DISPLAY 'F-RECBUF is at ' PTR UPON CONSOLE
      *     SET PTR TO ADDRESS OF FCRGET
      *
      *     DISPLAY 'call FCRGET len=' F-INLEN ' ptr=' F-ID UPON
      *     CONSOLE
           CALL FCRGET USING F-ID, F-RETCO,
                             F-INLEN, F-RECBUF
      *
      *     DISPLAY 'GOT:' F-INLEN UPON CONSOLE
      *     SET PTR TO ADDRESS OF F-RECBUF
      *     DISPLAY '[]F-RECBUF is at ' PTR UPON CONSOLE
      *     SET PTR TO ADDRESS OF FCRGET
      *     DISPLAY COUNTER '[-->] FCRGET is at ' PTR UPON CONSOLE
           IF  FLUCOK
             THEN  NEXT SENTENCE
             ELSE  IF  END-OF-FILE
                      THEN DISPLAY 'EOF after ' COUNTER UPON CONSOLE
                           GO TO CLOSE-FLUC
                      ELSE MOVE 'GET' TO OPERATION
                           PERFORM FLUC-ERROR
                           GO TO CLOSE-FLUC
                      END-IF
             END-IF.
      *
      *  DO WHAT YOU LIKE WITH THE RECORD
           MOVE SPACES TO W-RECBUF
           IF F-INLEN > 0
              MOVE F-RECBUF(1:F-INLEN) TO W-RECBUF(1:F-INLEN)
           END-IF.
      *
       WRITE-RECORD.
      *
      *  WRITE THE CONVERTED RECORD
      *
           MOVE F-INLEN TO OUTLEN
      *    DISPLAY 'would write record = ' OUTLEN UPON CONSOLE
      *     IF OUTLEN = 0 THEN
      *         MOVE 1   TO OUTLEN
      *         MOVE ' ' TO OUTDAT-RECORD
      *     END-IFs
      *     DISPLAY 'record: ' W-RECBUF UPON CONSOLE
           WRITE OUTDAT-RECORD FROM W-RECBUF
           IF OX-FSTAT NOT = ZEROS
              DISPLAY 'write error: ' OX-FSTAT UPON CONSOLE
              GO TO CLOSE-FLUC
           END-IF
      *
      *     DISPLAY 'NEXT SENTENCE ... ' UPON CONSOLE
           GO TO READ-RECORD.
      *
       CLOSE-FLUC.
      *
      *  CLOSE TO FLUC
      *
           CALL FCRCLS USING F-ID, F-RETCO, C-DELETE
                             C-STATFMT, C-STATLEN, C-STATBUF
           IF  NOT FLUCOK
             THEN MOVE 'CLOSE' TO OPERATION
                  PERFORM FLUC-ERROR.
       CLOSE-DATA.
      *
      *  CLOSE OUTPUT DATA
      *
           CLOSE  OUTDAT.
       MAIN-END.
           MOVE F-RETCO  TO RETURN-CODE
      *
      *  PRINT STATISTIC
      *
           DISPLAY 'READ-STATISTIC FROM FLUC' UPON CONSOLE
           DISPLAY C-STATBUF UPON CONSOLE

           GOBACK.
      *
      * PRINT THE ERROR SITUATION
      *
       FLUC-ERROR SECTION.
       FLUC-ERROR-1.
           DISPLAY 'SOFCRGET: ERROR IN OPERATION ' OPERATION UPON
           CONSOLE
           DISPLAY 'ERROR MESSAGE FROM FLUC:' UPON CONSOLE
           MOVE F-RETCO  TO MSGRC
      *  GET THE ERROR MESSAGE
           CALL FCRMSG USING MSGRC, F-RETCO, MSGLEN, MSGBUFF
           DISPLAY MSGBUFF UPON CONSOLE
           CALL FCRTRC USING MSGRC, F-RETCO, MSGLEN, MSGBUFF
           DISPLAY 'ERROR TRACE:' MSGBUFF UPON CONSOLE.
       FLUC-ERROR-99.
           EXIT.
