Comma Delimited File
 Read and Parse
http://www.simotime.com
 Copyright © 1987-2010 SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 09.05.17 
  Introduction
 
  Programming Objectives
  Programming Input and Output
  Programming Requirements
  Programming Overview
  CMD for Execution with Net Express and Windows
  The COBOL Demonstration Program
  The COBOL Parsing Program
  The COBOL Copy Files
 
  Record Layout for Column-Oriented, Fixed-Field-Length File
  Layout of Pass Area for Calling Parsing Program
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Comments or Suggestions
  About SimoTime

Introduction
(Next) (Previous) (Table-of-Contents)

This suite of sample programs describes how to read a comma-delimited file (filename.CSV, Comma-Separated-Value) of variable length strings and create a column oriented file of fixed length records and fixed length fields. If a string (or data field) contains a delimiter character then process as data. The program may be adjusted to access a delimited file using a tab, semicolon or other character as the delimiter.

Programming Objectives
(Next) (Previous) (Table-of-Contents)

This example illustrates the following functions.

1. Demonstrate how to read a comma-delimited file and create a sequential file (or a Line Sequential file) using Micro Focus COBOL (Net Express was used for the testing).
2. Demonstrate how to parse the comma-delimited string and create fixed-length fields for standard COBOL processing.
3. Demonstrate how to omit blank records from the output file.
4. Provide an example of a Window's CMD file to run the job on Windows using Micro Focus Net Express.

Programming Input and Output
(Next) (Previous) (Table-of-Contents)

The following is an example of a Comma Delimited file that was that was used to create a Sequential (or LINE Sequential) file that contained records with predefined, fixed fields. This file was created using Microsoft Excel.

000000000100,Anderson,Adrian,"111 Peachtree Plaza, Suite 111",Atlanta,GA
000000000200,Brown,Billie,222 Baker Boulevard,Baltimore,MD
000000000300,Carson,Cameron,333 Crenshaw Blvd.,Cupertino,CA
000000000400,Davidson,Dion,444 Main Street,Wilmington,DE
000000000500,Everest,Evan,555 5TH Avenue,New york,NY
000000000600,Franklin,Francis,666 66TH Avenue,Bedrock,NY
000000000700,Garfunkel,Gwen,777 77TH Street,New york,NY
000000000800,Harrison,Hilary,888 88TH Street,Pocatello,ID
000000000900,Isley,Isabel,999 99TH Avenue,Indianapolis,IN
000000001000,Johnson,Jamie,1010 Paradise Drive,Larkspur,CA
000000001100,Kemper,Kelly,1111 Oak Circle,Kansas City,KS
000000001200,Lemond,Lesley,1212 Lockwood Road,Mohave Desert,AZ
000000001300,Mitchell,Marlow,1313 Miller Creek Road,Anywhere,TX
000000001400,Newman,Noel,1414 Park Avenue,Santa Monica,CA
000000001500,Osborn,Owen,1515 Center Stage,Rolling Rock,PA
000000001600,Powell,Pierce,1616 Central Avenue,Ventura,CA
000000001700,Quigley,Quincy,1717 Farm Hill Road,Oshkosh,WI
000000001800,Ripley,Ray,1818 Alien Lane,Wayout,KS
000000001900,Smith,Sammy,1919 Carnoustie Drive,Novato,CA
000000002000,Tucker,Taylor,2020 Sanger Lane,St. Paul,MN
000000002100,Underwood,Ulysses,2121 Wall Street,New York,NY
000000002200,Victoria,Vaughn,"2222 Vine Street, #22",Hollywood,CA
000000002300,Wilson,Wiley,"2323 Main Street, #23",Boston,MA
000000002400,Xray,Xavier,2424 24TH Street,Nashville,TN
000000002500,Young,Yanni,2525 Yonge Street,Toronto,ON
000000002600,Zenith,Zebulon,2626 26TH Street,Dallas,TX
000000123456,Doe,John,123 Main Street,Anywhere,OR
000000999999,Smith,,99 E Street,San Rafael,CA

The following is an example of a sequential (or Line Sequential) file that contains records with predefined, fixed-length fields. This file was created by a COBOL program that read and parsed strings in a Comma Delimited file (filename.CSV).The customer number is in positions 1 through 12. Notice that customer numbers 000000002200, 000000002300 and 000000999999 contain examples of fields with leading spaces and fields that contain a comma in the data string. All the records have trailing spaces in the fields.

The following is the record layout for COBOL.

       01  CUSTTEXT-RECORD.
           05  CUSTTEXT-KEY            PIC X(12).
           05  FILLER                  PIC X.
           05  CUSTTEXT-LAST-NAME      PIC X(28).
           05  CUSTTEXT-FIRST-NAME     PIC X(20).
           05  CUSTTEXT-STREET-ADDRESS PIC X(48).
           05  CUSTTEXT-CITY           PIC X(16).
           05  CUSTTEXT-STATE          PIC X(2).
           05  FILLER                  PIC X(385).

The following is the LINE SEQUENTIAL (ASCII/Text ) file that was used for testing the programs.

000000000100 Anderson                    Adrian              111 Peachtree Plaza, Suite 111                  Atlanta         GA
000000000200 Brown                       Billie              222 Baker Boulevard                             Baltimore       MD
000000000300 Carson                      Cameron             333 Crenshaw Blvd.                              Cupertino       CA
000000000400 Davidson                    Dion                444 Main Street                                 Wilmington      DE
000000000500 Everest                     Evan                555 5TH Avenue                                  New york        NY
000000000600 Franklin                    Francis             666 66TH Avenue                                 Bedrock         NY
000000000700 Garfunkel                   Gwen                777 77TH Street                                 New york        NY
000000000800 Harrison                    Hilary              888 88TH Street                                 Pocatello       ID
000000000900 Isley                       Isabel              999 99TH Avenue                                 Indianapolis    IN
000000001000 Johnson                     Jamie               1010 Paradise Drive                             Larkspur        CA
000000001100 Kemper                      Kelly               1111 Oak Circle                                 Kansas City     KS
000000001200 Lemond                      Lesley              1212 Lockwood Road                              Mohave Desert   AZ
000000001300 Mitchell                    Marlow              1313 Miller Creek Road                          Anywhere        TX
000000001400 Newman                      Noel                1414 Park Avenue                                Santa Monica    CA
000000001500 Osborn                      Owen                1515 Center Stage                               Rolling Rock    PA
000000001600 Powell                      Pierce              1616 Central Avenue                             Ventura         CA
000000001700 Quigley                     Quincy              1717 Farm Hill Road                             Oshkosh         WI
000000001800 Ripley                      Ray                 1818 Alien Lane                                 Wayout          KS
000000001900 Smith                       Sammy               1919 Carnoustie Drive                           Novato          CA
000000002000 Tucker                      Taylor              2020 Sanger Lane                                St. Paul        MN
000000002100 Underwood                   Ulysses             2121 Wall Street                                New York        NY
000000002200 Victoria                    Vaughn              2222 Vine Street, #22                           Hollywood       CA
000000002300 Wilson                      Wiley               2323 Main Street, #23                           Boston          MA
000000002400 Xray                        Xavier              2424 24TH Street                                Nashville       TN
000000002500 Young                       Yanni               2525 Yonge Street                               Toronto         ON
000000002600 Zenith                      Zebulon             2626 26TH Street                                Dallas          TX
000000123456 Doe                         John                123 Main Street                                 Anywhere        OR
000000999999 Smith                                              99 E Street                                   San Rafael     CA

Programming Requirements
(Next) (Previous) (Table-of-Contents)

This suite of samples programs will run on the following platforms.

1. Executes on Windows/2000, Windows/NT and Windows/XP using Micro Focus Net Express and the CMD file provided.
2. May be ported to run on the UNIX platforms supported by Micro Focus COBOL.

Programming Overview
(Next) (Previous) (Table-of-Contents)

The following is a flowchart of the job for executing the program to create a Comma Delimited file from a Sequential file of fixed-length fields.

   
CBLCSVE2
cmd
      Start the Job
   
 
       
CSVGETD1
comma-delimit
CBLCSVC2
cobol
     
     
TXTPUTD1
sequential
  Read a comma-delimited file and create a Sequential file
   
 
 
     
   
 
     
     
SIMOPARS
cobol
   
   
EOJ
      End-of-Job
             

The main program (CBLCSVC1) will read a Sequential file (TXTGETD1) and produce a 128-byte, variable record length Comma-delimited sequential file (CSVPUTD1). The contents of this file will be variable length fields separated by a comma. The leading and trailing spaces will be removed from each field. Embedded spaces will remain. The source code for the CMD file, the JCL member and the COBOL programs is provided and may be modified to fit your environment.

CMD for Execution with Net Express and Windows
(Next) (Previous) (Table-of-Contents)

The following (CBLCSVE2.CMD) is a sample of the Windows CMD needed to run this job.

@echo OFF
echo * CblCsvE2 is Starting...
rem  * *******************************************************************
rem  *                   This program is provided by:                    *
rem  *                    SimoTime Enterprises, LLC                      *
rem  *           (C) Copyright 1987-2010 All Rights Reserved             *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem  *
rem  * Text    - COBOL for Comma Delimited File processing
rem  * Author  - SimoTime Enterprises
rem  * Date    - December 12, 2003
rem  * Version - 03.12.15
rem  *
rem  * This set of programs illustrates the use a COBOL program read a
rem  * comma-delimited file and create a fixed-field file.
rem  *
rem  * The COBOL program is compiled with the ASSIGN(EXTERNAL) directive.
rem  * This provides for external file mapping of the file names.
rem  *
rem  * This set of programs will run on a Personal Computer with Windows
rem  * and Micro Focus Net Express.
rem  *
rem  *                     ************
rem  *                     * CblCsvE2 *
rem  *                     ********cmd*
rem  *                          *
rem  *                          *
rem  *    ************     ************     ************
rem  *    * CSVGETD1 ******* CblCsvC2 ******* TXTPUTD1 *
rem  *    ********txt*     ********cbl*     ********csv*
rem  *                          *
rem  *                          *
rem  *                     ************
rem  *                     *   EOJ    *
rem  *                     ************
rem  *
rem  * *******************************************************************
rem  * Step   1 of 1  This is a single step job.
rem  *
     set CSVGETD1=d:\simoNXE4\AN01\DataCsv1\ExcelCommaDelimited.csv
     set TXTPUTD1=d:\simoNXE4\AN01\DataWrk1\TxtPutD1.txt
     CblCsvC2
     echo * CblCsvE2 is Finished...
pause

The COBOL Demonstration Program
(Next) (Previous) (Table-of-Contents)

The following (CBLCSVC1.CBL) is a sample of the Micro Focus COBOL demonstration program. This program will not compile or execute on an IBM Mainframe because of the ORGANIZATION IS LINE SEQUENTIAL on the SELECT statement. If the statement was changed to read ORGANIZATION IS SEQUENTIAL it would run on an IBM Mainframe and "read from" and "write to" a sequential file. The program was tested using Micro Focus Net Express, version 4.0 running on Windows/2000.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLCSVC2.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only and does not imply publication   *
      * or disclosure.                                                *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any non-commercial purpose and without fee is hereby      *
      * granted, provided the SimoTime copyright notice appear on all *
      * copies of the software. The SimoTime name or Logo may not be  *
      * used in any advertising or publicity pertaining to the use    *
      * of the software without the written permission of SimoTime    *
      * Enterprises.                                                  *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any commercial purpose requires a fee to be paid to       *
      * SimoTime Enterprises. Once the fee is received by SimoTime    *
      * the latest version of the software will be delivered and a    *
      * license will be granted for use within an enterprise,         *
      * provided the SimoTime copyright notice appear on all copies   *
      * of the software. The SimoTime name or Logo may not be used    *
      * in any advertising or publicity pertaining to the use of the  *
      * software without the written permission of SimoTime           *
      * Enterprises.                                                  *
      *                                                               *
      * SimoTime Enterprises makes no warranty or representations     *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any express or implied warranty,     *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Enterprises shall not be liable for any direct, indirect,     *
      * special or consequential damages resulting from the loss of   *
      * use, data or projects, whether in an action of contract or    *
      * tort, arising out of or in connection with the use or         *
      * performance of this software                                  *
      *                                                               *
      * SimoTime Enterprises                                          *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *****************************************************************
      *        This base program was generated by SimoZAPS            *
      *             A product of SimoTime Enterprises                 *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *                                   Record    Record     Key    *
      *  Function  Name     Organization  Format    Max-Min  Pos-Len  *
      *  INPUT     CSVGETD1 SEQUENTIAL    FIXED      00080            *
      *  OUTPUT    TXTPUTD1 ASCII/CRLF    VARIABLE   00080            *
      *                                                               *
      *****************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
      *    The LINE SEQUENTIAL file organization is Micro Fcus
      *    syntax for an ASCII/Text file.
           SELECT CSVGETD1-FILE  ASSIGN TO       CSVGETD1
                  ORGANIZATION IS LINE SEQUENTIAL
                  ACCESS MODE  IS SEQUENTIAL
                  FILE STATUS  IS CSVGETD1-STATUS.
           SELECT TXTPUTD1-FILE  ASSIGN TO       TXTPUTD1
                  ORGANIZATION IS LINE SEQUENTIAL
                  ACCESS MODE  IS SEQUENTIAL
                  FILE STATUS  IS TXTPUTD1-STATUS.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  CSVGETD1-FILE
           DATA RECORD    IS CSVGETD1-RECORD.
       01  CSVGETD1-RECORD             PIC X(512).

       FD  TXTPUTD1-FILE
           DATA RECORD    IS CUSTTEXT-RECORD.
       COPY CUSTTXB1.


       WORKING-STORAGE SECTION.
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *    ------------------------------------------------------------
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLCSVC2 '.
           05  T2 pic X(34) value 'Comma Delimited File, Read Access '.
           05  T3 pic X(10) value ' v03.12.15'.
           05  T4 pic X(24) value ' http://www.simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLCSVC2 '.
           05  C2 pic X(20) value 'Copyright 2003-2004 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           05  C4 pic X(20) value ' All Rights Reserved'.

       01  SIM-THANKS-01.
           05  C1 pic X(11) value '* CBLCSVC2 '.
           05  C2 pic X(32) value 'Thank you for using this sample '.
           05  C3 pic X(32) value 'by SimoTime Enterprises, LLC    '.
           05  C4 pic X(04) value '    '.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLCSVC2 '.
           05  C2 pic X(32) value 'Please send comments or suggesti'.
           05  C3 pic X(32) value 'ons to helpdesk@simotime.com    '.
           05  C4 pic X(04) value '    '.

       01  CSVGETD1-STATUS.
           05  CSVGETD1-STATUS-L   pic X.
           05  CSVGETD1-STATUS-R   pic X.
       01  CSVGETD1-EOF            pic X       value 'N'.
       01  CSVGETD1-OPEN-FLAG      pic X       value 'C'.

       01  TXTPUTD1-STATUS.
           05  TXTPUTD1-STATUS-L   pic X.
           05  TXTPUTD1-STATUS-R   pic X.
       01  TXTPUTD1-OPEN-FLAG      pic X       value 'C'.

       01  IO-STATUS.
           05  IO-STAT1            pic X.
           05  IO-STAT2            pic X.
       01  TWO-BYTES.
           05  TWO-BYTES-LEFT      pic X.
           05  TWO-BYTES-RIGHT     pic X.
       01  TWO-BYTES-BINARY        redefines TWO-BYTES pic 9(4) comp.
       01  IO-STATUS-4             pic 9(4)  value 0.
       01  IO-STATUS-4A            redefines IO-STATUS-4 pic X(4).


      *****************************************************************
      * Message Buffer used by the Z-DISPLAY-MESSAGE-TEXT routine.    *
      *****************************************************************
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* CBLCSVC2 '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.
       01  MESSAGE-BUFFER-SIZE     pic 9(3)    value 267.
       01  MSG-PTR                 pic 9(3)    value 0.
       01  MSG-LEN                 pic 9(3)    value 0.

       01  APPL-RESULT             pic S9(9)   comp.
           88  APPL-AOK            value 0.
           88  APPL-EOF            value 16.

       01  DOUBLE-QUOTE            pic X       value '"'.
       01  DATA-HAS-DELIMITER      pic X       value 'N'.
       01  DELIMITER-BYTE          pic X       value ','.
       01  WORK-128                pic X(128)  value SPACES.
       01  WORK-50                 pic X(50)   value SPACES.

       01  SIG-FIRST               pic 9(3)    value 0.
       01  SIG-LAST                pic 9(3)    value 0.
       01  SIG-LENGTH              pic 9(3)    value 0.
       01  IDX-1                   pic 9(3)    value 0.
       01  IDX-STOP                pic 9(3)    value 0.
       01  CSV-X1                  pic 9(3)    value 0.
       01  FIELD-SIZE              pic 9(3)    value 0.
       01  MESSAGE-LENGTH-ERROR.
           05  MESSAGE-KEY         pic X(12)   value SPACES.
           05  FILLER              pic X       value SPACES.
           05  FILLER              pic X(17)
                                   value 'Length error for '.
           05  MESSAGE-FIELD-NAME  pic X(32)   value SPACES.

       01  Z-WORK-12            pic X(12)   value SPACES.
       01  Z-X12                pic 9(3)    value 0.

       COPY PASSPARS.

      *****************************************************************
       PROCEDURE DIVISION.

           perform FIRST-TIME-LOGIC

           perform CSVGETD1-OPEN
           perform TXTPUTD1-OPEN

           perform until CSVGETD1-STATUS not = '00'
               perform CSVGETD1-READ
      *        If a successful read of the input file and the input
      *        record is not equal to SPACES then create an output.
               if  CSVGETD1-STATUS = '00'
               and CSVGETD1-RECORD not = SPACES
      *            move CSVGETD1-RECORD to MESSAGE-TEXT
      *            perform Z-DISPLAY-MESSAGE-TEXT
                   perform PARSE-CSV-RECORD
                   perform POST-TXT-RECORD
               end-if
           end-perform

           perform TXTPUTD1-CLOSE
           perform CSVGETD1-CLOSE

           perform Z-THANK-YOU

           GOBACK.

      *****************************************************************
      * The following routines are in alphabetical sequence..         *
      *****************************************************************

      *****************************************************************
       FIRST-TIME-LOGIC.
           perform Z-POST-COPYRIGHT
           move ',' to PRS-DELIMITER
           move 'Y' to PRS-KEEP-NULL-FIELDS
           move 'Y' to PRS-SUSPEND
           move '"' to PRS-SUSPEND-BYTE
           exit.

      *****************************************************************
       PARSE-AND-POST.
           perform PARSE-CSV-RECORD
           perform POST-TXT-RECORD
           exit.

      *****************************************************************
      * Determine the position within the field of the first and last *
      * significant characters within a field. Also, determine the    *
      * length of the text string within the field.                   *
      *****************************************************************
       PARSE-CSV-RECORD.
           move CSVGETD1-RECORD to PRS-BUFFER
           call 'SIMOPARS' using PRS-PARAMETERS
           exit.

      *****************************************************************
      * Move the field to the output buffer and insert a trailing     *
      * delimiter character.                                          *
      *****************************************************************
       POST-TXT-RECORD.
           move SPACES to Z-WORK-12
           move PRS-BUFFER(PRS-POSITION(1):PRS-SIZE(1))
             to Z-WORK-12(1:PRS-SIZE(1))
           perform Z-RIGHT-ADJUST-Z-WORK-12
           move Z-WORK-12 to CUSTTEXT-KEY
           move Z-WORK-12 to MESSAGE-KEY

           if  PRS-SIZE(2) greater than 0
               move PRS-BUFFER(PRS-POSITION(2):PRS-SIZE(2))
                 to CUSTTEXT-LAST-NAME(1:PRS-SIZE(2))
           end-if

      *    Determine maximum length of Last Name information and
      *    move to CUSTTEXT-LAST-NAME
           add length of CUSTTEXT-LAST-NAME
                      to ZERO giving FIELD-SIZE
           if  PRS-SIZE(2) not > FIELD-SIZE
               add PRS-SIZE(2) to ZERO giving FIELD-SIZE
           else
               move CUSTTEXT-LAST-NAME to MESSAGE-FIELD-NAME
               perform Z-DISPLAY-LENGTH-ERROR-MESSAGE
           end-if
           if  FIELD-SIZE greater than 0
               move PRS-BUFFER(PRS-POSITION(2):FIELD-SIZE)
                 to CUSTTEXT-LAST-NAME(1:FIELD-SIZE)
           end-if

      *    Determine maximum length of First Name information and
      *    move to CUSTTEXT-FIRST-NAME
           add length of CUSTTEXT-FIRST-NAME
                      to ZERO giving FIELD-SIZE
           if  PRS-SIZE(3) not > FIELD-SIZE
               add PRS-SIZE(3) to ZERO giving FIELD-SIZE
           else
               move 'CUSTTEXT-FIRST-NAME' to MESSAGE-FIELD-NAME
               perform Z-DISPLAY-LENGTH-ERROR-MESSAGE
           end-if
           if  FIELD-SIZE greater than 0
               move PRS-BUFFER(PRS-POSITION(3):FIELD-SIZE)
                 to CUSTTEXT-FIRST-NAME(1:FIELD-SIZE)
           end-if

      *    Determine maximum length of Street Address information and
      *    move to CUSTTEXT-STREET-ADDRESS
           add length of CUSTTEXT-STREET-ADDRESS
                      to ZERO giving FIELD-SIZE
           if  PRS-SIZE(4) not > FIELD-SIZE
               add PRS-SIZE(4) to ZERO giving FIELD-SIZE
           else
               move 'CUSTTEXT-STREET-ADDRESS' to MESSAGE-FIELD-NAME
               perform Z-DISPLAY-LENGTH-ERROR-MESSAGE
           end-if
           if  FIELD-SIZE greater than 0
               move PRS-BUFFER(PRS-POSITION(4):FIELD-SIZE)
                 to CUSTTEXT-STREET-ADDRESS(1:FIELD-SIZE)
           end-if

      *    Determine maximum length of City information and
      *    move to CUSTTEXT-CITY
           add length of CUSTTEXT-CITY to ZERO giving FIELD-SIZE
           if  PRS-SIZE(5) not > FIELD-SIZE
               add PRS-SIZE(5) to ZERO giving FIELD-SIZE
           else
               move 'CUSTTEXT-CITY' to MESSAGE-FIELD-NAME
               perform Z-DISPLAY-LENGTH-ERROR-MESSAGE
           end-if
           if  FIELD-SIZE greater than 0
               move PRS-BUFFER(PRS-POSITION(5):FIELD-SIZE)
                 to CUSTTEXT-CITY(1:FIELD-SIZE)
           end-if

           add length of CUSTTEXT-STATE to ZERO giving FIELD-SIZE
           if  PRS-SIZE(6) < FIELD-SIZE
               add PRS-SIZE(6) to ZERO giving FIELD-SIZE
           end-if
           if  FIELD-SIZE > 0
               move PRS-BUFFER(PRS-POSITION(6):FIELD-SIZE)
                 to CUSTTEXT-STATE(1:FIELD-SIZE)
           end-if

           perform POST-STRING-WITH-CLEAR-AFTER

           exit.

      *****************************************************************
      * Write the comma delimited record to the output file.          *
      *****************************************************************
       POST-STRING-WITH-CLEAR-AFTER.
      *    move WORK-128 to CUSTTEXT-RECORD
           perform TXTPUTD1-WRITE
           move SPACES to CUSTTEXT-RECORD
           exit.

      *****************************************************************
      * I/O ROUTINES FOR CSVGETD1...                                  *
      *****************************************************************
       CSVGETD1-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close CSVGETD1-FILE
           if  CSVGETD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'CSVGETD1-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CSVGETD1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       CSVGETD1-READ.
           read CSVGETD1-FILE
           if  CSVGETD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  CSVGETD1-STATUS = '10'
                   add 16 to ZERO giving APPL-RESULT
               else
                   add 12 to ZERO giving APPL-RESULT
               end-if
           end-if
           if  APPL-AOK
               CONTINUE
           else
               if  APPL-EOF
                   move 'Y' to CSVGETD1-EOF
               else
                   move 'CSVGETD1-Failure-GET...' to MESSAGE-TEXT
                   perform Z-DISPLAY-MESSAGE-TEXT
                   move CSVGETD1-STATUS to IO-STATUS
                   perform Z-DISPLAY-IO-STATUS
                   perform Z-ABEND-PROGRAM
               end-if
           end-if
           exit.
      *---------------------------------------------------------------*
       CSVGETD1-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open input CSVGETD1-FILE
           if  CSVGETD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to CSVGETD1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'CSVGETD1-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CSVGETD1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
      * I/O ROUTINES FOR TXTPUTD1...                                  *
      *****************************************************************
       TXTPUTD1-WRITE.
           if  TXTPUTD1-OPEN-FLAG = 'C'
               perform TXTPUTD1-OPEN
           end-if
           write CUSTTEXT-RECORD
           if  TXTPUTD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  TXTPUTD1-STATUS = '10'
                   add 16 to ZERO giving APPL-RESULT
               else
                   add 12 to ZERO giving APPL-RESULT
               end-if
           end-if.
           if  APPL-AOK
               CONTINUE
           else
               move 'TXTPUTD1-Failure-WRITE...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move TXTPUTD1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       TXTPUTD1-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open OUTPUT TXTPUTD1-FILE
           if  TXTPUTD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to TXTPUTD1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'TXTPUTD1-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move TXTPUTD1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       TXTPUTD1-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close TXTPUTD1-FILE
           if  TXTPUTD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'C' to TXTPUTD1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'TXTPUTD1-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move TXTPUTD1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
      * The following Z-ROUTINES provide administrative functions     *
      * for this program.                                             *
      *****************************************************************
      *
      *****************************************************************
      * ABEND the program, post a message to the console and issue    *
      * a STOP RUN.                                                   *
      *****************************************************************
       Z-ABEND-PROGRAM.
           if  MESSAGE-TEXT not = SPACES
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if
           move 'PROGRAM-IS-ABENDING...'  to MESSAGE-TEXT
           perform Z-DISPLAY-MESSAGE-TEXT
           add 12 to ZERO giving RETURN-CODE
           STOP RUN
           exit.

      *****************************************************************
      * Display CONSOLE message for LENGTH error...                   *
      *****************************************************************
       Z-DISPLAY-LENGTH-ERROR-MESSAGE.
           move MESSAGE-LENGTH-ERROR to MESSAGE-TEXT
           perform Z-DISPLAY-MESSAGE-TEXT
           move CSVGETD1-RECORD(1:79) to MESSAGE-TEXT
           perform Z-DISPLAY-MESSAGE-TEXT
           move SPACES to MESSAGE-FIELD-NAME
           exit.

      *****************************************************************
      * Display CONSOLE messages...                                   *
      *****************************************************************
       Z-DISPLAY-MESSAGE-TEXT.
           if  MESSAGE-TEXT-2 = SPACES
               display MESSAGE-BUFFER(1:79) upon console
           else
               display MESSAGE-BUFFER upon console
           end-if
           move all SPACES to MESSAGE-TEXT
           exit.

      *****************************************************************
      * Display the file status bytes. This routine will display as   *
      * four digits. If the full two byte file status is numeric it   *
      * will display as 00nn. If the 1st byte is a numeric nine (9)   *
      * the second byte will be treated as a binary number and will   *
      * display as 9nnn.                                              *
      *****************************************************************
       Z-DISPLAY-IO-STATUS.
           if  IO-STATUS not NUMERIC
           or  IO-STAT1 = '9'
               subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
               move IO-STAT2 to TWO-BYTES-RIGHT
               add TWO-BYTES-BINARY to ZERO giving IO-STATUS-4
               move IO-STAT1 to IO-STATUS-4A(1:1)
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-4A to MESSAGE-TEXT(17:4)
               perform Z-DISPLAY-MESSAGE-TEXT
           else
               move '0000' to IO-STATUS-4A
               move IO-STATUS to IO-STATUS-4A(3:2)
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-4A to MESSAGE-TEXT(17:4)
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if
           exit.

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE     upon console
           display SIM-COPYRIGHT upon console
           exit.

      *****************************************************************
      * Delete all characters to the right of the first space then
      * right-adjust with zero fill. This routine works with a single,
      * twelve character field and does not require a work area.
      *****************************************************************
       Z-RIGHT-ADJUST-Z-WORK-12.
      *    The following INSPECT statement will erase to end-of-field
      *    any characters after the first space character.
           inspect Z-WORK-12
                   replacing CHARACTERS by ' ' after initial ' '

      *    The following IF logic is for performance. It quickly
      *    reduces the number of loops for the PERFORM logic.
           if  Z-WORK-12(7:6) = SPACES
               if  Z-WORK-12(4:3) = SPACES
                   move Z-WORK-12(1:3) to Z-WORK-12(10:3)
                   move all ZEROES     to Z-WORK-12(1:9)
               else
                   move Z-WORK-12(1:6) to Z-WORK-12(7:6)
                   move all ZEROES     to Z-WORK-12(1:6)
               end-if
           else
               if  Z-WORK-12(10:3) = SPACES
      *            The following three MOVE statements are used to
      *            avoid a potential problem with an overlapping MOVE.
                   move Z-WORK-12(7:3) to Z-WORK-12(10:3)
                   move Z-WORK-12(4:3) to Z-WORK-12(7:3)
                   move Z-WORK-12(1:3) to Z-WORK-12(4:3)
                   move all ZEROES     to Z-WORK-12(1:3)
               end-if
           end-if

           perform until Z-WORK-12(12:1) not = SPACE
               if  Z-WORK-12(12:1) = SPACE
                   add 11 to ZERO giving Z-X12
                   perform 11 times
                     move Z-WORK-12(Z-X12:1) to Z-WORK-12(Z-X12 + 1:1)
                     subtract 1 from Z-X12
                   end-perform
                   move ZERO to Z-WORK-12(1:1)
               end-if
           end-perform
           exit.

      *****************************************************************
       Z-THANK-YOU.
           display SIM-THANKS-01 upon console
           display SIM-THANKS-02 upon console
           exit.

      *****************************************************************
      *           This program was generated by SimoZAPS              *
      *             A product of SimoTime Enterprises                 *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *  Generation Date: 2003-04-08  Generation Time: 10:46:30:63    *
      *****************************************************************

The COBOL Parsing Program
(Next) (Previous) (Table-of-Contents)

The following (SIMOPARS.CBL) is the COBOL parsing program.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    SIMOPARS.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises, LLC.            *
      *                                                               *
      * All rights reserved.  Unpublished, all rights reserved under  *
      * copyright law and international treaty.  Use of a copyright   *
      * notice is precautionary only and does not imply publication   *
      * or disclosure.                                                *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any non-commercial purpose and without fee is hereby      *
      * granted, provided the SimoTime copyright notice appear on all *
      * copies of the software. The SimoTime name or Logo may not be  *
      * used in any advertising or publicity pertaining to the use    *
      * of the software without the written permission of SimoTime    *
      * Enterprises.                                                  *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any commercial purpose requires a fee to be paid to       *
      * SimoTime Enterprises. Once the fee is received by SimoTime    *
      * the latest version of the software will be delivered and a    *
      * license will be granted for use within an enterprise,         *
      * provided the SimoTime copyright notice appear on all copies   *
      * of the software. The SimoTime name or Logo may not be used    *
      * in any advertising or publicity pertaining to the use of the  *
      * software without the written permission of SimoTime           *
      * Enterprises.                                                  *
      *                                                               *
      * SimoTime Enterprises makes no warranty or representations     *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any express or implied warranty,     *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Enterprises shall not be liable for any direct, indirect,     *
      * special or consequential damages resulting from the loss of   *
      * use, data or projects, whether in an action of contract or    *
      * tort, arising out of or in connection with the use or         *
      * performance of this software                                  *
      *                                                               *
      * SimoTime Enterprises                                          *
      * 15 Carnoustie Drive                                           *
      * Novato, CA 94949-5849                                         *
      * 415.883.6565                                                  *
      *                                                               *
      * RESTRICTED RIGHTS LEGEND                                      *
      * Use, duplication, or disclosure by the Government is subject  *
      * to restrictions as set forth in subparagraph (c)(1)(ii) of    *
      * the Rights in Technical Data and Computer Software clause at  *
      * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of          *
      * Commercial  Computer Software - Restricted Rights  at 48      *
      * CFR 52.227-19, as applicable.  Contact SimoTime Enterprises,  *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *****************************************************************
      *
      *****************************************************************
      * Source Member: SIMOPARS.CBL
      * Copy Files     PASSPARS.CPY
      *****************************************************************
      *
      * SIMOPARS - Parse Buffer defined in pass area.
      *
      * CALLING PROTOCOL
      * ----------------
      * call 'SIMOPARS' using PRS-PARAMETERS
      *
      *    01  PRS-PARAMETERS.
      *        05  PRS-REQUEST          PIC X       VALUE '0'.
      *        05  PRS-STATUS           PIC 9(4).
      *        05  PRS-DELIMITER        PIC X       VALUE SPACE.
      *        05  PRS-KEEP-NULL-FIELDS PIC X       VALUE 'N'.
      *        05  PRS-SUSPEND          PIC X       VALUE 'N'.
      *        05  PRS-SUSPEND-BYTE     PIC X       VALUE SPACE.
      *        05  PRS-TERMINATOR       PIC X       VALUE 'N'.
      *        05  PRS-TERMINATOR-BYTE  PIC X       VALUE SPACE.
      *        05  PRS-BUFFER-SIZE      PIC 9(4)    VALUE 1024.
      *        05  PRS-BUFFER           PIC X(1024).
      *        05  PRS-TABLE-MAX        PIC 9(4)    VALUE 64.
      *        05  PRS-NUMBER-OF-ITEMS  PIC 9(4)    VALUE 0.
      *        05  PRS-LAST-SIG-BYTE    PIC 9(4)    VALUE 0.
      *        05  PRS-POSITION         OCCURS 64 TIMES
      *                                 PIC 9(4)    VALUE 0.
      *        05  PRS-SIZE             OCCURS 64 TIMES
      *
      * This routine uses reference modification to identify the
      * position of the first significant character after the
      * delimiter character. This approach compensates for multiple
      * leading or embedded delimiter characters. The string function
      * of COBOL does not handle leading spaces.
      *
      * For example, if the delimiter character is a space then
      * leading spaces will be ignored and multiple, embedded spaces
      * will be treated as a single space.
      *
      * MAINTENANCE
      * -----------
      * 1998/01/02 Simmons, CREATED PROGRAM.
      * 1998/01/02 Simmons, No changes to date...
      *
      *****************************************************************
      *
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
      *****************************************************************
      * Data-structure for Program use...                             *
      *****************************************************************
       01  I-PTR               pic 9(4)    value 0.
       01  O-PTR               pic 9(4)    value 0.
       01  B-COUNT             pic 9(4)    value 0.
       01  SUSPEND-SWITCH      pic X       value 'N'.

      *****************************************************************
       LINKAGE SECTION.
       COPY PASSPARS.

      *****************************************************************
       PROCEDURE DIVISION using PRS-PARAMETERS.
           add      8 to   ZERO giving RETURN-CODE
           add      9 to   ZERO giving PRS-STATUS
           subtract 1 from 1    giving PRS-NUMBER-OF-ITEMS
           evaluate PRS-REQUEST
               when '0'   perform PARSE-BUFFER
               when '1'   perform INITIALIZE-TABLE-ELEMENTS
               when OTHER add 12 to ZERO giving PRS-STATUS
           end-evaluate

           if  PRS-STATUS = 9
               subtract PRS-STATUS from PRS-STATUS
           end-if

           GOBACK.

      *****************************************************************
       INITIALIZE-TABLE-ELEMENTS.
           move 1 to I-PTR
           move 1 to O-PTR
           perform until O-PTR > PRS-TABLE-MAX
               move 0 to PRS-POSITION(O-PTR)
               move 0 to PRS-SIZE(O-PTR)
               add  1 to O-PTR
           end-perform
           subtract RETURN-CODE from RETURN-CODE
           exit.

      *****************************************************************
       PARSE-BUFFER.
      *!   Initialize Offset/Length tables to zero (0).
           perform INITIALIZE-TABLE-ELEMENTS
           add 1 to ZERO giving PRS-LAST-SIG-BYTE
           subtract PRS-LAST-SIG-BYTE from PRS-LAST-SIG-BYTE
      *!   Parse the Buffer.
           add 1 to ZERO giving O-PTR
           perform until I-PTR > PRS-BUFFER-SIZE
               if  PRS-SUSPEND = 'Y'
               and PRS-BUFFER(I-PTR:1) = PRS-SUSPEND-BYTE
                   if  SUSPEND-SWITCH = 'Y'
                       move 'N' to SUSPEND-SWITCH
                   else
                       move 'Y' to SUSPEND-SWITCH
                   end-if
               else
                   if  PRS-BUFFER(I-PTR:1) = PRS-DELIMITER
                   and SUSPEND-SWITCH = 'N'
                       add 1 to B-COUNT
                       if  PRS-KEEP-NULL-FIELDS = 'Y'
                       or  B-COUNT = 1
                       and PRS-SIZE(O-PTR) > 0
                           if  O-PTR < PRS-TABLE-MAX
                               add 1 to O-PTR
                               add 1 to PRS-NUMBER-OF-ITEMS
                           else
                               move PRS-BUFFER-SIZE to I-PTR
                           end-if
                       end-if
                   else
                       subtract B-COUNT from B-COUNT
                       add 1 to PRS-SIZE(O-PTR)
                       if  PRS-SIZE(O-PTR) = 1
                           move I-PTR to PRS-POSITION(O-PTR)
                       end-if
                   end-if
               end-if
               add 1 to I-PTR
               if  PRS-TERMINATOR = 'Y'
               and I-PTR  not > PRS-BUFFER-SIZE
               and PRS-BUFFER(I-PTR:1) = PRS-TERMINATOR-BYTE
                   if  PRS-SIZE(O-PTR) > 0
                       add 1 to PRS-NUMBER-OF-ITEMS
                   end-if
                   add PRS-BUFFER-SIZE to 1 giving I-PTR
               end-if
           end-perform
           if  PRS-POSITION(O-PTR) = 0
               subtract 1 from O-PTR
           end-if
           if  PRS-NUMBER-OF-ITEMS > 0
               add    PRS-POSITION(PRS-NUMBER-OF-ITEMS)
                to    PRS-SIZE(PRS-NUMBER-OF-ITEMS)
               giving PRS-LAST-SIG-BYTE
               subtract 1 from PRS-LAST-SIG-BYTE
           end-if
           subtract RETURN-CODE from RETURN-CODE
           exit.
      *****************************************************************
      *      This example is provided by SimoTime Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

The COBOL Copy Files
(Next) (Previous) (Table-of-Contents)

This section contains the listing for the copy files used by the programs in this example.

Copy File for Record Layout
(Next) (Previous) (Table-of-Contents)

The following (CUSTTXB1.CPY) is the record layout of the column-oriented, fixed-field-length, Customer Master file.

       01  CUSTTEXT-RECORD.
           05  CUSTTEXT-KEY            PIC X(12).
           05  FILLER                  PIC X.
           05  CUSTTEXT-LAST-NAME      PIC X(28).
           05  CUSTTEXT-FIRST-NAME     PIC X(20).
           05  CUSTTEXT-STREET-ADDRESS PIC X(48).
           05  CUSTTEXT-CITY           PIC X(16).
           05  CUSTTEXT-STATE          PIC X(2).
           05  FILLER                  PIC X(385).

Copy File for Pass Area of Parsing Program
(Next) (Previous) (Table-of-Contents)

The following (PASSPARS.CPY) is the layout of the pass area that is used when calling the parsing program.

      *****************************************************************
      *           Data Structure used for calling SIMOPARS.           *
      *****************************************************************
      *         Copyright (C) 1987-2010 SimoTime Enterprises          *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Enterprises                 *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *                                                               *
      * PRS-REQUEST          Type of request, must be zero (0) for    *
      *                      parsing. This item is  provided by the   *
      *                      calling program and is not modified      *
      *                      by the parsing routine.                  *
      * PRS-STATUS           This is an indicator as to the success   *
      *                      or failure of the request. A value of    *
      *                      zero (0000) indicates the routine was    *
      *                      successful. A non-zero value indicates   *
      *                      a failure.                               *
      *                                                               *
      * ------------------------------------------------------------- *
      * The following fields are provided by the calling routine.     *
      *                                                               *
      * PRS-DELIMITER        This is a one byte character that is     *
      *                      used as a delimiter. This item is        *
      *                      provided by the calling program and      *
      *                      is not modified by the parsing routine.  *
      *                                                               *
      * PRS-KEEP-NULL-FIELDS This must be a Yes (Y) or No (N) value   *
      *                      (Y) will indicate a Yes, keep null field *
      *                      (N) will indicate a No and null fields   *
      *                      will be dropped.                         *
      * PRS-SUSPEND          This must be a Yes (Y) or No (N) value   *
      *                      to indicate that the suspend/resume      *
      *                      function of checking for a delimiter     *
      *                      is active.                               *
      * PRS-SUSPEND-BYTE     If the previous parameter is (Y) this    *
      *                      byte will be used to suspend or resume   *
      *                      the testing for a delimiter charcter.    *
      * PRS-TERMINATOR       This must be a Yes (Y) or No (N) value   *
      *                      to indicate a character that will be     *
      *                      used for termination of the parsing.     *
      *                      If (Y) then the next parameter is used   *
      *                      as a termination character. If (N) the   *
      *                      buffer will be parsed according to the   *
      *                      size  of the buffer or maximum number    *
      *                      of table entries. This item is provided  *
      *                      by the calling program and is not        *
      *                      modified by the parsing routine.         *
      * PRS-TERMINATOR-BYTE  If the previous parameter is (Y) this    *
      *                      byte will be used to terminate the       *
      *                      parsing when it is encountered in the    *
      *                      data string. This item is provided by    *
      *                      the calling program and is not modified  *
      *                      by the parsing routine.                  *
      *                                                               *
      * PRS-BUFFER-SIZE      The size of the data string to be        *
      *                      parsed and must be a value of 1-1024.    *
      *                      This item is provided by the calling     *
      *                      program and is not  modified by the      *
      *                      parsing routine.                         *
      * PRS-BUFFER           This is the data string or field that    *
      *                      will be parsed. This item is provided    *
      *                      by the calling program and is not        *
      *                      modified by the parsing routine.         *
      *                                                               *
      * PRS-TABLE-MAX        The maximum number of table entries      *
      *                      available for the POSITION/SIZE values   *
      *                      of the words in the input buffer.        *
      *                      This item is provided by the calling     *
      *                      program and is not modified by the       *
      *                      parsing routine.                         *
      *                                                               *
      * ------------------------------------------------------------- *
      * The following fields are updated by the parsing routine.      *
      *                                                               *
      * PRS-NUMBER-OF-ITEMS  This is the number of keywords found     *
      *                      in the input data string. This item is   *
      *                      provided by the parsing routine.         *
      *                                                               *
      * PRS-LAST-SIG-BYTE    This is the position of the last         *
      *                      significant, non-delimiter byte. If the  *
      *                      PRS-TERMINATOR is "Y" this will be the   *
      *                      last significant byte before the         *
      *                      terminator byte.                         *
      *                                                               *
      * PRS-POSITION         This is a table of 64 elements of        *
      *                      4-bytes. The value is either zero (0)    *
      *                      or the position of a keyword within the  *
      *                      input data string. The first position    *
      *                      within the buffer is one (1).            *
      *                      This item is provided by the parsing     *
      *                      routine.                                 *
      * PRS-SIZE             This is a table of 64 elements of        *
      *                      4-bytes. The value is either zero (0)    *
      *                      or the size of a keyword within the      *
      *                      input data string. This item is provided *
      *                      by the parsing routine.                  *
      *                                                               *
      * ------------------------------------------------------------- *
      * NOTE...              The table element number is the number   *
      *                      of the word within the data buffer.      *
      *                      The data buffer is PRS-BUFFER.           *
      *                      For example, PRS-POSITION(1) would point *
      *                      to the position of the first character   *
      *                      of the first word in the data buffer     *
      *                      PRS-SIZE(1) would specify the number of  *
      *                      characters in the first word.            *
      *                                                               *
      *****************************************************************
       01  PRS-PARAMETERS.
           05  PRS-REQUEST          PIC X       VALUE '0'.
           05  PRS-STATUS           PIC 9(4).
      *!   Provided by the calling program...
           05  PRS-DELIMITER        PIC X       VALUE SPACE.
           05  PRS-KEEP-NULL-FIELDS PIC X       VALUE 'N'.
           05  PRS-SUSPEND          PIC X       VALUE 'N'.
           05  PRS-SUSPEND-BYTE     PIC X       VALUE SPACE.
           05  PRS-TERMINATOR       PIC X       VALUE 'N'.
           05  PRS-TERMINATOR-BYTE  PIC X       VALUE SPACE.

           05  PRS-BUFFER-SIZE      PIC 9(4)    VALUE 1024.
           05  PRS-BUFFER           PIC X(1024).

           05  PRS-TABLE-MAX        PIC 9(4)    VALUE 64.

      *!   Updated by the parsing routine...
           05  PRS-NUMBER-OF-ITEMS  PIC 9(4)    VALUE 0.
           05  PRS-LAST-SIG-BYTE    PIC 9(4)    VALUE 0.
           05  PRS-POSITION         OCCURS 64 TIMES
                                    PIC 9(4)    VALUE 0.
           05  PRS-SIZE             OCCURS 64 TIMES
                                    PIC 9(4)    VALUE 0.
      *!   PASSPARS - End-of-Copy File...

Summary
(Next) (Previous) (Table-of-Contents)

The purpose of this program is to provide examples for accessing a comma-delimited file containing variable-length strings and creating a new column-oriented, fixed-field-length Sequential file.

Software Agreement and Disclaimer
(Next) (Previous) (Table-of-Contents)

Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to SimoTIme Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.

Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.

SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.

Downloads and Links to Similar Pages
(Next) (Previous) (Table-of-Contents)

You may download this example at http://www.simotime.com/sim4dzip.htm#COBOLCommaDelimitedFileReadParse or view the complete list of SimoTime Examples at http://www.simotime.com/sim4dzip.htm.

Note: You must be attached to the Internet to download a Z-Pack or view the list.

An example of how to Create a Comma-Delimited file is provided.

The hexadecimal dump of the parameter-buffer uses the same technique as describe in another SimoTime example that describes the dumping of a data string using COBOL. The name of the member that does the actual hexadecimal dump is called SimoDUMP. A copy file (PASSDUMP.CPY) is provided for defining the pass area.

The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPS can also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements. The Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.

This item will provide a link to  an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.

Check out  The VSAM - QSAM Connection  for more examples of mainframe VSAM and QSAM accessing techniques and sample code.

This document provides a quick summary of the  File Status Key  for VSAM data sets and QSAM files.

Check out  The SimoTime Library  for a wide range of topics for Programmers, Project Managers and Software Developers.

To review all the information available on this site start at  The SimoTime Home Page .

Comments or Suggestions
(Next) (Previous) (Table-of-Contents)

If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com

We appreciate your comments and feedback.

About SimoTime Enterprises
(Next) (Previous) (Table-of-Contents)

Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com


Return-to-Top
Copyright © 1987-2010  SimoTime Enterprises All Rights Reserved
When technology complements business
http://www.simotime.com