Generate a COBOL Program
 Convert from a KSDS to a Sequential File with CSV Format
http://www.simotime.com
When technology complements business    Copyright © 1987-2010  SimoTime Enterprises  All Rights Reserved
  Table of Contents Version 10.03.20 
  Introduction
 
  Programming Objectives
  Programming Input and Output
 
  The Process Control File
  The Record Layout or COBOL Copy File
  Sample Input Records of Mainframe File
  Sample Output Records in ASCII/Text and CSV Format
  Programming Requirements
  Programming Overview
  CMD for Execution with Net Express and Windows
  The COBOL Demonstration Program
  Record Layout for Column-Oriented, Fixed-Field-Length File
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Glossary of Terms
  Comments or Suggestions
  About SimoTime

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

In today's world it is the rule (rather than the exception) to have a business systems environment that consists of a variety of machine (both hardware and software) configurations. Today's business systems environment may include a mainframe and a mixture of Linux, UNIX and Windows (LUW) machines and their associated operating systems. It is most likely the machines are scattered at locations around the world.

This environment brings with it all the challenges of the transfer, share, convert and compare functions of managing data. Business users want their data delivered in a format that is ready to use on their individual machines. A typical data conversion request would be to convert a data file that is currently on an IBM mainframe to a file that may be easily imported into an Excel spreadsheet.

A mainframe file may be a VSAM KSDS or a record sequential file with fixed length records that are EBCDIC-encoded. The records are typically a group of fields (with fixed field length) arranged and accessed by their pre-defined position within the record. The numeric fields may be a signed or unsigned (implied positive) format. To further add to the confusion the numeric fields may be a variety of different formats (packed, binary or display formats are typically used on a mainframe).

A mainframe file will require two conversions, a "file format" and "record content" conversion. Both conversions may be done in a single scan of the file. This document will focus on converting to an ASCII/Text file with variable length records containing variable length data strings (or fields) separated (or delineated) by a comma (a CSV or Comma-Separated-Values). The numeric fields will require special handling (especially the signed and/or non-display numeric formats).

This suite of sample programs describes how to read a column oriented file of fixed length records and fixed length fields and create a comma-delimited file (filename.CSV, Comma-Separated-Value) of variable length fields with the leading and trailing spaces removed from each of the fields. If a field (or data string) contains a delimiter character then enclose the field in double quotes. The program may be adjusted to create 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.

Item Description
1. Demonstrate how to generate the programs that will convert a mainframe, EBCDIC-encoded File to an ASCII/Text, Comma-Separated-Values (or CSV) File.
2. Describe the contents of a Process Control File.
3. Describe how to convert mainframe numeric formats to a standard display format with a separate sign position
4. Describe how to generate HTML documentation for the record layout that is defined by a COBOL Copy File

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

The following is an example of a file that contains records with predefined, fixed-length fields. This file will be used to create a Comma Delimited file (filename.CSV).The customer number is in positions 1 through 6. Notice that customer numbers 002200, 002300 and 999999 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 Process Control File
(Next) (Previous) (Table-of-Contents)

The following is the Process Control File (filename.PCF). If column one is an asterisk the record is a comment. If column one contains an ampersand it is a process control statement.

***********************************************************************
*                     This program is provided by:                    *
*                      SimoTime Enterprises, LLC                      *
*             (C) Copyright 1987-2010 All Rights Reserved             *
*               Web Site URL:   http://www.simotime.com               *
*                     e-mail:   helpdesk@simotime.com                 *
***********************************************************************
* SYSUT1 is the Customer Master File, Indexed, 512-byte records.      *
* SYSUT2 is a Record Sequential file, 256-byte fixed-length records.  *
***********************************************************************
* This Process Control File will be used to generate a callable COBOL
* routine that will extract data from the customer master file and
* create a record sequential with the fields separated by a comma.
* The input file (CUSTMAST.DAT) is a Micro Focus Key-Sequenced file.
* The output file may be easily imported into an Excel spread sheet.
* Refer to the utconv01.htm document for additional detail.
*
* The following group of statements will define the high level
* functions and processes to be performed.
*
&SIMOPREP  call ..\Env1BASE
&USERPREP  call UserCONV
&CONFORM   IBM
&COPYFILE  CUSTCB01.CPY
&HTMLFILE  cusext01.htm
*
* The following group of statements will define the behavioral
* characteristics and environment variable for the file I/O Program
* to be generated.
*
*HEAD34    ....:....1....:....2....:....3....
&HEAD34    Extract Customer Info to CSV RSEQ
&PROGID    CUSEXTC1
&SYSUT1    name=CUSTMAST org=Indexed    recfm=VARIABLE rmin=12 rmax=512 kpos=1 klen=12 RECVARY
&SYSUT2    name=CUSTRCSV org=Sequential recfm=FIXED    rmax=256
*
* The following two statements are used when the records in the data
* file (input or output) are a Comma-Separated-Values (or CSV) format.
*
&DELIMITER ,
&FRAME     "
*
* The following group of statements will define the behavioral
* characteristics and environment variables for the record content
* conversion program to be generated.
* This is for CSV Formatted output records.
*
&EXTCALL   CUSEXTR1
&EXTREC    CUST-RECORD
&EXTLREC   256
&EXTFMT    CSV ,
&EXTINIT   SPACES
&EXTHDR    YES
*
* The following group of statements will define the fields to be
* extracted from the input file and written to the output file.
* conversion program to be generated.
* This is for CSV Formatted output records.
*
&EXTRACT   CUST-NUMBER
&EXTRACT   CUST-STATUS
&EXTRACT   CUST-LAST-NAME
&EXTRACT   CUST-FIRST-NAME
&EXTRACT   CUST-MID-NAME
&EXTRACT   CUST-ADDRESS-1
&EXTRACT   CUST-ADDRESS-2
&EXTRACT   CUST-CITY
&EXTRACT   CUST-STATE
&EXTRACT   CUST-POSTAL-CODE
&EXTRACT   CUST-PHONE-WORK
&EXTRACT   CUST-PHONE-CELL
&EXTRACT   CUST-CREDIT-LIMIT
*
&END
An Example of a Process Control File

Refer to the  Field Extract Utility Conversion Program  for a detailed description of the statements within the Process Control File

The Record Layout or COBOL Copy File
(Next) (Previous) (Table-of-Contents)

The following is the record layout for COBOL.

       01  SYSTXTT1-RECORD.
           05  SYSTXTT1-KEY            PIC X(6).
           05  FILLER                  PIC X.
           05  SYSTXTT1-LAST-NAME      PIC X(20).
           05  SYSTXTT1-FIRST-NAME     PIC X(10).
           05  SYSTXTT1-STREET-ADDRESS PIC X(25).
           05  SYSTXTT1-CITY           PIC X(16).
           05  SYSTXTT1-STATE          PIC X(2).

Sample Input Records of Mainframe File
(Next) (Previous) (Table-of-Contents)

The following is the column-oriented, 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

The following is an example of a Comma Delimited file that was created from reading the preceding Sequential (or LINE Sequential) file that contains records with predefined, fixed fields. This file was created by a COBOL program running on a PC with Micro Focus COBOL (Net Express, version 4.0).

Sample Output Records in ASCII/Text and CSV Format
(Next) (Previous) (Table-of-Contents)

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.

Item Description
1. Executes on Windows/XP, Windows Vista, Windows/7 or Windows Server.
2. Micro Focus Net Express or Micro Focus Studio is required to generate, compile and execute the COBOL conversion programs.
3. The generated programs may be compiled and executed on a Linux or UNIX platform that s 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.

                   
 
GENCVTL1
lseq
 
 
 
GENCVTE1
cmd
          Start the Job
   
     
     
     
     
     
     
           
   
     
     
     
if &SIMOPREP
Call
 
 
 
     
     
     
       
   
     
   
SIMOPREP
cmd
      Set the System (or global) environment variables
   
     
     
     
if &USERPREP
Call
 
 
 
     
     
     
       
   
     
   
USERPREP
cmd
      Set the User (or job specific) environment variables
   
     
     
     
     
     
     
           
 
Entry TAG-A
 
LOOP
for
          Read a file of a list of member names
     
 
           
 
     
     
     
Yes
 
 
End-of-List
?
No
 
 
     
     
     
      Process each name in the list
 
     
     
     
       
 
     
     
SimoCONV
cmd
       
 
     
     
     
     
 
 
 
 
 
 
     
     
     
       
 
     
     
     
     
Run
 
 
 
     
     
     
       
 
     
     
UTCONVD1proc
pcf
 
 
 
UTCONVRT
cbl
     
     
     
UTCONVD2genr
cmd
  Read the Process Control file,
Create CMD and Specification file
 
     
     
     
     
   
 
     
     
     
     
     
     
UTCONVD3spec
txt
  Specifications File 
 
     
     
     
     
if Job-Status=0
Call
 
 
 
     
     
     
       
 
     
   
UTCONVD2genr
cmd
      Execute the newly created CMD file,
generate the conversion programs
 
     
     
     
     
 
 
 
 
 
 
     
     
     
       
 
     
     
     
     
if &HTMLFILE
Call
 
 
 
     
     
     
       
 
     
     
member-name
CPY
 
 
 
REC1HTML
cmd
 
 
 
member-name
HTML
  Generate the HTML Document
 
     
     
     
     
if &PROGID
Call
 
 
 
     
     
     
       
 
     
     
UTCONVD3spec
TXT
 
 
 
ZAPSREC1
cmd
 
 
 
&PROGID
CBL
  Generate the I/O Member, a file copy and possible file format conversion
 
     
     
     
     
if &CALLEXT
Call
 
 
 
     
     
     
       
 
     
     
member-name
CPY
 
 
 
REC1EXTR
cmd
 
 
 
&CALLEXT
CBL
  Generate the callable conversion routine for record content conversion
 
     
     
     
     
GOTO TAG-A
           
 
     
     
     
 
 
 
     
     
     
           
     
EOJ
          End-of-Job
                   
Create a Comma Delimited file from a Sequential file of fixed-length fields

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 (GENCVTE1.CMD) is a sample of the Windows CMD needed to run this job.

@echo OFF
rem  * ************************************************************************
rem  * This procedure calls the following Windows Command Files.
rem  * 1. Env1Base.CMD - this provides a single point for setting commonly
rem  *    used environment variables.
rem  * 2. SimoNOTE.CMD - this provides a consistent process for displaying
rem  *    messages to the screen and writing to a journal or log file.
rem  * 3. SimoCONV.CMD - this will do the actual compile of the
rem  *    specified program.
rem  * ************************************************************************
     set CmdName=GenCvtE1
     call ..\Env1BASE
rem  *
     call SimoNOTE "***********************************************%CmdName%.CMD"
     call SimoNOTE "Starting JobName %CmdName%.CMD"
rem  *
rem  * Set the environment variables for directories or folders.
     set UTCOBCPY=c:\SimoSam1\CobCpy1
     set UTHTMLIB=c:\SimoSam1\HTML
     set UTGENGET=c:\SimoSam1\CONVERTS
     set UTGENPUT=c:\SimoSam1\GENS
rem  * Set the environment variables for config file and counters
     set SimoGENS=PAUSE
     set SIMOCFG1=SIMOCFG1.CFG
     set AOK_Count=0
     set NOK_Count=0
     for /F %%i in (SIMOTIME.LISTONE.GENCVTL1.LST) do CALL SimoCONV %%i
rem  *
     call SimoNOTE "AOKcount Compile Count for AOK is %AOK_Count% "
     call SimoNOTE "NOKcount Compile Count for NOK is %NOK_Count% "
     call SimoNOTE "Finished JobName %CmdName%.CMD "
     if not "%SimoGENS%" == "BATCH" pause
Command File, How to Create and Execute a COBOL Program to Convert a Mainframe Data Set to a Comma-Separated-Values File.

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

The following (CBLCSVC1.CBL) is an example of a Micro Focus COBOL demonstration program that reads a file of fixed-length fields within fixed-length records and creates a new file with CSV (Comma-Separated-Values) formatted records. 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 5.0 running on Windows/XP.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLCSVC1.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2010 SimoTime Enterprises.                 *
      *                                                               *
      * 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     TXTGETD1 SEQUENTIAL    FIXED      00080            *
      *  OUTPUT    CSVPUTD1 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 TXTGETD1-FILE  ASSIGN TO TXTGETD1
                  ORGANIZATION   IS LINE SEQUENTIAL
                  ACCESS MODE    IS SEQUENTIAL
                  FILE STATUS    IS TXTGETD1-STATUS.
           SELECT CSVPUTD1-FILE  ASSIGN TO CSVPUTD1
                  ORGANIZATION   IS LINE SEQUENTIAL
                  ACCESS MODE    IS SEQUENTIAL
                  FILE STATUS    IS CSVPUTD1-STATUS.

      *****************************************************************
       DATA DIVISION.
       FILE SECTION.
       FD  TXTGETD1-FILE
           DATA RECORD    IS CUSTTEXT-RECORD.
       COPY CUSTTXB1.


       FD  CSVPUTD1-FILE
           DATA RECORD    IS CSVPUTD1-RECORD.
       01  CSVPUTD1-RECORD.
           05  CSVPUTD1-DATA-01  PIC X(00128).

       WORKING-STORAGE SECTION.
      *****************************************************************
      *    Data-structure for Title and Copyright...
      *    ------------------------------------------------------------
       01  SIM-TITLE.
           05  T1 pic X(11) value '* CBLCSVC1 '.
           05  T2 pic X(34) value 'Comma Delimited File, Write 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 '* CBLCSVC1 '.
           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 '* CBLCSVC1 '.
           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 '* CBLCSVC1 '.
           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  TXTGETD1-STATUS.
           05  TXTGETD1-STATUS-L   pic X.
           05  TXTGETD1-STATUS-R   pic X.
       01  TXTGETD1-EOF            pic X       value 'N'.
       01  TXTGETD1-OPEN-FLAG      pic X       value 'C'.

       01  CSVPUTD1-STATUS.
           05  CSVPUTD1-STATUS-L   pic X.
           05  CSVPUTD1-STATUS-R   pic X.
       01  CSVPUTD1-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 '* CBLCSVC1 '.
           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.

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

           perform Z-POST-COPYRIGHT

           perform TXTGETD1-OPEN
           perform CSVPUTD1-OPEN

           perform until TXTGETD1-STATUS not = '00'
               perform TXTGETD1-READ
      *        If a successful read of the input file and the input
      *        record is not equal to SPACES then create an output.
               if  TXTGETD1-STATUS = '00'
               and CUSTTEXT-RECORD not = SPACES
                   display CUSTTEXT-RECORD
                   perform BUILD-COMMA-DELIMITED-STRING
                   display WORK-128
                   perform POST-STRING-WITH-CLEAR-AFTER
               end-if
           end-perform

           perform CSVPUTD1-CLOSE
           perform TXTGETD1-CLOSE

           perform Z-THANK-YOU

           GOBACK.

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

       BUILD-COMMA-DELIMITED-STRING.
           add 1 to ZERO giving CSV-X1

           move CUSTTEXT-KEY to WORK-50
           perform PARSE-AND-POST

           move CUSTTEXT-LAST-NAME to WORK-50
           perform PARSE-AND-POST

           move CUSTTEXT-FIRST-NAME to WORK-50
           perform PARSE-AND-POST

           move CUSTTEXT-STREET-ADDRESS to WORK-50
           perform PARSE-AND-POST

           move CUSTTEXT-CITY to WORK-50
           perform PARSE-AND-POST

           move CUSTTEXT-STATE to WORK-50
           perform PARSE-AND-POST

      *    Set CSV-X1 to position of last character in string and
      *    remove the trailing comma...
           subtract 1 from CSV-X1
           if  WORK-128(CSV-X1:2) = ', '
               move '  ' to WORK-128(CSV-X1:2)
               subtract 1 from CSV-X1
           end-if

           exit.
      *****************************************************************
       PARSE-AND-POST.
           perform PARSE-WORK-50
           perform POST-WORK-50
           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-WORK-50.
           subtract SIG-FIRST from SIG-FIRST
           subtract SIG-LAST from SIG-LAST
           subtract SIG-LENGTH from SIG-LENGTH

      *    The IDX-STOP is used to stop the perform loop by setting the
      *    number of characters to scan.
           add 50 to ZERO giving IDX-STOP

      *    The following is for performance and will quickly reduce
      *    the number of times the perform loop executes.
           if  WORK-50(26:25) = SPACES
               if  WORK-50(13:13) = SPACES
                   add 12 to ZERO giving IDX-STOP
               else
                   add 25 to ZERO giving IDX-STOP
               end-if
           else
               if  WORK-50(38:13) = SPACES
                   add 37 to ZERO giving IDX-STOP
               else
                   add 50 to ZERO giving IDX-STOP
               end-if
           end-if

           add 1 to ZERO giving IDX-1
           move 'N' to DATA-HAS-DELIMITER
           perform until IDX-1 GREATER THAN IDX-STOP
               if  WORK-50(IDX-1:1) = DELIMITER-BYTE
                   move 'Y' to DATA-HAS-DELIMITER
               end-if
               if  WORK-50(IDX-1:1) not = SPACE
                   add IDX-1 to ZERO giving SIG-LAST
                   if  SIG-FIRST = 0
                       add IDX-1 to ZERO giving SIG-FIRST
                   end-if
               end-if
               add 1 to IDX-1
           end-perform
           if  SIG-FIRST GREATER THAN ZERO
               compute SIG-LENGTH = SIG-LAST - SIG-FIRST + 1
           end-if
           exit.

      *****************************************************************
      * Move the field to the output buffer and insert a trailing     *
      * delimiter character.                                          *
      *****************************************************************
       POST-WORK-50.
      *    The following will insert a leading Double-Quote if the
      *    data string contains a delimiter character.
           if  DATA-HAS-DELIMITER = 'Y'
               move DOUBLE-QUOTE to WORK-128(CSV-X1:1)
               add 1 to CSV-X1
           end-if
      *

      *    Remove the delimiter characters from the data string.
      *    inspect WORK-50(1:IDX-STOP)
      *            replacing all DELIMITER-BYTE by SPACE
      *

           if  SIG-FIRST GREATER THAN ZERO
               move WORK-50(SIG-FIRST:SIG-LENGTH)
                 to WORK-128(CSV-X1:SIG-LENGTH)
               add SIG-LENGTH to CSV-X1
      *        The following will insert a trailing Double-Quote if
      *        the data string contains a delimiter character.
               if  DATA-HAS-DELIMITER = 'Y'
                   move DOUBLE-QUOTE to WORK-128(CSV-X1:1)
                   add 1 to CSV-X1
               end-if
      *
               move DELIMITER-BYTE to WORK-128(CSV-X1:1)
               add 1 to CSV-X1
           else
               move DELIMITER-BYTE to WORK-128(CSV-X1:1)
               add 1 to CSV-X1
           end-if
           exit.

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

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

      *****************************************************************
      * I/O ROUTINES FOR CSVPUTD1...                                  *
      *****************************************************************
       CSVPUTD1-WRITE.
           if  CSVPUTD1-OPEN-FLAG = 'C'
               perform CSVPUTD1-OPEN
           end-if
           write CSVPUTD1-RECORD
           if  CSVPUTD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
           else
               if  CSVPUTD1-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 'CSVPUTD1-Failure-WRITE...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CSVPUTD1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       CSVPUTD1-OPEN.
           add 8 to ZERO giving APPL-RESULT.
           open OUTPUT CSVPUTD1-FILE
           if  CSVPUTD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'O' to CSVPUTD1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'CSVPUTD1-Failure-OPEN...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CSVPUTD1-STATUS to IO-STATUS
               perform Z-DISPLAY-IO-STATUS
               perform Z-ABEND-PROGRAM
           end-if
           exit.
      *---------------------------------------------------------------*
       CSVPUTD1-CLOSE.
           add 8 to ZERO giving APPL-RESULT.
           close CSVPUTD1-FILE
           if  CSVPUTD1-STATUS = '00'
               subtract APPL-RESULT from APPL-RESULT
               move 'C' to CSVPUTD1-OPEN-FLAG
           else
               add 12 to ZERO giving APPL-RESULT
           end-if
           if  APPL-AOK
               CONTINUE
           else
               move 'CSVPUTD1-Failure-CLOSE...' to MESSAGE-TEXT
               perform Z-DISPLAY-MESSAGE-TEXT
               move CSVPUTD1-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.
           display MESSAGE-BUFFER upon console
           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.

      *****************************************************************
       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    *
      *****************************************************************
Sample Program, read a file of fixed-length fields within fixed-length records and create a new file with CSV formatted records.

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).
Source Listing, Copy File with Customer Data

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

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

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#COBOLCommaDelimitedFileCreateNew 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 Read and Parse an Existing 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 .

Glossary of Terms
(Next) (Previous) (Table-of-Contents)

Check out  The SimoTime Glossary  for a list of terms and definitions used in the documents provided by SimoTime.

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