COBOL, Sequential Add Convert Sequential File to KSDS |
The SimoTime Home Page |
This is an example of how a COBOL program can read a record sequential (RSEQ) file and write a VSAM Keyed-Sequential-Data-Set (KSDS) using sequential processing techniques. Each file contains fixed-length records. The records contained in the output file will be a mirror image of the records contained in the input file. The COBOL source code was generated using SimoTime technologies. Refer to the "Downloads and Links" section of this document for additional information.
In the world of programming there are many ways to solve a problem. This program is provided as a COBOL example of one of the possible solutions to the problem of changing the contents and structure of data files.
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-2025
SimoTime Technologies and Services
All Rights Reserved
This program will read a record sequential file and write to a VSAM Keyed-Sequential-Data-Set. The encoding schema (i.e. ASCII or EBCDIC) and record format (i.e. 512-byte, fixed-length records with packed and binary data fields) will be the same for both the input and output file.
Note: Since this conversion task is only doing a file-format conversion and the record content is not processed but simply copied then the encoding schema of the records is not a consideration. The records may be EBCDIC, ASCII or BINARY and they will be copied without being changed.
The following Process Control File (SEQKSD01.pcf) contains the specifications for generating a COBOL program that will do a file format conversion by doing a copy of a VSAM, KSDS to a Record Sequential file.
*********************************************************************** * SEQKSD01.pcf - a Process Control File for Numeric Totals * * (C) Copyright 1987-2019 All Rights Reserved * * Web Site URL: http://www.simotime.com * * e-mail: helpdesk@simotime.com * *********************************************************************** * SYSUT1 is a Record Sequential, 512-byte, fixed, file with * Packed and Binary data. * * SYSUT2 is a KSDS, 512-byte, file with Packed and Binary data. * * This process control file will be used to generate a file format * conversion program. The generated program is intended to do an * ordered load of a new VSAM/KSDS. The records in the sequential file * must be sequenced by the primary key field. *********************************************************************** * &SIMOPREP call ..\..\ENV1BASE &USERPREP call USERCONV &CONFORM IBM &DIALECT C2 &VSAMload SEQUENTIAL *HEAD34 ....:....1....:....2....:....3.... &HEAD34 Convert from RSEQ-512 to KSDS-512 &IOMODNAME SEQKSDC1 &SYSUT1 name=DX512SEQ org=Sequential recfm=FIXED rlen=512 &SYSUT2 name=DX512KSD org=Indexed recfm=VARIABLE rmin=12 rmax=512 kpos=1 klen=12 &TransCOPY from pos 1 len 512 to pos 1 len 512 * &END
The following is the content of the (SEQKSDX1.cmd) file that was used to create the COBOL source code. This process uses the SimoZAPS utility program to do the actual program generation.
@echo OFF rem * ******************************************************************* rem * SEQKSDX1.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 * set JobName=SEQKSDX1 rem * Set the Environment for the System Level call ../ENV1BASE call SimoNOTE "***********************************************************************%JobName%" call SimoNOTE "* Starting %JobName%" call SimoNOTE "* SEQKSDX1 Starting the GENERATE function. call SimoNOTE "* This process will read the SEQKSD01.pcf file and create the" call SimoNOTE "* SEQKSDC1.cbl source member to do a data file conversion." call SimoNOTE "* The SEQKSD01.pcf file is expected to contains the specifications" call SimoNOTE "* for reading a Record Sequential file (RSEQ) and writing to an" call SimoNOTE "* Indexed file. Both files have 512-byte fixed-length records." call SimoNOTE "* The generated conversion program will add new records to the file" call SimoNOTE "* using sequential processing techniques." call SimoNOTE "* set ConvertStatus=0016 cd %BASELIB1%\CONVERTS call EZUTCONV SEQKSD01 if not "%ConvertStatus%" == "0000" goto :ConvertEojNOK rem * rem * ************************************************************************ :ConvertEojAOK call SimoNOTE "* Complete %JobName%, RC=%ConvertStatus%" goto :End rem * rem * ************************************************************************ :ConvertEojNOK call SimoNOTE "* ABENDING %JobName%, RC=%ConvertStatus%, !!!ABENDING!!!" goto :End rem * rem * ************************************************************************ :End pause
The following member (KSDSEQC1.cbl) is the generated COBOL source code that will do a file format conversion by reading an Indexed file and writing to a Sequential file.
IDENTIFICATION DIVISION. PROGRAM-ID. SEQKSDC1. 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: 2014-05-06 Generation Time: 11:19:55:02 * * * * Record Record Key * * Function Name Organization Format Max-Min Pos-Len * * INPUT DX512SEQ SEQUENTIAL FIXED 00512 * * * * OUTPUT DX512KSD INDEXED VARIABLE 00512 00001 * * 00012 00012 * * * ***************************************************************** ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT DX512SEQ-FILE ASSIGN TO DX512SEQ ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS DX512SEQ-STATUS. SELECT DX512KSD-FILE ASSIGN TO DX512KSD ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS DX512KSD-PKEY-00001-00012 FILE STATUS IS DX512KSD-STATUS. ***************************************************************** DATA DIVISION. FILE SECTION. FD DX512SEQ-FILE DATA RECORD IS DX512SEQ-REC . 01 DX512SEQ-REC. 05 DX512SEQ-DATA-01 PIC X(00512). FD DX512KSD-FILE DATA RECORD IS DX512KSD-REC . 01 DX512KSD-REC. 05 DX512KSD-PKEY-00001-00012 PIC X(00012). 05 DX512KSD-DATA-00013-00500 PIC X(00500). ***************************************************************** * This program was created with the SYSMASK1.TXT file as input. * * The SYSMASK1 provides for the sequential reading of the input * * file and the sequential writing of the output 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. This is a sequential load process. * * * * If the key field is not in sequence then refer to SYSMASK2 * * to provide for a random add or update of the indexed file. * * * * This program mask will have the ASCII/EBCDIC table inserted * * for use by the /TRANSLATE function of SimoZAPS. * * * * For additional information contact SimoTime Technologies. * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * ***************************************************************** WORKING-STORAGE SECTION. 01 SIM-TITLE. 05 T1 pic X(11) value '* SEQKSDC1 '. 05 T2 pic X(34) value 'Convert RSEQ-512 to KSDS-512 '. 05 T3 pic X(10) value ' v12.04.05'. 05 T4 pic X(24) value ' helpdesk@simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* SEQKSDC1 '. 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 DX512SEQ-STATUS. 05 DX512SEQ-STATUS-L pic X. 05 DX512SEQ-STATUS-R pic X. 01 DX512SEQ-EOF pic X value 'N'. 01 DX512SEQ-OPEN-FLAG pic X value 'C'. 01 DX512KSD-STATUS. 05 DX512KSD-STATUS-L pic X. 05 DX512KSD-STATUS-R pic X. 01 DX512KSD-EOF pic X value 'N'. 01 DX512KSD-OPEN-FLAG pic X value 'C'. 01 DX512SEQ-LRECL pic 9(5) value 00512. 01 DX512KSD-LRECL pic 9(5) value 00512. 01 DX512SEQ-LRECL-MAX 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 '* SEQKSDC1 '. 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 'SEQKSDC1'. 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 RSEQ-512 to KSDS-512 '. 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 DX512SEQ-TOTAL. 05 DX512SEQ-RDR pic 9(9) value 0. 05 filler pic X(3) value ' - '. 05 filler pic X(23) value 'Line count for DX512SEQ'. 01 DX512KSD-TOTAL. 05 DX512KSD-ADD pic 9(9) value 0. 05 filler pic X(3) value ' - '. 05 filler pic X(23) value 'Line count for DX512KSD'. ***************************************************************** 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 DX512SEQ-OPEN perform DX512KSD-OPEN perform until DX512SEQ-STATUS not = '00' perform DX512SEQ-READ if DX512SEQ-STATUS = '00' add 1 to DX512SEQ-RDR perform BUILD-OUTPUT-RECORD perform DX512KSD-WRITE if DX512KSD-STATUS = '00' add 1 to DX512KSD-ADD end-if end-if end-perform move DX512SEQ-TOTAL to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move DX512KSD-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 DX512KSD-CLOSE perform DX512SEQ-CLOSE GOBACK. ***************************************************************** BUILD-OUTPUT-RECORD. * TransCOPY... move DX512SEQ-REC(00001:00512) to DX512KSD-REC(00001:00512) exit. ***************************************************************** * I/O Routines for the INPUT File... * ***************************************************************** DX512SEQ-CLOSE. add 8 to ZERO giving APPL-RESULT. close DX512SEQ-FILE if DX512SEQ-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 DX512SEQ' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move DX512SEQ-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if exit. *---------------------------------------------------------------* DX512SEQ-READ. read DX512SEQ-FILE if DX512SEQ-STATUS = '00' subtract APPL-RESULT from APPL-RESULT else if DX512SEQ-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 DX512SEQ-EOF else move 'READ Failure with DX512SEQ' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move DX512SEQ-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if end-if exit. *---------------------------------------------------------------* DX512SEQ-OPEN. add 8 to ZERO giving APPL-RESULT. open input DX512SEQ-FILE if DX512SEQ-STATUS = '00' subtract APPL-RESULT from APPL-RESULT move 'O' to DX512SEQ-OPEN-FLAG else add 12 to ZERO giving APPL-RESULT end-if if APPL-AOK CONTINUE else move 'OPEN Failure with DX512SEQ' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move DX512SEQ-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if exit. ***************************************************************** * I/O Routines for the OUTPUT File... * ***************************************************************** DX512KSD-WRITE. if DX512KSD-OPEN-FLAG = 'C' perform DX512KSD-OPEN end-if write DX512KSD-REC if DX512KSD-STATUS = '00' subtract APPL-RESULT from APPL-RESULT else if DX512KSD-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 DX512KSD' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move DX512KSD-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if exit. *---------------------------------------------------------------* DX512KSD-OPEN. add 8 to ZERO giving APPL-RESULT. open OUTPUT DX512KSD-FILE if DX512KSD-STATUS = '00' subtract APPL-RESULT from APPL-RESULT move 'O' to DX512KSD-OPEN-FLAG else add 12 to ZERO giving APPL-RESULT end-if if APPL-AOK CONTINUE else move 'OPEN Failure with DX512KSD' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move DX512KSD-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if exit. *---------------------------------------------------------------* DX512KSD-CLOSE. add 8 to ZERO giving APPL-RESULT. close DX512KSD-FILE if DX512KSD-STATUS = '00' subtract APPL-RESULT from APPL-RESULT move 'C' to DX512KSD-OPEN-FLAG else add 12 to ZERO giving APPL-RESULT end-if if APPL-AOK CONTINUE else move 'CLOSE Failure with DX512KSD' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move DX512KSD-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: 2014-05-06 Generation Time: 11:19:55:04 * *****************************************************************
This is an example of how a COBOL program can read a record sequential (RSEQ) file and write a VSAM Keyed-Sequential-Data-Set (KSDS) using sequential processing techniques. This document may be used 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.
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.
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.
The following links may be to the current server or to the Internet.
Explore the Principles of Data File Conversion. This link includes guidelines for defining requirements and determining the scope of effort for a data conversion effort.
Explore How to Generate a Data File Convert Program using simple specification statements in a Process Control File (PCF). This link to the User Guide includes the information necessary to create a Process Control File and generate the COBOL programs that will do the actual data file conversion. The User Guide contains a list of the PCF statements that are used for the data file convert process.
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.
Explore The File Status Return Codes that are used to interpret the results of accessing VSAM data sets and/or QSAM files.
The following links will require an internet connect.
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 Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.
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.
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 |
Sequential to KSDS, COBOL Source for Sequential Add |
Copyright © 1987-2025 SimoTime Technologies and Services All Rights Reserved |
When technology complements business |
http://www.simotime.com |