File Conversion & Formatting
When technology complements business   Mainframe and PC
Copyright © 1987-2008  SimoTime Enterprises, LLC  All Rights Reserved http://www.simotime.com

  Introduction
  Naming Convention
 
  Naming Convention for Programs
  Naming Convention for Data Files
  Flowchart for the File Conversion Cycle
  Data Conversion & File Formatting, Generating the Source Code
 
  Setting the Environment Variables
  Generating COBOL Source Code
  Compiling the COBOL Programs
  Step-01, Read from VSAM EBCDIC and Write to QSAM EBCDIC
  Step-02, Download QSAM EBCDIC to Server
  Step-03, Read from Sequential EBCDIC and Write to ASCII Indexed
  Step-04, Read from ASCII Indexed and Write to Sequential EBCDIC
  Step-05, Upload Sequential EBCDIC to Host
  Step-06, Read from Sequential EBCDIC and Write to VSAM EBCDIC
  File Conversion between ASCII Text and ASCII Indexed
 
 
Step-A1,  Read from ASCII Indexed and Write to ASCII/Text
  Expand the COMP (or BINARY) and COMP-3 (or Packed) Fields
 
Step-A2,  Edit the ASCII/Text File using NotePAD
 
Step-A3,  Read from ASCII/Text and Write to ASCII Indexed
  Create COMP (or BINARY) and COMP-3 (or Packed) Fields
  Extra Examples for Updating VSAM or Indexed Files
 
  Step-X1, Read from Sequential EBCDIC and Update an existing VSAM EBCDIC
  Step-X2, Read from ASCII/Text and Update an existing ASCII Indexed
  The ASCII and EBCDIC Tables
  A Data Conversion Exercise using Net Express
 
  Create an ASCII/Text File
  Convert ASCII/Text File to ASCII/Indexed File
  Convert ASCII/Indexed File to EBCDIC/Sequential File
  Convert EBCDIC/Sequential File to EBCDIC/VSAM/KSDS
  Convert EBCDIC/VSAM/KSDS to EBCDIC/Sequential File
  Convert EBCDIC/Sequential File to ASCII/Indexed File
  Convert ASCII/Indexed File to ASCII/Text File
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Comments or Suggestions
  About SimoTime
 
 Quick Connects 
The Assembler Connection
The COBOL Connection
The JCL Connection
The Numbers Connection
The SQL Connection
The VSAM-QSAM-Sort Connection
 References 
ASCII / EBCDIC Tables
Data Management
File Status Codes
File Transfer Protocol
Glossary of Terms
Search Engines and Links
Training and Self Study
Help Desk for SimoTime

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

There are many options available when moving and converting data between an IBM Mainframe and a Windows or Unix environment. This document will discuss the cycle of how to convert a VSAM, KSDS to a flat Sequential file on the mainframe, download the flat sequential file from the mainframe to the PC and create an Indexed file of ASCII content on the PC.

A general guideline to follow is, "The scope of effort for converting a mainframe legacy file from EBCDIC to ASCII is directly proportional to the size of the file, the age of the file and the number and type of numeric fields." Estimating the time for conversion between EBCDIC and ASCII can be done with a high degree of accuracy. Estimating the time for "scrubbing the data" may be a challenging task.

Additional programs are included for converting ASCII, Text files to Indexed files. These examples also show how to manage Packed-Decimal and BINARY or COMP fields.

In the world of programming there are many ways to solve a problem. This suite of programs is provided as an example of one of the possible solutions to the problems of file conversion. The intent is to keep the programming effort simple and do the conversion as quickly as possible.

The programs have been tested on an IBM mainframe, Mainframe Express from Micro Focus and Net Express from Micro Focus. Sample projects may be obtainf for Mainframe Express and Net Express by sending an e-mail to: helpdesk@simotime.com

Note: The source code and documentation for this suite of examples is available from the SimoTime Library under Download Directory at   www.simotime.com

This is an example of how a COBOL program can read a VSAM Keyed Sequential Data Set (KSDS) with EBCDIC content and create a sequential file with EBCDIC content. The example then describes how to translate the EBCDIC content to ASCII and write an ASCII file. At first glance the conversion between EBCDIC and ASCII appears to be a simple and practical task. Typically the EBCDIC files reside on a mainframe legacy system. These files may be very large and may have been updated over a period on many years. In addition to containing displayable EBCDIC characters the records may contain binary and packed decimal fields that cannot simply be converted using an EBCDIC/ASCII table. Also, some of the fields in a record may contains low-values (i.e. x'00') that are being handle as a space characters on the mainframe. The low-values remain low-values when converted to ASCII and when downloaded or ported to the PC these low-values may be treated as null characters and this could present a problem if not addressed in the initial conversion process.

The COBOL source code for the conversions programs was generated using SimoZAPS, a product of SimoTime Enterprises. The SimoZAPS utility program also has the capability of reading, writing or converting between other file formats. In the world of programming there are many ways to solve a problem. This suite of programs is provided as a COBOL example of one of the possible solutions to the problem of changing the contents and structure of data files.

Naming Convention
(Next) (Previous) (Table-of-Contents)

The programs and data files used in this example use a file naming format that is eight (8) characters long with a three (3) character extension.

Naming Convention for Programs
(Next) (Previous) (Table-of-Contents)

The member names used in this suite of examples are eight (8) characters long with a three (3) character extension.

Position Description
1-2
Value  The source or input file type.
KS VSAM, KSDS (Keyed-Sequential-Data-Set) or Indexed File
SQ QSAM or Sequential file
TX An ASCII/Text File
3
Value  The source file content.
A ASCII Content
E EBCDIC Content
4-5
Value  The target or output file type.
KS VSAM, KSDS (Keyed-Sequential-Data-Set) or Indexed File
SQ QSAM or Sequential file
TX An ASCII/Text File
6
Value  The target file content.
A ASCII Content
E EBCDIC Content
7
Value  Type of program or File.
C COBOL Program
T Text File
M Make function, usually a .BAT file.
X Xlate, or translate/convert routine, usually a .BAT file.
8
Value  Description
1 Sequential processing, add new records
2 Random processing, add new or update existing records

Naming Convention for Data Files
(Next) (Previous) (Table-of-Contents)

The data files used in this example are eight (8) characters long with a three (3) character extension.

Position Description
1-2
Value  The data file type.
KS VSAM, KSDS (Keyed-Sequential-Data-Set) or Indexed File
SQ QSAM or Sequential file
TX An ASCII/Text File
3
Value  The source file content.
A ASCII Content
E EBCDIC Content
4-5
Value  The target file type.
DB Data File or Data Base
6-8
Value  The target file content.
nnn Usually a three digit number that defines the record length

Flowchart for the File Conversion Cycle
(Next) (Previous) (Table-of-Contents)

The following shows the file conversion cycle or process when transferring files between the host system (in this example the host system is an IBM mainframe) and the PC/Windows environment. This illustration also shows the process for converting between ASCII/Text files and Indexed files.

        Host        
Data Set
SEQUENTIAL
ebcdic
SQEKSEC1
Read
SEQUENTIAL
Write
VSAM, KSDS
Data Set
VSAM, KSDS
ebcdic
KSESQEC1
Read
VSAM, KSDS
Write
SEQUENTIAL
Data Set
SEQUENTIAL
ebcdic
  Step-6       Step-1  
FTP
binary
Step-5 Upload
to
Host
      Download
to
Server
Step-2
FTP
binary
  Step-4   Server   Step-3  
Data Set
SEQUENTIAL
ebcdic
KSASQEC1
Read
INDEXED
Write
SEQUENTIAL
Data Set
INDEXED
ascii
SQEKSAC1
Read
SEQUENTIAL
Write
INDEXED
Data Set
SEQUENTIAL
ebcdic
               
       
COPY
lan
       
    Step-A3     Step-A1    
   
TXAKSAC1
Read
ASCII/Text
Write
INDEXED
Data Set
INDEXED
ascii
KSATXAC1
Read
INDEXED
Write
ASCII/Text
   
      Local PC      
   
Data Set
Text File
ascii
NotePAD
Read
ASCII/Text
Write
ASCII/Text
Data Set
Text File
ascii
   
      Step-A2      
    Step-A6       Step-A4    
   
CBLCSVC2
Read
CSV File
Write
Text File
     
CBLCSVC1
Read
Text File
Write
CSV File
   
             
   
Data Set
CSV File
ascii
Excel
Import
CSV File
Save As
CSV File
Data Set
CSV File
ascii
   
        Step-A5        

Data Conversion & File Formatting, Generating the Source Code
(Next) (Previous) (Table-of-Contents)

This section contains a number of example programs to do data file conversion between EBCDIC and ASCII. Two of the programs (TXAKSAC1.CBL and KSATXAC1.CBL) illustrate a process for converting packed-decimal and COMP fields to and from character-oriented numeric fields.

Once the COBOL source code has been generated it needs to be compiled. The following three .BAT files are provided to set the environment variables, generate the programs and compile the programs.

Member Description
ZENVST01.BAT This batch file will set the environment variables and is called by the following two .BAT files.
ZGENST01.TXT This .BAT file will generate all the COBOL source code used in this project.
ZCBLST01.CBL This i.BAT file will compile all the COBOL programs used in this project.

Setting the Environment Variables
(Next) (Previous) (Table-of-Contents)

The following is the .BAT file used to set the environment variables

@echo off
echo ****************************************************************
echo *                This program is provided by:                  *
echo *                 SimoTime Enterprises, LLC                    *
echo *        (C) Copyright 1987-2003 All Rights Reserved           *
echo *          Web Site URL:   http://www.simotime.com             *
echo *                e-mail:   helpdesk@simotime.com               *
echo ****************************************************************
echo * %0 is STARTING...
echo * %0 is STARTING...  >XENVST01.LOG
echo * This process will set the envariables for the demoST01.BAT
echo *
     SET  COBCPY=.;..\
     SET  DATACNTL=d:\simonxe1\st01\datacntl
rem  *
     set path=d:\Net Express;d:\Net Express\base\bin;path=%path%
rem  *
     set ENV4ST01=YES
rem  *
echo * %0 path is %path%
echo *                             >>XENVST01.LOG
echo * %0 path is as follows...    >>XENVST01.LOG
echo *                             >>XENVST01.LOG
echo * %path%                      >>XENVST01.LOG
echo *                             >>XENVST01.LOG
rem  *
echo * %0 is COMPLETE...
echo * %0 is COMPLETE...           >>XENVST01.LOG

Generating COBOL Source Code
(Next) (Previous) (Table-of-Contents)

The following is the .Bat file for generating the COBOL source code.

@echo off
echo ****************************************************************
echo *                This program is provided by:                  *
echo *                 SimoTime Enterprises, LLC                    *
echo *        (C) Copyright 1987-2003 All Rights Reserved           *
echo *          Web Site URL:   http://www.simotime.com             *
echo *                e-mail:   helpdesk@simotime.com               *
echo ****************************************************************
echo * %0 is STARTING...
echo * %0 is STARTING...  >>XGENST01.LOG
echo * This batch file generates the COBOL source code for the Demo.
echo *
     if exist XGENST01.LOG erase XGENST01.LOG
     if "%ENV4ST01%" == "YES" goto :SKIPENV
        CALL zENVst01.bat
:SKIPENV
rem  *
     setlocal
     call :GENERATE KSASQEM1 KSASQEC1
     call :GENERATE KSATXAM1 KSATXAC1
     call :GENERATE KSESQEM1 KSESQEC1
     call :GENERATE SQEKSAM1 SQEKSAC1
     call :GENERATE SQEKSEM1 SQEKSEC1
     call :GENERATE SQEKSEM2 SQEKSEC2
     call :GENERATE TXAKSAM1 TXAKSAC1
     call :GENERATE TXAKSAM2 TXAKSAC2
rem  *
     dir  XGENST01.LOG
     type XGENST01.LOG
echo * %0 is COMPLETE...
echo * %0 is COMPLETE...  >>XGENST01.LOG
     goto :END

:GENERATE
     echo * %1 COBOL Generation is STARTING...
     if exist %1.cbl erase %1.cbl
rem  *
     call %1
     if exist %2.CBL echo * 0% %1 generation SUCCESSFUL...
     if exist %2.CBL echo * 0% %1 generation SUCCESSFUL...    >>XGENST01.LOG
     if exist %2.CBL goto :END
     echo * 0% %1 generation FAILURE!!!...                    >>XGENST01.LOG
:END

Compiling the COBOL Programs
(Next) (Previous) (Table-of-Contents)

The following is the .BAT file for compiling the COBOL programs.

@echo off
echo ****************************************************************
echo *                This program is provided by:                  *
echo *                 SimoTime Enterprises, LLC                    *
echo *        (C) Copyright 1987-2003 All Rights Reserved           *
echo *          Web Site URL:   http://www.simotime.com             *
echo *                e-mail:   helpdesk@simotime.com               *
echo ****************************************************************
echo * %0 is STARTING...
echo * %0 is STARTING...                                   >>XCBLST01.LOG
echo * This process will compile all the COBOL programs for the Demo.
echo *
     if exist XCBLST01.LOG erase XCBLST01.LOG
     if "%ENV4ST01%" == "YES" goto :SKIPENV
        CALL zENVst01.bat
:SKIPENV
rem  *
     setlocal
     call :COMPILE KSASQEC1
     call :COMPILE KSATXAC1
     call :COMPILE KSESQEC1
     call :COMPILE SQEKSAC1
     call :COMPILE SQEKSEC1
     call :COMPILE SQEKSEC2
     call :COMPILE TXAKSAC1
     call :COMPILE TXAKSAC2
rem  *
     dir  XCBLST01.LOG
     type XCBLST01.LOG
echo * %0 is COMPLETE...
echo * %0 is COMPLETE...                                   >>XCBLST01.LOG
     goto :END

:COMPILE
     echo * %0 %1 COBOL Compile is STARTING...
     if exist %1.idy erase %1.idy
     if exist %1.obj erase %1.obj
     if exist %1.dll erase %1.dll
     if exist %1.gnt erase %1.gnt
     if exist %1.int erase %1.int
rem  *
     cobol %1.CBL noanim omf(gnt) assign(external);
     if exist %1.GNT echo * %0 %1 compiled with NO ANIMATE...
     if exist %1.GNT echo * %0 %1 compiled with NO ANIMATE... >>XCBLST01.LOG
     if exist %1.GNT goto :END
     echo * %0 %1 Compile failure!!!                          >>XCBLST01.LOG
:END

Step-01, Read from VSAM EBCDIC and Write to QSAM EBCDIC
(Next) (Previous) (Table-of-Contents)

Read a VSAM Keyed Sequential Data Set (KSDS) with EBCDIC content and create a sequential file with EBCDIC content. This program is intended to run on a mainframe but will also run on a PC with Micro Focus Mainframe Express. This program does not convert the content of the records within the file. It simply creates a new file type (i.e. VSAM, KSDS to a flat sequential file).

The KSESQEx1.ext files are used to generate, compile and execute the file conversion programs.

Member Description
KSESQEM1.BAT This batch file will execute the SimoZAPS utility to create a COBOL program that will do the file conversion.
KSESQET1.TXT This is the specificatons file that is read by the SimoZAPS Generation Function. The content of this file will be used by the preceding batch file to generate the COBOL source member that will do the specified file conversion.
KSESQEC1.CBL This is the generated COBOL source member that reads a VSAM, KSDS and creates a QSAM or sequential file.

The following flowchart is a quick overview of the process for generating the COBOL source code to do the file conversion and formating.

   
KSESQEM1
BAT
      The batch file for running the program to generate COBOL source code.
   
 
       
KSESQET1
SPECS
     
     
     
SIMOZAPS
UTL
     
     
     
KSESQEC1
CBL
  Read the input file (KSESQET1) containing the specifications for generating the source code and create a new file (KSESQEC1) containing the generated COBOL source code.
   
 
       
   
End-of-Job
EOJ
       

Step-02, Download Sequential EBCDIC file to PC or Server
(Next) (Previous) (Table-of-Contents)

Download the sequential file from the mainframe to the PC using FTP (File Transfer Protocol). Since the file contains EBCDIC characters, decimal-packed and COMP data it will be necessary to download in a BINARY format.

Note: Micro Focus provides a Mainframe Access (MFA)option with their Mainframe Express product. The MFA option may be used to download a sequential or VSAM file from the mainframe to the PC with a simple point-and-click or command line procedure.

Step-03, Read from Sequential EBCDIC and Write to ASCII Indexed
(Next) (Previous) (Table-of-Contents)

This program is intended to run on the PC using Micro Focus Net Express (it will also run on the mainframe and the PC with Mainframe Express). It will convert both the file type (i.e. Sequential to Indexed) and the content of the records within the file. Packed-decimal and COMP fields are copied as appropriate. Character fields are converted from EBCDIC to ASCII.

The SQEKSA?1.ext files are used to generate the file conversion program.

Member Description
SQEKSAM1.BAT This batch file will execute the SimoZAPS utility to create a COBOL program that will do the file conversion.
SQEKSAT1.TXT This is the specificatons file that is read by the SimoZAPS Generation Function. The content of this file will be used by the preceding batch file to generate the COBOL source member that will do the specified file conversion.
SQEKSAC1.CBL This is the generated COBOL source member that reads a Sequential EBCDIC file and creates an ASCII, Indexed file.

The following flowchart is a quick overview of the process for generating the COBOL source code to do the file conversion and formating.

   
SQEKSAM1
BAT
      The batch file for running the program to generate COBOL source code.
   
 
       
SQEKSAT1
SPECS
     
     
     
SIMOZAPS
UTL
     
     
     
SQEKSAC1
CBL
  Read the input file SQEKSAT1) containing the specifications for generating the source code and create a new file SQEKSAC1) containing the generated COBOL source code.
   
 
       
   
End-of-Job
EOJ
       

Step-04, Read from ASCII Indexed and Write to Sequential EBCDIC
(Next) (Previous) (Table-of-Contents)

This program is intended to run on the PC using Micro Focus Net Express (it will also execute on the PC with Mainframe Express or the mainframe). It will convert both the file type (i.e. Indexed to Sequential) and the content of the records within the file. Packed-decimal and COMP fields are copied as appropriate. Character fields are converted from ASCII to EBCDIC.

The KSASQE?1.ext files are used to generate the file conversion program.

Member Description
KSASQEM1.BAT This batch file will execute the SimoZAPS utility to create a COBOL program that will do the file conversion.
KSASQET1.TXT This is the specificatons file that is read by the SimoZAPS Generation Function. The content of this file will be used by the preceding batch file to generate the COBOL source member that will do the specified file conversion.
KSASQEC1.CBL This is the generated COBOL source member that reads a Sequential EBCDIC file and creates an ASCII, Indexed file.

The following flowchart is a quick overview of the process for generating the COBOL source code to do the file conversion and formating.

   
KSASQEM1
BAT
      The batch file for running the program to generate COBOL source code.
   
 
       
KSASQET1
SPECS
     
     
     
SIMOZAPS
UTL
     
     
     
KSASQEC1
CBL
  Read the input file KSASQET1) containing the specifications for generating the source code and create a new file KSASQEC1) containing the generated COBOL source code.
   
 
       
   
End-of-Job
EOJ
       

Step-05, Upload Sequential EBCDIC to Host
(Next ) (Previous) (Table-of-Contents)

Upload the sequential file from the mainframe to the PC using FTP (File Transfer Protocol). Since the file contains EBCDIC character, decimal-packed and COMP data it will be necessary to upload in a BINARY format.

Step-06, Read from Sequential EBCDIC and Write to VSAM EBCDIC
(Next) (Previous) (Table-of-Contents)

Read a Sequential file with EBCDIC content and create a VSAM Keyed Sequential Data Set (KSDS) with EBCDIC content. This program is intended to run on a mainframe and will run on a PC with Micro Focus Mainframe Express (it will also execute on the PC with Net Express). This program does not convert the content of the records within the file. It simply copies the records to the new file type (i.e. flat sequential file to a VSAM, KSDS).

The SQEKSEx1.ext files are used to generate, compile and execute the file conversion programs.

Member Description
SQEKSEM1.BAT This batch file will execute the SimoZAPS utility to create a COBOL program that will do the file conversion.
SQEKSET1.TXT This is the specificatons file that is read by the SimoZAPS Generation Function. The content of this file will be used by the preceding batch file to generate the COBOL source member that will do the specified file conversion.
SQEKSEC1.CBL This is the generated COBOL source member that reads a VSAM, KSDS and creates a QSAM or sequential file.

The following flowchart is a quick overview of the process for generating the COBOL source code to do the file conversion and formating.

   
SQEKSEM1
BAT
      The batch file for running the program to generate COBOL source code.
   
 
       
SQEKSET1
SPECS
     
     
     
SIMOZAPS
UTL
     
     
     
SQEKSEC1
CBL
  Read the input file (SQEKSET1) containing the specifications for generating the source code and create a new file (SQEKSEC1) containing the generated COBOL source code.
   
 
       
   
End-of-Job
EOJ
       

File Conversion between ASCII Text and ASCII Indexed
(Next) (Previous) (Table-of-Contents)

The following examples show how to convert between Indexed files and ASC/Text files. Since the COBOL programs contains the file definition of "ORGANIZATION IS LINE SEQUENTIAL" on the "SELECT" statement this program will not compile on the mainframe. The programs have been compiled and executed on the PC using Micro Focus Net Express.

Step-A1, Read from an ASCII/Indexed and Write to an ASCII/Text
(Next) (Previous) (Table-of-Contents)

This generated sample program will read an Indexed file with ASCII content and create a Text file with ASCII content. This example will also convert a packed-decimal (i.e. COMP-3) and BINARY (i.e. COMP) field to a printable numeric field.

The KSATXA?1.ext files are used to generate the file conversion program.

Member Description
KSATXAM1.BAT This batch file will execute the SimoZAPS utility to create a COBOL program that will do the file conversion.
KSATXAT1.TXT This is the specificatons file that is read by the SimoZAPS Generation Function. The content of this file will be used by the preceding batch file to generate the COBOL source member that will do the specified file conversion.
KSATXAC1.CBL This is the generated COBOL source member that reads an Indexed ASCII and creates an ASCII/Text.

The following flowchart is a quick overview of the process for generating the COBOL source code to do the file conversion and formating.

   
KSATXAM1
BAT
      The batch file for running the program to generate COBOL source code.
   
 
       
KSATXAT1
SPECS
     
     
     
SIMOZAPS
UTL
     
     
     
KSATXAC1
CBL
  Read the input file (KSATXAT1) containing the specifications for generating the source code and create a new file (KSATXAC1) containing the generated COBOL source code.
   
 
       
   
End-of-Job
EOJ
       

Step-A2, Edit the ASCII/Text File using NotePAD
(Next) (Previous) (Table-of-Contents)

Th