Comma Delimited File
Read and Parse
  Table of Contents  v-24.01.01 - cblcsv02.htm 
  Introduction
  Programming Objectives
  Programming Input and Output
  Programming Requirements
  Programming Overview
  CMD for Batch Job
  The COBOL Programs
  The COBOL I/O Program
  The COBOL Convert Routine
  The COBOL Parsing Program
  The COBOL Copy Files
  Record Layout or Structure
  Pass Area of Parsing Program
  Summary
  Software Agreement and Disclaimer
  Downloads and Links
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Contact or Feedback
  Company Overview
The SimoTime Home Page 

Table of Contents Previous Section Next Section Introduction

Convert an ASCII encoded file with a record structure that uses a Comma Separated Value or CSV format to a file with a record structure that uses a Row and Column or Record and Field format. This test case includes documentation, job scripts and sample programs that describes and demonstrates how to read a comma-delimited file (filename.CSV, Comma-Separated-Value) of variable length strings and create a Row-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.

The programs have been tested on an IBM Mainframe System, a Windows system with Micro Focus COBOL and a Linux System with GnuCOBOL.


We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.

Copyright © 1987-2024
SimoTime Technologies and Services
All Rights Reserved

Table of Contents Previous Section Next Section Programming Objectives

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 Objectives, Read and Parse a CSV File for Conversion to Fixed Field Format

Table of Contents Previous Section Next Section Programming Input and Output

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.

100,,Anderson,Adrian,"1113 Peachtree Plaza, Suite 111",,Atlanta,GA,26101
200,,Brown,Billie,224 Baker Boulevard,,Baltimore,MD,35702
300,,Carson,Cameron,336 Crenshaw Blvd.,,Cupertino,CA,96154
400,,Davidson,Dion,448 Main Street,,Wilmington,DE,27323
500,,Everest,Evan,55 5TH Avenue,,New York,NY,10341
600,,Franklin,Francis,6612 66TH Avenue,,Bedrock,NY,11903
700,,Garfunkel,Gwen,777 77TH Street,,New York,NY,16539
800,,Harrison,Hilary,888 88TH Street,,Pocatello,ID,79684
900,,Isley,Isabel,999 99TH Avenue,,Indianapolis,IN,38762
1000,,Johnson,Jamie,1010 Paradise Drive,,Larkspur,CA,90504
1100,,Kemper,Kelly,1111 Oak Circle,,Kansas City,KS,55651
1200,,Lemond,Lesley,1212 Lockwood Road,,Mohave Desert,AZ,80303
1300,,Mitchell,Marlow,1313 Miller Creek Road,,Anywhere,TX,77123
1400,,Newman,Noel,1414 Park Avenue,,Santa Monica,CA,90210
1500,,Osborn,Owen,1515 Center Stage,,Rolling Rock,PA,36613
1600,,Powell,Pierce,PO Box 1616,,Ventura,CA,97712
1700,,Quigley,Quincy,1717 Farm Hill Road,,Oshkosh,WI,43389
1800,,Ripley,Ray,1818 Alien Lane,,Wayout,KS,55405
1900,,Smith,Sammy,1919 Carnoustie Drive,,Novato,CA,94919
2000,,Tucker,Taylor,2020 Sanger Lane,,St. Paul,MN,43998
2100,,Underwood,Ulysses,2121 Wall Street,,New York,NY,17623
2200,,Van Etten,Valerie,"    2222 Vine Street, #22",,Hollywood,CA,98775
2300,,Wilson,Wiley,"2323 Main Street, #23",,  Boston,MA,1472
2400,,Xray,Xavier,2424 24TH Street,,Nashville,TN,44190
2500,,Young,Yanni,2525 Yonge Street,,Toronto,ON,6B74A6
2600,,Zenith,Zebulon,2626 26TH Street,,Dallas,TX,71922
123456,,Doe,John,123 Main Street,,Anywhere,OR,88156
999999,,Smith,,   99 E Street,, San Rafael,CA,94901

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.

000000000100 Anderson                    Adrian              1113 Peachtree Plaza, Suite 111                                                                 Atlanta         GA26101
000000000200 Brown                       Billie              224 Baker Boulevard                                                                             Baltimore       MD35702
000000000300 Carson                      Cameron             336 Crenshaw Blvd.                                                                              Cupertino       CA96154
000000000400 Davidson                    Dion                448 Main Street                                                                                 Wilmington      DE27323
000000000500 Everest                     Evan                55 5TH Avenue                                                                                   New York        NY10341
000000000600 Franklin                    Francis             6612 66TH Avenue                                                                                Bedrock         NY11903
000000000700 Garfunkel                   Gwen                777 77TH Street                                                                                 New York        NY16539
000000000800 Harrison                    Hilary              888 88TH Street                                                                                 Pocatello       ID79684
000000000900 Isley                       Isabel              999 99TH Avenue                                                                                 Indianapolis    IN38762
000000001000 Johnson                     Jamie               1010 Paradise Drive                                                                             Larkspur        CA90504
000000001100 Kemper                      Kelly               1111 Oak Circle                                                                                 Kansas City     KS55651
000000001200 Lemond                      Lesley              1212 Lockwood Road                                                                              Mohave Desert   AZ80303
000000001300 Mitchell                    Marlow              1313 Miller Creek Road                                                                          Anywhere        TX77123
000000001400 Newman                      Noel                1414 Park Avenue                                                                                Santa Monica    CA90210
000000001500 Osborn                      Owen                1515 Center Stage                                                                               Rolling Rock    PA36613
000000001600 Powell                      Pierce              PO Box 1616                                                                                     Ventura         CA97712
000000001700 Quigley                     Quincy              1717 Farm Hill Road                                                                             Oshkosh         WI43389
000000001800 Ripley                      Ray                 1818 Alien Lane                                                                                 Wayout          KS55405
000000001900 Smith                       Sammy               1919 Carnoustie Drive                                                                           Novato          CA94919
000000002000 Tucker                      Taylor              2020 Sanger Lane                                                                                St. Paul        MN43998
000000002100 Underwood                   Ulysses             2121 Wall Street                                                                                New York        NY17623
000000002200 Van Etten                   Valerie                 2222 Vine Street, #22                                                                       Hollywood       CA98775
000000002300 Wilson                      Wiley               2323 Main Street, #23                                                                             Boston        MA1472
000000002400 Xray                        Xavier              2424 24TH Street                                                                                Nashville       TN44190
000000002500 Young                       Yanni               2525 Yonge Street                                                                               Toronto         ON6B74A6
000000002600 Zenith                      Zebulon             2626 26TH Street                                                                                Dallas          TX71922
000000123456 Doe                         John                123 Main Street                                                                                 Anywhere        OR88156
000000999999 Smith                                              99 E Street                                                                                   San Rafael     CA94901

Table of Contents Previous Section Next Section Programming Requirements

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

1 Executes on Windows/XP, Windows/7 and Windows Server using Micro Focus Net Express and the CMD file provided.
2 May be ported to run on the Linux and UNIX platforms supported by Micro Focus COBOL.
  Programming Requirements, Operating Environments for Program Execution

Table of Contents Previous Section Next Section Programming Overview

The main program (CBLCSVC2) will read an ASCII/Text file with CSV formatted records (CSVGETD1) and produce a file with the record content being a fixed field format (TXTPUTD1), The record length is 512 bytes.. The source code for the CMD file and the COBOL programs is provided and may be modified to fit your environment.

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

             
CBLCSVE2
cmd
Start the Job
   
CUSTLCSV
LSEQ
Comma-Separated
 
 
CBLCSVC2
cbl
   
   
CUSTLFFL
LSEQ
Fixed-Field
Read a CSV file and create a file with fixed field lengths
   
   
   
   
   
CBLCSVR2
cbl
Do the record content conversion, CSV to FFL
   
   
   
   
   
SIMOPARS
cbl
Parse the CSV strings
EOJ
This is End-of-Job.
   
Note-1: LSEQ = Line Sequential File, Record Format may be Comma-Separated-Value or Fixed-Field-Length
Create a Sequential file of fixed-length fields from a Comma Delimited file

Color Associations: The  light-green  boxes are unique to SIMOTIME Technologies using an IBM Mainframe System or Micro Focus Enterprise Developer. The  light-red  boxes are unique to the SIMOTIME Technologies using a Linux, UNIX or Windows System and COBOL Technologies such as Micro Focus. The  light-yellow  boxes are SIMOTIME Technologies, Third-party Technologies, decision points or program transitions in the processing logic or program generations. The  light-blue  boxes identify the input/output data structures such as Documents, Spreadsheets, Data Files, VSAM Data Sets, Partitioned Data Set Members (PDSM's) or Relational Tables. The  light-gray  boxes identify a system function or an informational item.

Table of Contents Previous Section Next Section CMD for Batch Job

The following (CBLCSVE2.cmd) is a sample of the Windows CMD needed to run this job. This set of programs illustrates the use of Micro Focus COBOL programs that will read an ASCII/Text file with a comma-separated-values (CSV) format and create an ASCII/Text file with a column-oriented, fixed-field-length (FFL) format.

@echo OFF
echo * CblCsvE2 is Starting...
rem  * *******************************************************************
rem  *               CBLCSVE2.CMD - a Windows Command File               *
rem  *         This program is provided by SimoTime Technologies         *
rem  *           (C) Copyright 1987-2019 All Rights Reserved             *
rem  *             Web Site URL:   http://www.simotime.com               *
rem  *                   e-mail:   helpdesk@simotime.com                 *
rem  * *******************************************************************
rem  *
rem  * Text    - COBOL, read a LCSV file and create a LFFL file.
rem  * Author  - SimoTime Technologies
rem  * Date    - December 12, 2003
rem  * Version - 04.01.20
rem  *
rem  * This set of programs illustrates the use COBOL programs that will
rem  * read an ASCII/Text file with a Comma-Separated-Values (CSV) format
rem  * and create an ASCII/Text file with a column-oriented,
rem  * Fixed-Field-Length (FFL) format.
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  *                     * if EXIST ******* CUSTLFFL *
rem  *                     *******stmt*     ******erase*
rem  *                          *
rem  *    ************     ************     ************
rem  *    * CUSTLCSV ******* CblCsvC2 ******* CUSTLFFL *
rem  *    *******lcsv*     ********cbl*     *******lffl*
rem  *                          *
rem  *                     ************
rem  *                     *   EOJ    *
rem  *                     ************
rem  *
rem  * Note-1: LCSV=Line Sequential with Comma-Separated-Values format.
rem  * Note-2: LFFL=Line Sequential with Fixed-Field-Length format.
rem  *
rem  * ********************************************************************
rem  * Step   1 of 2  Set the global environment variables...
rem  *
     call ..\Env1BASE
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
     set JobName=CblCsvE2
rem  *
     call SimoNOTE "*******************************************************%JobName%"
     call SimoNOTE "Starting JobName %JobName%, User is %USERNAME%"
rem  *
rem  * *******************************************************************
rem  * Step   2 of 2  Execute the program, create a TXT file.
rem  *
     set CUSTLCSV=%BaseLib1%\DATA\XLSS\SIMOTIME.TEXT.CUSTLCSV.CSV
     set CUSTLFFL=%BaseLib1%\DATA\TXT1\SIMOTIME.TEXT.CUSTLFFL.TXT
     set SYSOUT=%BaseLib1%\LOGS\SIMOTIME.SYSOUT.CBLCSVE2.TXT
     if exist %CUSTLFFL% erase %CUSTLFFL%
     run CBLCSVC2
     if not "%ERRORLEVEL%" == "0" set JobStatus=0010
     if not %JobStatus% == 0000 goto :EojNok
rem  *
     if exist %CUSTLFFL% goto :EojAok
     set JobStatus=0020
     goto :EojNok
:EojAok
     call SimoNOTE "DataTake CUSTLCSV=%CUSTLCSV%"
     call SimoNOTE "DataMake CUSTLFFL=%CUSTLFFL%"
     call SimoNOTE "Finished JobName %JobName%, Job Status is %JobStatus%"
     goto :End
:EojNok
     call SimoNOTE "ABENDING JobName %JobName%, Job Status is %JobStatus%"
:End
     call SimoNOTE "Conclude SysLog is %SYSLOG%"
     if not "%1" == "nopause" pause

Table of Contents Previous Section Next Section The COBOL Programs

The conversion process uses two (2) programs. The mainline program does the file I/O and calls the conversion routine to the record content conversion. The following describes the two programs.

Table of Contents Previous Section Next Section The COBOL I/O Program

The following (CBLCSVC2.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 6.0 running on Windows/7.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLCSVC2.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      *           This program was generated by SimoZAPS              *
      *             A product of SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *  Generation Date: 2012-01-16  Generation Time: 13:01:02:99    *
      *                                                               *
      *                                   Record    Record     Key    *
      *  Function  Name     Organization  Format    Max-Min  Pos-Len  *
      *  INPUT     CUSTLCSV ASCII/CRLF    VARIABLE   00512            *
      *                                                               *
      *  OUTPUT    CUSTLFFL ASCII/CRLF    FIXED      00512            *
      *                                                               *
      *                                                               *
      *****************************************************************
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT CUSTLCSV-FILE  ASSIGN TO       CUSTLCSV
                  ORGANIZATION  IS LINE SEQUENTIAL
                  ACCESS MODE   IS SEQUENTIAL
                  FILE STATUS   IS CUSTLCSV-STATUS.
           SELECT CUSTLFFL-FILE  ASSIGN TO       CUSTLFFL
                  ORGANIZATION  IS LINE SEQUENTIAL
                  ACCESS MODE   IS SEQUENTIAL
                  FILE STATUS   IS CUSTLFFL-STATUS.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  CUSTLCSV-FILE
           DATA RECORD    IS CUSTLCSV-REC
           .
       01  CUSTLCSV-REC.
           05  CUSTLCSV-DATA-01 PIC X(00512).

       FD  CUSTLFFL-FILE
           DATA RECORD    IS CUSTLFFL-REC
           .
       01  CUSTLFFL-REC.
           05  CUSTLFFL-DATA-01 PIC X(00512).

      *****************************************************************
      * This program was created with the SYSMASK3.TXT file as the    *
      * template for the File I/O. It is intended for use with the    *
      * TransCALL facility that makes a call to a routine that does   *
      * the actual conversion between EBCDIC and ASCII. For more      *
      * information or questions contact SimoTime Technologies.       *
      *                                                               *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      * The SYSMASK3 provides for the sequential reading of the input *
      * file and the sequential writing of the output file.           *
      *                                                               *
      * This program mask is used with a callable subroutine that     *
      * will do ASCII/EBCDIC Conversion based on a COBOL Copy File.   *
      *                                                               *
      * If the output file is indexed then the input file must be in  *
      * sequence by the field that will be used to provide the key    *
      * for the output file.                                          *
      *                                                               *
      * If the key field is not in sequence then refer to SYSMASK4    *
      * to provide for a random add or update of the indexed file.    *
      *****************************************************************
       WORKING-STORAGE SECTION.
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLCSVC2 '.
           05  T2 pic X(34) value 'Convert a CUSTLCSV to a CUSTLFFL  '.
           05  T3 pic X(10) value ' v10.07.06'.
           05  T4 pic X(24) value '   helpdesk@simotime.com'.
       01  SIM-COPYRIGHT.
           05  C1 pic X(11) value '* CBLCSVC2 '.
           05  C2 pic X(32) value 'This Data File Convert Member wa'.
           05  C3 pic X(32) value 's generated by SimoTime Technolo'.
           05  C4 pic X(04) value 'gies'.

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

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

       01  CUSTLCSV-LRECL            pic 9(5)    value 00512.
       01  CUSTLFFL-LRECL            pic 9(5)    value 00512.

      *****************************************************************
      * The following buffers are used to create a four-byte status   *
      * code that may be displayed.                                   *
      *****************************************************************
       01  IO-STATUS.
           05  IO-STAT1            pic X.
           05  IO-STAT2            pic X.
       01  IO-STATUS-04.
           05  IO-STATUS-0401      pic 9     value 0.
           05  IO-STATUS-0403      pic 999   value 0.
       01  TWO-BYTES-BINARY        pic 9(4)  BINARY.
       01  TWO-BYTES-ALPHA         redefines TWO-BYTES-BINARY.
           05  TWO-BYTES-LEFT      pic X.
           05  TWO-BYTES-RIGHT     pic X.

      *****************************************************************
      * 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  PROGRAM-NAME            pic X(8)     value 'CBLCSVC2'.

       01  INFO-STATEMENT.
           05  INFO-SHORT.
               10  INFO-ID pic X(8)    value 'Starting'.
               10  filler  pic X(2)    value ', '.
               10  filler  pic X(34)
                   value   'Convert a CUSTLCSV to a CUSTLFFL  '.
           05  filler      pic X(24)
               value ' http://www.SimoTime.com'.

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

       01  CUSTLCSV-TOTAL.
           05  CUSTLCSV-RDR  pic 9(9)    value 0.
           05  filler      pic X(3)    value ' - '.
           05  filler      pic X(23)   value 'Line count for CUSTLCSV'.
       01  CUSTLFFL-TOTAL.
           05  CUSTLFFL-ADD  pic 9(9)    value 0.
           05  filler      pic X(3)    value ' - '.
           05  filler      pic X(23)   value 'Line count for CUSTLFFL'.

      *****************************************************************
       PROCEDURE DIVISION.
           move all '*' to MESSAGE-TEXT-1
           perform Z-DISPLAY-MESSAGE-TEXT
           move INFO-STATEMENT to MESSAGE-TEXT-1
           perform Z-DISPLAY-MESSAGE-TEXT
           move all '*' to MESSAGE-TEXT-1
           perform Z-DISPLAY-MESSAGE-TEXT
           perform Z-POST-COPYRIGHT
           perform CUSTLCSV-OPEN
           perform CUSTLFFL-OPEN

           perform until CUSTLCSV-STATUS not = '00'
               perform CUSTLCSV-READ
               if  CUSTLCSV-STATUS = '00'
                   add 1 to CUSTLCSV-RDR
                   perform BUILD-OUTPUT-RECORD
                   perform CUSTLFFL-WRITE
                   if  CUSTLFFL-STATUS = '00'
                       add 1 to CUSTLFFL-ADD
                   end-if
               end-if
           end-perform

           move CUSTLCSV-TOTAL to MESSAGE-TEXT
           perform Z-DISPLAY-MESSAGE-TEXT

           move CUSTLFFL-TOTAL to MESSAGE-TEXT
           perform Z-DISPLAY-MESSAGE-TEXT

           if  APPL-EOF
               move 'Complete' to INFO-ID
           else
               move 'ABENDING' to INFO-ID
           end-if
           move INFO-STATEMENT to MESSAGE-TEXT(1:79)
           perform Z-DISPLAY-MESSAGE-TEXT

           perform CUSTLFFL-CLOSE
           perform CUSTLCSV-CLOSE
           GOBACK.

      *****************************************************************
       BUILD-OUTPUT-RECORD.
      *    Import CALL process...
           call 'CBLCSVR2'                        using CUSTLFFL-REC
                                                        CUSTLCSV-REC
           add 00512 to ZERO giving CUSTLFFL-LRECL
           exit.

      *****************************************************************
      * I/O Routines for the INPUT File...                            *
      *****************************************************************
       CUSTLCSV-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close CUSTLCSV-FILE
           if  CUSTLCSV-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'CLOSE Failure with CUSTLCSV' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CUSTLCSV-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       CUSTLCSV-READ.
           read CUSTLCSV-FILE
           if  CUSTLCSV-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  CUSTLCSV-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 CUSTLCSV-EOF
               else
                   move 'READ Failure with CUSTLCSV' to MESSAGE-TEXT
                   perform Z-DISPLAY-MESSAGE-TEXT
                   move CUSTLCSV-STATUS to IO-STATUS
                   perform Z-DISPLAY-IO-STATUS
                   perform Z-ABEND-PROGRAM
               end-if
           end-if
           exit.
      *---------------------------------------------------------------*
       CUSTLCSV-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open input CUSTLCSV-FILE
           if  CUSTLCSV-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to CUSTLCSV-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'OPEN Failure with CUSTLCSV' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CUSTLCSV-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.

      *****************************************************************
      * I/O Routines for the OUTPUT File...                           *
      *****************************************************************
       CUSTLFFL-WRITE.
           if  CUSTLFFL-OPEN-FLAG = 'C'
               perform CUSTLFFL-OPEN
           end-if
           write CUSTLFFL-REC
           if  CUSTLFFL-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  CUSTLFFL-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 'WRITE Failure with CUSTLFFL' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CUSTLFFL-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       CUSTLFFL-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open OUTPUT CUSTLFFL-FILE
           if  CUSTLFFL-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to CUSTLFFL-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'OPEN Failure with CUSTLFFL' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CUSTLFFL-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       CUSTLFFL-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close CUSTLFFL-FILE
           if  CUSTLFFL-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'C' to CUSTLFFL-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'CLOSE Failure with CUSTLFFL' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CUSTLFFL-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 messages...                                   *
      *****************************************************************
       Z-DISPLAY-MESSAGE-TEXT.
           if MESSAGE-TEXT-2 = SPACES
               display MESSAGE-BUFFER(1:79)
           else
               display MESSAGE-BUFFER
           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'
               move IO-STAT1 to IO-STATUS-04(1:1)
               subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
               move IO-STAT2 to TWO-BYTES-RIGHT
               add TWO-BYTES-BINARY to ZERO giving IO-STATUS-0403
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-04 to MESSAGE-TEXT(17:4)
               perform Z-DISPLAY-MESSAGE-TEXT
           else
               move '0000' to IO-STATUS-04
               move IO-STATUS to IO-STATUS-04(3:2)
               move 'File Status is: nnnn' to MESSAGE-TEXT
               move IO-STATUS-04 to MESSAGE-TEXT(17:4)
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if
           exit.

      *****************************************************************
       Z-POST-COPYRIGHT.
           display SIM-TITLE
           display SIM-COPYRIGHT
           exit.
      *****************************************************************
      *           This program was generated by SimoZAPS              *
      *             A product of SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *                                                               *
      *  Generation Date: 2012-01-16  Generation Time: 13:01:03:02    *
      *****************************************************************

Table of Contents Previous Section Next Section The COBOL Convert Routine

The following (CBLCSVR2.cbl) is a sample of the Micro Focus COBOL conversion routine from Comma-Separated-Values (CSV) to Fixed-Field-Length (FFL) formats. The program was tested using Micro Focus Net Express, version 6.0 running on Windows/7.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLCSVR2.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      *           This routine was generated by SimoREC1              *
      *             A product of SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *  Generation Date: 2012/01/16  Generation Time: 13:01:03:19    *
      *****************************************************************
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  NGZU-12-00.
           05  NRZU-12-00  pic  9(12).

       01  IX-P1               pic 9(9)      value 0.
       01  IX-P2               pic 9(9)      value 0.
       01  IX-NP               pic 9(5)      value 0.
       01  IX-L1               pic 9(9)      value 0.
       01  RA-P1               pic 9(3)      value 0.
       01  RA-P2               pic 9(3)      value 0.
       01  LOOP-CONTROL        pic 9(5)      value 0.
       01  COLUMN-NUMBER       pic 9(5)      value 0.
       01  WORK-AREA-X.
           05  WORK-AREA-X1    pic X         value '"'.
           05  WORK-AREA       pic X(00544)  value SPACES.
       01  WORK-AREA-X2        pic X(00512)  value SPACES.
       01  FRAME-STOP.
           05  FRAME-BYTE      pic X         value '"'.
           05  DELIMITER-BYTE  pic X         value ','.
       01  FRAME-FLAG          pic X         value 'N'.
       01  O-FLAG              pic X(3)      value 'CSV'.
       01  BYTE-Y              pic X         value 'Y'.
       01  BYTE-N              pic X         value 'N'.
       01  FRAME-COUNT         pic 9(5)      value 0.
       01  DELIM-COUNT         pic 9(5)      value 0.
       01  FFL-SIZE            pic 9(5)      value 0.
       01  CSV-SIZE            pic 9(5)      value 0.
       01  LAST-NON-SPACE-BYTE pic 9(5)      value 0.
       01  SIGN-BYTE           pic X         value SPACE.
       01  DIG-POS             pic 9(3).
       01  DIG-LEN             pic 9(3).
       01  DIG-CTL             pic 9(3).
       01  DEC-POS             pic 9(3).
       01  DEC-LEN             pic 9(3).
       01  DEC-CTL             pic 9(3).
       01  DEC-POINT           pic 9(3).
      *
      *****************************************************************
       LINKAGE SECTION.
       COPY CUSTTXB1.
       01  REC1CALL-REC pic X(00512).
      *
      *****************************************************************
       PROCEDURE DIVISION using CUSTTEXT-RECORD
                                REC1CALL-REC.
      *
           add 1 to ZERO giving IX-NP
           move ZERO to COLUMN-NUMBER
           move all SPACES
             to CUSTTEXT-RECORD
      *
      *    Number Move, CUSTTEXT-KEY
      *    Unsign, ZONED Decimal
           add 1 to COLUMN-NUMBER
           add 00012 to ZERO giving FFL-SIZE
           perform CONVERT-NUMBER
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-STATUS
           add 1 to COLUMN-NUMBER
           add 00001 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-LAST-NAME
           add 1 to COLUMN-NUMBER
           add 00028 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-FIRST-NAME
           add 1 to COLUMN-NUMBER
           add 00020 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-STREET-ADDR-01
           add 1 to COLUMN-NUMBER
           add 00048 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-STREET-ADDR-02
           add 1 to COLUMN-NUMBER
           add 00048 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-CITY
           add 1 to COLUMN-NUMBER
           add 00016 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-STATE
           add 1 to COLUMN-NUMBER
           add 00002 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
      *
      *    String Move, CUSTTEXT-POSTAL-CODE
           add 1 to COLUMN-NUMBER
           add 00012 to ZERO giving FFL-SIZE
           perform CONVERT-TEXT
           perform POST-DATA-TO-FIELD
           GOBACK.
      *
      *****************************************************************
       CONVERT-NUMBER.
           move SPACES to WORK-AREA
           move '+' to SIGN-BYTE
           perform GET-DATA-CONTENT
      *    Scan for Explicit Sign and Decimal Point...
           move ZERO to DIG-POS
           move ZERO to DIG-LEN
           move ZERO to DEC-POS
           move ZERO to DEC-LEN
           move ZERO to DEC-POINT
           add 1 to ZERO giving IX-L1
           if  WORK-AREA(1:1) = '+'
           or  WORK-AREA(1:1) = '-'
               move WORK-AREA(1:1) to SIGN-BYTE
               add 1 to IX-L1
           end-if
           perform
               until IX-L1 > 40
               or WORK-AREA(IX-L1:1) = SPACE
                   if  WORK-AREA(IX-L1:1) = '+'
                   or  WORK-AREA(IX-L1:1) = '-'
                       move WORK-AREA(IX-L1:1) to SIGN-BYTE
                       move SPACES to WORK-AREA(IX-L1:3)
                   end-if
                   if  WORK-AREA(IX-L1:1) = '.'
                       add IX-L1 to ZERO giving DEC-POINT
                   end-if
                   if  WORK-AREA(IX-L1:1) > '0'
                   and WORK-AREA(IX-L1:1) < '9'
                   or  WORK-AREA(IX-L1:1) = '0'
                   or  WORK-AREA(IX-L1:1) = '9'
                       if  DEC-POINT = ZERO
                           add 1 to DIG-LEN
                           if  DIG-POS = ZERO
                               add IX-L1 to DIG-POS
                           end-if
                       else
                           add 1 to DEC-LEN
                           if  DEC-POS = ZERO
                               add IX-L1 to DEC-POS
                           end-if
                       end-if
                   end-if
               add 1 to IX-L1
           end-perform
           exit.
      *
      *****************************************************************
       CONVERT-TEXT.
           move SPACES to WORK-AREA
           perform GET-DATA-CONTENT
           exit.
      *
      *****************************************************************
       GET-DATA-CONTENT.
      *    This routine performs a left-to-right scan of a data
      *    string. A data string may be enclosed within a set
      *    of framing characters (usually double-quotes).
      *    Concatenated data strings may be separated by a
      *    delimiter byte (usually a comma).
      *    The variable length data value minus the possible
      *    framing characters and will be placed in a work area
      *    for use with a fixed-length field format.
      *****************************************************************
           add 1 to ZERO giving IX-P2
           move ZERO to LOOP-CONTROL
           move BYTE-N to FRAME-FLAG
           if  REC1CALL-REC(IX-NP:1) = FRAME-BYTE
               move BYTE-Y to FRAME-FLAG
               add 1 to IX-NP
           end-if
           if  REC1CALL-REC(IX-NP:1) not = DELIMITER-BYTE
           or  FRAME-FLAG = BYTE-Y
               perform until REC1CALL-REC(IX-NP:1) = DELIMITER-BYTE
               and FRAME-FLAG = BYTE-N
               or LOOP-CONTROL > FFL-SIZE + 10
                 if  REC1CALL-REC(IX-NP:1) = FRAME-BYTE
                     if  REC1CALL-REC(IX-NP:2) = FRAME-STOP
                         add 1 to IX-NP
                         move BYTE-N to FRAME-FLAG
                     else
                         add 1 to IX-NP
                         move REC1CALL-REC(IX-NP:1)
                           to WORK-AREA(IX-P2:1)
                         add 1 to IX-NP
                         add 1 to IX-P2
                     end-if
                 else
                     move REC1CALL-REC(IX-NP:1) to WORK-AREA(IX-P2:1)
                     add 1 to IX-NP
                     add 1 to IX-P2
                 end-if
                 add 1 to LOOP-CONTROL
               end-perform
           end-if
      *    Increment past Delimiter Byte
           if  REC1CALL-REC(IX-NP:1) = DELIMITER-BYTE
               add 1 to IX-NP
           end-if
           exit.
      *
      *****************************************************************
       POST-DATA-TO-FIELD.
           evaluate COLUMN-NUMBER
             when 001  initialize NGZU-12-00
                       add 12 to ZERO giving DIG-CTL
                       add 00 to ZERO giving DEC-CTL
                       if  DIG-LEN > 0
                           if  DIG-LEN > DIG-CTL
                               perform until DIG-LEN < DIG-CTL + 1
                                   subtract 1 from DIG-LEN
                                   add 1 to DIG-POS
                               end-perform
                           end-if
                           move WORK-AREA(DIG-POS:DIG-LEN)
                           to NGZU-12-00(1 + DIG-CTL - DIG-LEN:DIG-LEN)
                       end-if
                       if  DEC-LEN > 0
                           if  DEC-LEN > DEC-CTL
                               add DEC-CTL to ZERO giving DEC-LEN
                           end-if
                           move WORK-AREA(DEC-POS:DEC-LEN)
                             to NGZU-12-00(DIG-CTL + 1:DEC-LEN)
                       end-if
                       if NRZU-12-00 is NUMERIC
                           if SIGN-BYTE = '-'
                               subtract NRZU-12-00 from ZERO
                               giving CUSTTEXT-KEY
                           else
                               add NRZU-12-00 to ZERO
                               giving CUSTTEXT-KEY
                           end-if
                       else
                           display 'non-Numeric in Numeric Field'
                       end-if
             when 002  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-STATUS
             when 003  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-LAST-NAME
             when 004  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-FIRST-NAME
             when 005  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-STREET-ADDR-01
             when 006  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-STREET-ADDR-02
             when 007  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-CITY
             when 008  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-STATE
             when 009  move WORK-AREA(1:FFL-SIZE)
                         to CUSTTEXT-POSTAL-CODE
           end-evaluate
           exit.
      *****************************************************************
      *           This routine was generated by SimoREC1              *
      *             A product of SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *  Generation Date: 2012/01/16  Generation Time: 13:01:03:19    *
      *****************************************************************

Table of Contents Previous Section Next Section The COBOL Parsing Program

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

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    SIMOPARS.
       AUTHOR.        SIMOTIME TECHNOLOGIES.
      *****************************************************************
      * Copyright (C) 1987-2019 SimoTime Technologies.                *
      *                                                               *
      * 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    *
      * Technologies.                                                 *
      *                                                               *
      * Permission to use, copy, modify and distribute this software  *
      * for any commercial purpose requires a fee to be paid to       *
      * SimoTime Technologies. 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           *
      * Technologies.                                                 *
      *                                                               *
      * SimoTime Technologies makes no warranty or representations    *
      * about the suitability of the software for any purpose. It is  *
      * provided "AS IS" without any expressed or implied warranty,   *
      * including the implied warranties of merchantability, fitness  *
      * for a particular purpose and non-infringement. SimoTime       *
      * Technologies 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 Technologies                                         *
      * 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 Technologies, *
      * 15 Carnoustie Drive, Novato, CA 94949-5849.                   *
      *                                                               *
      *****************************************************************
      *      This program is provided by SimoTime Technologies        *
      *        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 2048.
      *        05  PRS-BUFFER           PIC X(2048).
      *        05  PRS-TABLE-MAX        PIC 9(4)    VALUE 128.
      *        05  PRS-NUMBER-OF-ITEMS  PIC 9(4)    VALUE 0.
      *        05  PRS-LAST-SIG-BYTE    PIC 9(4)    VALUE 0.
      *        05  PRS-POSITION         OCCURS 128 TIMES
      *                                 PIC 9(4)    VALUE 0.
      *        05  PRS-SIZE             OCCURS 128 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.

      *****************************************************************
      * Message Buffer used by the Z-DISPLAY-MESSAGE-TEXT routine.    *
      *****************************************************************
       01  MESSAGE-BUFFER.
           05  MESSAGE-HEADER      pic X(11)   value '* SIMOPARS '.
           05  MESSAGE-TEXT.
               10  MESSAGE-TEXT-1  pic X(68)   value SPACES.
               10  MESSAGE-TEXT-2  pic X(188)  value SPACES.

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

      *****************************************************************
       PROCEDURE DIVISION using PRS-PARAMETERS.
           if  PRS-REQUEST not = '2'
               perform EDIT-LINKAGE-ITEMS
           end-if

           add      8 to   ZERO giving RETURN-CODE
           add      9 to   ZERO giving PRS-STATUS
           move ZERO to PRS-NUMBER-OF-ITEMS
           evaluate PRS-REQUEST
             when '0'   perform PARSE-BUFFER
             when '1'   perform INITIALIZE-TABLE-ELEMENTS
             when '2'   perform INITIALIZE-DEFAULT-VALUES
             when OTHER add 12 to ZERO giving PRS-STATUS
           end-evaluate

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

           GOBACK.

      *****************************************************************
       EDIT-LINKAGE-ITEMS.
           if  PRS-TABLE-MAX not numeric
               add 128 to ZERO giving PRS-TABLE-MAX
               move 'PRS-TABLE-MAX set to 128' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if
           if  PRS-TABLE-MAX > 128
               add 128 to ZERO giving PRS-TABLE-MAX
               move 'PRS-TABLE-MAX set to 128' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if

           if  PRS-BUFFER-SIZE not numeric
               add 2048 to ZERO giving PRS-BUFFER-SIZE
               move 'PRS-BUFFER-SIZE set to 2048' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if
           if  PRS-BUFFER-SIZE > 2048
               add 2048 to ZERO giving PRS-BUFFER-SIZE
               move 'PRS-BUFFER-SIZE set to 2048' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
           end-if

           exit.

      *****************************************************************
       INITIALIZE-DEFAULT-VALUES.
           move ',' to PRS-DELIMITER
           move 'Y' to PRS-SPACE-TRUNCATION
           move 'Y' to PRS-KEEP-NULL-FIELDS
           add 128 to ZERO giving PRS-TABLE-MAX
           add 2048 to ZERO giving PRS-BUFFER-SIZE
           perform INITIALIZE-TABLE-ELEMENTS
           move '0' to PRS-REQUEST
           move ZERO to PRS-STATUS
           move ZERO to PRS-NUMBER-OF-ITEMS
           move ZERO to PRS-LAST-SIG-BYTE
           exit.

      *****************************************************************
       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 Position/Length tables to zero (0).
           perform INITIALIZE-TABLE-ELEMENTS
           move ZERO to PRS-LAST-SIG-BYTE
      *!   Parse the Buffer.
           add 1 to ZERO giving O-PTR
           perform until I-PTR > PRS-BUFFER-SIZE
             perform PARSE-BUFFER-10
           end-perform

      *    Wrap-up the parse of this buffer...
           if  PRS-LAST-SIG-BYTE > 0
           and PRS-BUFFER(PRS-LAST-SIG-BYTE:1) not = PRS-DELIMITER
               add 1 to PRS-NUMBER-OF-ITEMS
           end-if

           if  PRS-POSITION(O-PTR) = 0
               subtract 1 from O-PTR
           end-if

           subtract RETURN-CODE from RETURN-CODE

           exit.
      *---------------------------------------------------------------*
       PARSE-BUFFER-10.
           if  PRS-BUFFER(I-PTR:1) not = SPACE
               add I-PTR to ZERO giving PRS-LAST-SIG-BYTE
           end-if

           if  PRS-BUFFER(I-PTR:1) = PRS-DELIMITER
               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

           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

           exit.

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

      *****************************************************************
      *      This example is provided by SimoTime Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Table of Contents Previous Section Next Section The COBOL Copy Files

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

Table of Contents Previous Section Next Section Record Layout or Structure

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

      *****************************************************************
      *               CUSTTXB1.CPY - a COBOL Copy File                *
      *        A Customer Text File used by CSV Demo programs.        *
      *         Copyright (C) 1987-2019 SimoTime Technologies         *
      *                     All Rights Reserved                       *
      *              Provided by SimoTime Technologies                *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************
      *    The record length is 512 bytes.
      *
      *    Column  Field Name               Size
      *       -    -----------------------   --
      *       A    CUSTTEXT-KEY              12
      *       B    CUSTTEXT-STATUS           01
      *       C    CUSTTEXT-LAST-NAME        28
      *       D    CUSTTEXT-FIRST-NAME       20
      *       E    CUSTTEXT-STREET-ADDR-01   48
      *       F    CUSTTEXT-STREET-ADDR-02   48
      *       G    CUSTTEXT-CITY             16
      *       H    CUSTTEXT-STATE            02
      *       I    CUSTTEXT-POSTAL-CODE      12
      *       -    -----------------------   --
      *
       01  CUSTTEXT-RECORD.
           05  CUSTTEXT-KEY            PIC 9(12).
           05  CUSTTEXT-STATUS         PIC X.
           05  CUSTTEXT-LAST-NAME      PIC X(28).
           05  CUSTTEXT-FIRST-NAME     PIC X(20).
           05  CUSTTEXT-STREET-ADDR-01 PIC X(48).
           05  CUSTTEXT-STREET-ADDR-02 PIC X(48).
           05  CUSTTEXT-CITY           PIC X(16).
           05  CUSTTEXT-STATE          PIC X(2).
           05  CUSTTEXT-POSTAL-CODE    PIC X(12).
           05  FILLER                  PIC X(325).
      *
      ***  CUSTTXB1 - End-of-Copy File - - - - - - - - - - - CUSTTXB1 *
      *****************************************************************
      *

Table of Contents Previous Section Next Section Pass Area of Parsing Program

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

      *****************************************************************
      *     Data Structure or Pass Area used for calling SIMOPARS.    *
      *****************************************************************
      *         Copyright (C) 1987-2019 SimoTime Technologies         *
      *                     All Rights Reserved                       *
      *****************************************************************
      *              Provided by SimoTime Technologies                *
      *        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-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.
           05  PRS-STATUS           PIC 9(4).
      ***  Provided by the calling program...
           05  PRS-DELIMITER        PIC X.
           05  PRS-KEEP-NULL-FIELDS PIC X.
           05  PRS-TERMINATOR       PIC X.
           05  PRS-TERMINATOR-BYTE  PIC X.
           05  PRS-SPACE-TRUNCATION PIC X.

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

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

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

Table of Contents Previous Section Next Section Summary

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. This document may be used to assist as a tutorial for new programmers or as a quick reference for experienced programmers.

In the world of programming there are many ways to solve a problem. This documentation and software were developed and tested on systems that are configured for a SIMOTIME environment based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be needed to execute the jobs and programs when transferred to a system of a different architecture or configuration.

SIMOTIME Services has experience in moving or sharing data or application processing across a variety of systems. For additional information about SIMOTIME Services or Technologies please contact us using the information in the  Contact or Feedback  section of this document.

Table of Contents Previous Section Next Section Software Agreement and Disclaimer

Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Technologies. Once the fee is received by SimoTime the latest version of the software, documentation or training material 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 Technologies.

SimoTime Technologies makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Technologies 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, documentation or training material.

Table of Contents Previous Section Next Section Downloads and Links

This section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an internet connection, the second group of documents will require an internet connection.

Note: A SimoTime License is required for the items to be made available on a local system or server.

Table of Contents Previous Section Next Section Current Server or Internet Access

The following links may be to the current server or to the Internet.

Link to Internet   Link to Server   Explore how to Create a File with CSV Formatted Records. The conversion from a Fixed-Field-Length (FFL) format to a Comma-Separated-Values (CSV) format is included in this example.

Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the Link to Internet icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the Link to Server icon.

Link to Internet   Link to Server   Explore the JCL Connection for more examples of JCL functionality with programming techniques and sample code.

Link to Internet   Link to Server   Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.

Link to Internet   Link to Server   Explore An Enterprise System Model that describes and demonstrates how Applications that were running on a Mainframe System and non-relational data that was located on the Mainframe System were copied and deployed in a Microsoft Windows environment with Micro Focus Enterprise Server.

Link to Internet   Link to Server   Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.

Link to Internet   Link to Server   Explore The File Status Return Codes that are used to interpret the results of accessing VSAM data sets and/or QSAM files.

Table of Contents Previous Section Next Section Internet Access Required

The following links will require an internet connect.

This suite of programs and documentation is available to download for review and evaluation purposes. Other uses will require a SimoTime Software License. Link to an Evaluation zPAK Option that includes the program members, documentation and control files.

A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection

Explore The Micro Focus Web Site for more information about products (including Micro Focus COBOL) and services available from Micro Focus. This link requires an Internet Connection.

Explore the GnuCOBOL Technologies available from SourceForge. SourceForge is an Open Source community resource dedicated to helping open source projects be as successful as possible. GnuCOBOL (formerly OpenCOBOL) is a COBOL compiler with run time support. The compiler (cobc) translates COBOL source to executable using intermediate C, designated C compiler and linker. This link will require an Internet Connection.

Table of Contents Previous Section Next Section Glossary of Terms

Link to Internet   Link to Server   Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.

Table of Contents Previous Section Next Section Contact or Feedback

This document was created and is maintained by SimoTime Technologies. If you have any questions, suggestions, comments or feedback please use the following contact information.

1. Send an e-mail to our helpdesk.
1.1. helpdesk@simotime.com.
2. Our telephone numbers are as follows.
2.1. 1 415 763-9430 office-helpdesk
2.2. 1 415 827-7045 mobile

 

We appreciate hearing from you.

Table of Contents Previous Section Next Section Company Overview

SimoTime Technologies was founded in 1987 and 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. Our customers include small businesses using Internet technologies to corporations using very large mainframe systems.

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. We specialize in preparing applications and the associated data that are currently residing on a single platform to be distributed across a variety of platforms.

Preparing the application programs will require the transfer of source members that will be compiled and deployed on the target platform. The data will need to be transferred between the systems and may need to be converted and validated at various stages within the process. SimoTime has the technology, services and experience to assist in the application and data management tasks involved with doing business in a multi-system environment.

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
Reading a Comma-Delimited File (CSV) with COBOL
Copyright © 1987-2024
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com