Sequential File Access A Single COBOL Program for QSAM I/O |
The SimoTime Home Page |
This suite of programs provides an example of how a single mainline COBOL program accesses a QSAM or Sequential file. The COBOL program is written using COBOL/2 dialect but also works with COBOL for MVS and COBOL/370. A JCL member is provided to run the job as an MVS batch job on an IBM mainframe or as a project with Micro Focus Mainframe Express (MFE) running on a PC with Windows.
This example may serve as a tutorial for programmers that are new to COBOL or QSAM-Sequential file processing. This example may also be used as a reference for experienced programmers.
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
The following is the mainframe JCL (CBLQSMJ3.jcl) required to run as an MVS batch job on the mainframe. This will also run on the PC with Micro Focus Mainframe Express. The coding technique is used with the expectation the JCL would be used as a stand alone procedure.
//CBLQSMJ3 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //* ******************************************************************* //* CBLQSMJ3.JCL - a JCL Member for Batch Job Processing * //* This program is provided by SimoTime Technologies * //* (C) Copyright 1987-2019 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - COBOL for QSAM or Sequential file I/O //* Author - SimoTime Technologies //* Date - January 01, 1997 //* //* This set of programs illustrates the use of a COBOL program to //* do QSAM or Sequential file I/O. The purpose is to show the //* processing of a QSAM or Sequential file. //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express. //* //* ************ //* * CBLQSMJ3 * //* ********jcl* //* * //* * //* ************ ************ ************ //* * QSAM0080 *-----* CBLQSMC3 *-----* Console * //* *******data* ********cbl* ******dsply* //* * //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 of 1, This is a single step job. //* //CBLVSMX1 EXEC PGM=CBLQSMC3 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //QSAM0080 DD DSN=SIMOTIME.DATA.QSAM0080,DISP=SHR //SYSOUT DD SYSOUT=* //*
The following is the Windows Command (CBLQSME3.cmd) required to run as a batch job on a Windows System with Micro Focus.
@echo OFF rem * ******************************************************************* rem * CBLQSME3.CMD - a Windows Command File * rem * This program is provided by SimoTime Technologies * rem * (C) Copyright 1987-2019 All Rights Reserved * rem * Web Site URL: http://www.simotime.com * rem * e-mail: helpdesk@simotime.com * rem * ******************************************************************* rem * rem * Text - COBOL to access QSAM and display records to console. rem * Author - SimoTime Enterprises rem * Date - January 01, 2006 rem * rem * This single COBOL program will read and display the contents rem * of a sequential file of 80-byte, fixed-length records. rem * rem * ******************************************************************** rem * Step 1 of 2, Set the global environment variables... rem * setlocal call ..\Env1BASE %CmdName% if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG set CmdName=CblQsmE3 rem * call SimoNOTE "*******************************************************%CmdName%" call SimoNOTE "Starting JobName %CmdName%" rem * ******************************************************************** rem * Step 2 of 2, Execute the sample program... rem * set QSAM0080=%BaseLib1%\DATA\Asc1\SIMOTIME.DATA.QSAM0080.DAT rem * run CBLQSMC3 if not "%ERRORLEVEL%" == "0" set JobStatus=0010 if not "%JobStatus%" == "0000" goto :EojNOK :EojAOK call SimoNOTE "Finished CmdName %CmdName%, Job Status is %JobStatus%" goto :End :EojNOK call SimoNOTE "ABENDING CmdName %CmdName%, Job Status is %JobStatus%" echo %DATE% - %TIME% Starting User ABEND Processing...>>%SYSLOG% set >>%SYSLOG% echo %DATE% - %TIME% Complete User ABEND Processing...>>%SYSLOG% goto :End :End call SimoNOTE "Conclude SysOut is %SYSOUT%" if not "%1" == "nopause" pause exit /B %JobStatus%
This program (CBLQSMC3.cbl) was written to be used as a teaching and learning aid. It is a simple program that reads a sequential file and displays the records. Notice the "Z-DISPLAY-IO-STATUS" routine to display the file status code.
IDENTIFICATION DIVISION. PROGRAM-ID. CBLQSMC3. AUTHOR. SIMOTIME TECHNOLOGIES. ***************************************************************** * Copyright (C) 1987-2019 SimoTime Technologies. * * * * All rights reserved. Unpublished, all rights reserved under * * copyright law and international treaty. Use of a copyright * * notice is precautionary only and does not imply publication * * or disclosure. * * * * Permission to use, copy, modify and distribute this software * * for any non-commercial purpose and without fee is hereby * * granted, provided the SimoTime copyright notice appear on all * * copies of the software. The SimoTime name or Logo may not be * * used in any advertising or publicity pertaining to the use * * of the software without the written permission of SimoTime * * Technologies. * * * * Permission to use, copy, modify and distribute this software * * for any commercial purpose requires a fee to be paid to * * SimoTime Technologies. Once the fee is received by SimoTime * * the latest version of the software will be delivered and a * * license will be granted for use within an enterprise, * * provided the SimoTime copyright notice appear on all copies * * of the software. The SimoTime name or Logo may not be used * * in any advertising or publicity pertaining to the use of the * * software without the written permission of SimoTime * * Technologies. * * * * SimoTime Technologies makes no warranty or representations * * about the suitability of the software for any purpose. It is * * provided "AS IS" without any expressed or implied warranty, * * including the implied warranties of merchantability, fitness * * for a particular purpose and non-infringement. SimoTime * * Technologies shall not be liable for any direct, indirect, * * special or consequential damages resulting from the loss of * * use, data or projects, whether in an action of contract or * * tort, arising out of or in connection with the use or * * performance of this software * * * * SimoTime Technologies * * 15 Carnoustie Drive * * Novato, CA 94949-5849 * * 415.883.6565 * * * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the Government is subject * * to restrictions as set forth in subparagraph (c)(1)(ii) of * * the Rights in Technical Data and Computer Software clause at * * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of * * Commercial Computer Software - Restricted Rights at 48 * * CFR 52.227-19, as applicable. Contact SimoTime Technologies, * * 15 Carnoustie Drive, Novato, CA 94949-5849. * * * ***************************************************************** * This program is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * * * ***************************************************************** * ***************************************************************** * Source Member: CBLQSMC3.CBL ***************************************************************** * * CBLQSMC3 -This is an example of a single COBOL program that * accesses a QSAM or Sequential File. * * EXECUTION OR CALLING PROTOCOL * ----------------------------- * Use standard mainframe JCL to EXECUTE or ANIMATE. * * DESCRIPTION * ----------- * This program uses standard COBOL syntax to access a QSAM * or Sequential File. * * ************ * * CBLQSMJ3 * * ********jcl* * * * * * ************ ************ ************ * * QSAM0080 *-----* CBLQSMC3 *-----* CONSOLE * * *******qsam* ********cbl* ******dsply* * * * REQUIREMENTS * ------------ * This program was originally written to conform to the IBM, * COBOL II dialect but will work with COBOL for MVS or COBOL/390. * This program may also be executed on the PC using Mainframe * Express (MFE) from Micro Focus. * ***************************************************************** * * MAINTENANCE * ----------- * 1997/02/27 Simmons, Created program. * 1997/02/27 Simmons, No changes to date. * 1998/11/10 Simmons, Modified to conform to COBOL II. * 1998/11/21 Simmons, Added code to display file status when an * I/O error occurs. * ***************************************************************** * ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT QSAM0080-FILE ASSIGN to QSAM0080 ORGANIZATION is SEQUENTIAL ACCESS MODE is SEQUENTIAL FILE STATUS is QSAM0080-STATUS. * DATA DIVISION. FILE SECTION. FD QSAM0080-FILE. 01 QSAM0080-RECORD. 05 QSAM0080-KEY pic X(6). 05 QSAM0080-DATA pic X(74). WORKING-STORAGE SECTION. ***************************************************************** * Data-structure for Title and Copyright... * ------------------------------------------------------------ 01 SIM-TITLE. 05 T1 pic X(11) value '* CBLQSMC3 '. 05 T2 pic X(34) value 'Sample, COBOL for QSAM I/O '. 05 T3 pic X(10) value ' v03.01.30'. 05 T4 pic X(24) value ' http://www.simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* CBLQSMC3 '. 05 C2 pic X(20) value 'Copyright 1987-2019 '. 05 C3 pic X(28) value ' SimoTime Technologies '. 05 C4 pic X(20) value ' All Rights Reserved'. 01 SIM-THANKS-01. 05 C1 pic X(11) value '* CBLQSMC3 '. 05 C2 pic X(32) value 'Thank you for using this program'. 05 C3 pic X(32) value ' provided from SimoTime Technolo'. 05 C4 pic X(04) value 'gies'. 01 SIM-THANKS-02. 05 C1 pic X(11) value '* CBLQSMC3 '. 05 C2 pic X(32) value 'Please send all inquires or sugg'. 05 C3 pic X(32) value 'estions to the helpdesk@simotime'. 05 C4 pic X(04) value '.com'. ***************************************************************** 01 QSAM0080-STATUS. 05 QSAM0080-STAT1 pic X. 05 QSAM0080-STAT2 pic X. ***************************************************************** * 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. ***************************************************************** * Buffer used for posting messages to the console. ***************************************************************** 01 MESSAGE-BUFFER. 05 MESSAGE-HEADER pic X(11) value '* CBLVSMC1 '. 05 MESSAGE-TEXT. 10 MESSAGE-TEXT-1 pic X(68) value SPACES. 10 MESSAGE-TEXT-2 pic X(188) value SPACES. ***************************************************************** 01 APPL-RESULT pic S9(9) comp. 88 APPL-AOK value 0. 88 APPL-EOF value 16. 01 END-OF-FILE pic X(3) value 'NO '. ***************************************************************** PROCEDURE DIVISION. perform Z-POST-COPYRIGHT. perform QSAM0080-OPEN. perform until END-OF-FILE = 'YES' if END-OF-FILE = 'NO ' perform QSAM0080-GET-NEXT if END-OF-FILE = 'NO ' display QSAM0080-RECORD end-if end-if end-perform. perform QSAM0080-CLOSE. perform Z-THANK-YOU. GOBACK. ***************************************************************** * I/O routines to access a QSAM or Sequential file... * ***************************************************************** QSAM0080-GET-NEXT. read QSAM0080-FILE. if QSAM0080-STATUS = '00' subtract APPL-RESULT from APPL-RESULT else if QSAM0080-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 'YES' to END-OF-FILE else move '* QSAM0080-FAILURE-GET-!!!' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move QSAM0080-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if end-if exit. *---------------------------------------------------------------* QSAM0080-OPEN. add 8 to ZERO giving APPL-RESULT. open input QSAM0080-FILE if QSAM0080-STATUS = '00' subtract APPL-RESULT from APPL-RESULT else add 12 to ZERO giving APPL-RESULT end-if if APPL-AOK CONTINUE else move 'QSAM0080-FAILURE-OPEN-!!!' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move QSAM0080-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if exit. *---------------------------------------------------------------* QSAM0080-CLOSE. add 8 to ZERO giving APPL-RESULT. close QSAM0080-FILE if QSAM0080-STATUS = '00' subtract APPL-RESULT from APPL-RESULT else add 12 to ZERO giving APPL-RESULT end-if if APPL-AOK CONTINUE else move 'QSAM0080-FAILURE-CLOSE-!!!' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move QSAM0080-STATUS to IO-STATUS perform Z-DISPLAY-IO-STATUS perform Z-ABEND-PROGRAM end-if exit. ***************************************************************** * The following Z-Routines perform administrative functions * for this program. ***************************************************************** Z-ABEND-PROGRAM. if MESSAGE-TEXT not = SPACES perform Z-DISPLAY-MESSAGE-TEXT end-if move 'IS ABENDING !' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT add 12 to ZERO giving RETURN-CODE STOP RUN. * 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. ***************************************************************** * Display CONSOLE messages... * ***************************************************************** Z-DISPLAY-MESSAGE-TEXT. if MESSAGE-TEXT-2 = SPACES display MESSAGE-BUFFER(1:79) upon console else display MESSAGE-BUFFER upon console end-if move all SPACES to MESSAGE-TEXT exit. *---------------------------------------------------------------* Z-POST-COPYRIGHT. display SIM-TITLE display SIM-COPYRIGHT exit. ***************************************************************** Z-THANK-YOU. display SIM-THANKS-01 display SIM-THANKS-02 exit. ***************************************************************** * This example is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * *****************************************************************
This suite of programs provides an example of how a single mainline COBOL program accesses a QSAM or Sequential file. This document may be used to assist as a tutorial for new programmers or as a quick reference for experienced programmers.
In the world of programming there are many ways to solve a problem. This documentation and software were developed and tested on systems that are configured for a SIMOTIME environment based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be needed to execute the jobs and programs when transferred to a system of a different architecture or configuration.
SIMOTIME Services has experience in moving or sharing data or application processing across a variety of systems. For additional information about SIMOTIME Services or Technologies please contact us using the information in the Contact or Feedback section of this document.
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.
Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the icon.
Explore QSAM or Sequential File Access using a COBOL Program that calls a COBOL program to do the file I/O to read a QSAM or Sequential file and displays information to SYSOUT. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370.
Explore QSAM or Sequential File Access using a COBOL Program that calls an Assembler program to do the file I/O to read a QSAM or Sequential file and displays information to SYSOUT. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370.
Explore the JCL Connection for more examples of JCL functionality with programming techniques and sample code.
Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.
Explore An Enterprise System Model that describes and demonstrates how Applications that were running on a Mainframe System and non-relational data that was located on the Mainframe System were copied and deployed in a Microsoft Windows environment with Micro Focus Enterprise Server.
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.
This suite of programs and documentation is available to download for review and evaluation purposes. Other uses will require a SimoTime Software License. Link to an Evaluation zPAK Option that includes the program members, documentation and control files.
A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection
Explore The Micro Focus Web Site for more information about products (including Micro Focus COBOL) and services available from Micro Focus. This link requires an Internet Connection.
Explore the 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 |
COBOL Accessing a QSAM or Sequential File |
Copyright © 1987-2025 SimoTime Technologies and Services All Rights Reserved |
When technology complements business |
http://www.simotime.com |