Skip to main content

Processing tab delimited data.

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

Processing text files containing "tab" delimited data.

Resolution:

Create an "extfh.cfg" File Handler Configuration file with these settings. (TABXMPL.TXT is a text file name that contains "tab" characters.

    [XFH-DEFAULT]

    BASENAME=ON

    [TABXMPL.TXT]

    EXPANDTAB=OFF

The default setting turns BASENAME ON. The TABXMPL.TXT setting turns EXPANDTAB OFF for a file named "tabxmpl.txt". This will preserve the "tab" characters as each record is read making it possible for a program to detect these characters in a text file record.

The following is an example program that will isolate each element of data delimited by a "tab" character.

      $ set Ans85 Mf"10" NoOsvs NoVsc2 NoAlter NoQual DefaultByte"00"

           select textFile assign 'tabxmpl.txt'

                           organization line sequential

                           file status fileStatus.

       fd  textFile.

       01   textFileRecord  pic x(80).

       working-storage section.

       01   fileStatus.

             02   fileStatus1     pic x.

             02   runTimeError pic x   comp-x.

       77  nameArray       occurs 25 times indexed by nAIndex

                                         pic x(25).

       77  stringPointer   pic x   comp-x.

       78  tab                     value x'09'.

       local-storage section.

       procedure division.

           open input textFile

           perform until fileStatus <> '00'

             read textFile

             at end

               close textFile

               move '10' to fileStatus

             not at end

               call 'unstringNames'

             end-read

           end-perform

           if fileStatus <> '00' and <> '10'

             if fileStatus1 = '9'

               display 'Run-time error = 9/' runTimeError '.'

             else

               display 'File status = ' fileStatus '.'

             end-if

           end-if

           stop run.

       entry 'unstringNames'.

           set stringPointer to 1

           perform varying nAIndex from 1 by 1

           until stringPointer > length of textFileRecord

             unstring textFileRecord delimited by tab

                 into nameArray(nAIndex)

                 with pointer stringPointer

             end-unstring

             display nameArray(nAIndex)

           end-perform

           exit program.

See Related tab for a complete example project including test data.

Attachments:

Tabxmpl.zip

Old KB# 5247

#ServerExpress
#AcuCobol
#netexpress
#RMCOBOL
#COBOL

0 replies

Be the first to reply!