Assembler I/O Routine COBOL calls Assembler, QSAM Access |
The SimoTime Home Page |
This suite of programs provides an example of how a mainline COBOL program calls a mainframe assembler (HLASM) I/O routine to access a QSAM file. The file is a flat, sequential file. The COBOL program is written using COBOL/2 dialect but also works with COBOL for MVS and COBOL/370. The assembler IO routine is written in IBM Mainframe Assembler, it will compile using Assembler/H or HLASM. 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.
Another example of accessing QSAM files that uses a called COBOL I/O program is also provided. One of the differences between the COBOL I/O member and the Assembler I/O member is the COBOL module requires the record length to be pre-defined. This would require a separate COBOL I/O member for each file with a different record length. The Assembler I/O member will do an OPEN of a file and the record-length is returned in the DCB (Data Control Block). Since assembler has access to the DCB this information is extracted and returned to the calling COBOL program in the Pass-Area. This capability allows one Assembler I/O member to access sequential files of various record lengths. In this example the calling COBOL program only has a data buffer of 4,096 bytes. Therefore, this is an arbitrary limit for the record size the called Assembler I/O member is allowed to access. This arbitrary limit may be increased.
This program may serve as a tutorial for programmers that are new to COBOL, 370 Assembler or QSAM and as a reference for experienced programmers. Additional information is provided in the Downloads and Links to Similar Pages section of this document.
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 a flowchart of a sample job that executes a COBOL program that calls an Assembler program to access a sequential file.
Color Associations: The The Call InterfaceThe following summarizes the items needed for the calling COBOL program (QSAMIOC1) to call the Assembler program (QSAMIOA1). The "calling COBOL program" contains the following statement to make the call to the "called Assembler program". CALL 'QSAMIOA1' USING PASS-AREA The source code listings for both the Caller COBOL program and the Called Assembler I/O routine are included within this document. COBOL Copy File, Pass Area StructureThe following COBOL copy file(QSAMIOB1.cpy) is used in the WORKING-STORAGE section of the Caller program to define the data structure for the pass area that will be used by the Caller and Called programs. ***************************************************************** * QSAMIOB1.CPY - a COBOL Copy File * * The Pass Area Structure for calling QSAMIOA1 * * Copyright (C) 1987-2019 SimoTime Technologies * * All Rights Reserved * * Provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * ***************************************************************** * 01 PASS-AREA. 05 PASS-REQUEST pic X(8). 05 PASS-RESULT pic S9(9) comp. 88 NORMAL-RESULT value 0. 88 COBOL-RESULT-SAME value 8. 88 EOF-RESULT value 16. 05 PASS-LRECL pic S9(4) comp. 05 PASS-DATA pic X(4096). * *** QSAMIOB1 - End-of-Copy File - - - - - - - - - - - QSAMIOB1 * ***************************************************************** * The JCL MemberThe following is the mainframe JCL (QSAMIOJ1.jcl) required to run as an MVS job on the mainframe. This job will also run with Micro Focus Mainframe Express. The coding technique is used with the expectation the JCL would be used as a stand alone procedure. //QSAMIOJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1, // COND=(0,LT) //* ******************************************************************* //* 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 calling 370 Assembler for QSAM File I/O. //* Author - SimoTime Technologies //* Date - January 01, 1987 //* //* This set of programs illustrate the use of COBOL calling a 370 //* assembler program to do QSAM sequential 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. //* //* ************ //* * QSAMIOJ1 * //* ********jcl* //* * //* ************ ************ //* * QSAMIOC1 ************call**** QSAMIOA1 * //* ********cbl* * ********asm* //* * * * //* * * * //* * * ************ //* * * * QSAMFILE * //* * * *******data* //* * * //* * * //* * * ************ //* * ************* SYSOUT * //* * ****console* //* * //* * //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 of 1 This is a single step job. //* //QSAMIOX1 EXEC PGM=QSAMIOC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //QSAMFILE DD DSN=SIMOTIME.DATA.QSAM0080,DISP=SHR //* The Mainline COBOL ProgramThis program (QSAMIOC1.cbl) was written to be used as a teaching and learning aid. The displays are not required and the parameters use full words. The displays would probably be removed and the request codes would probably be a single character in a production environment. IDENTIFICATION DIVISION. PROGRAM-ID. QSAMIOC1. 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: QSAMIOC1.CBL * Calls to: CBLASMA1 ***************************************************************** * * QSAMIOC1 - Call QSAMIOA1 to access a QSAM Sequential File * * EXECUTION or CALLING PROTOCOL * ----------------------------- * Use standard JCL to EXECUTE or ANIMATE. * * DESCRIPTION * ----------- * This program will call a 370 Assembler routine to access a * QSAM Sequential File. * * ************ * * QSAMIOJ1 * * ********jcl* * * * * * ************ ************ * * QSAMIOC1 *-----* CONSOLE * * ********cbl* ******dsply* * * * * * ************ ************ * * QSAMFILE *-----* QSAMIOA1 * * *******vsam* ********mlc* * * ***************************************************************** * * MAINTENANCE * ----------- * 1997/02/27 Simmons, Created program. * 1997/02/27 Simmons, No changes to date.. * ***************************************************************** * ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. ***************************************************************** * Data-structure for Title and Copyright... * ------------------------------------------------------------ 01 SIM-TITLE. 05 T1 pic X(11) value '* QSAMIOC1 '. 05 T2 pic X(34) value 'COBOL calls Assembler QSAM I/O '. 05 T3 pic X(10) value ' v03.01.24'. 05 T4 pic X(24) value ' http://www.simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* QSAMIOC1 '. 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 '* QSAMIOC1 '. 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 '* QSAMIOC1 '. 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 RECORD-SIZE-LIMIT pic 9(5) value 4096. 01 REQUEST-OPEN pic X(8) value 'OPEN '. 01 REQUEST-GET pic X(8) value 'GET '. 01 REQUEST-CLOSE pic X(8) value 'CLOSE '. 01 END-OF-FILE pic X(3) value 'NO '. 01 OPERATOR-MESSAGE pic X(48). COPY QSAMIOB1. ***************************************************************** PROCEDURE DIVISION. perform Z-POST-COPYRIGHT display '* QSAMIOC1 OPEN Request...' upon console. perform OPEN-THE-FILE. if PASS-LRECL > RECORD-SIZE-LIMIT move '* QSAMIOC1 Record Length exceeds limit' to OPERATOR-MESSAGE perform Z-ABEND-MESSAGE add 16 to ZERO giving RETURN-CODE STOP RUN end-if display '* QSAMIOC1 OPEN Complete...' upon console. perform until END-OF-FILE = 'YES' or PASS-RESULT not = ZERO if END-OF-FILE = 'NO ' move REQUEST-GET to PASS-REQUEST perform GET-NEXT-RECORD if END-OF-FILE = 'NO ' display PASS-DATA(1:PASS-LRECL) upon console end-if end-if end-perform. perform CLOSE-THE-FILE. display '* QSAMIOC1 has COMPLETED...' upon console perform Z-THANK-YOU. GOBACK. ***************************************************************** GET-NEXT-RECORD. call 'QSAMIOA1' using PASS-AREA. if NORMAL-RESULT CONTINUE else if EOF-RESULT move 'YES' to END-OF-FILE else move '* QSAMIOC1, QKSD001F, FAILURE, GET...' to OPERATOR-MESSAGE perform Z-ABEND-MESSAGE STOP RUN end-if end-if exit. OPEN-THE-FILE. add 8 to ZERO giving PASS-RESULT. move REQUEST-OPEN to PASS-REQUEST. call 'QSAMIOA1' using PASS-AREA. if NORMAL-RESULT CONTINUE else move '* QSAMIOC1, QKSD001F, FAILURE, OPEN...' to OPERATOR-MESSAGE perform Z-ABEND-MESSAGE add 12 to ZERO giving RETURN-CODE STOP RUN end-if exit. CLOSE-THE-FILE. add 8 to ZERO giving PASS-RESULT. move REQUEST-CLOSE to PASS-REQUEST. call 'QSAMIOA1' using PASS-AREA. if NORMAL-RESULT CONTINUE else move '* QSAMIOC1, QSAM0080, FAILURE, CLOSE...' to OPERATOR-MESSAGE perform Z-ABEND-MESSAGE add 12 to ZERO giving RETURN-CODE STOP RUN end-if exit. ***************************************************************** * The following Z-Routines perform administrative functions * * for this program. * ***************************************************************** Z-ABEND-MESSAGE. if OPERATOR-MESSAGE not = SPACES perform Z-DISPLAY-CONSOLE-MESSAGE else move '* QSAMIOC1 IS ABENDING...' to OPERATOR-MESSAGE perform Z-DISPLAY-CONSOLE-MESSAGE end-if exit. Z-DISPLAY-CONSOLE-MESSAGE. display OPERATOR-MESSAGE upon console display OPERATOR-MESSAGE move SPACES to OPERATOR-MESSAGE 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 * ***************************************************************** The Assembler I/O RoutineThis program (QSAMIOA1.mlc) does not provide much visual information when it is executed on the mainframe. The real value to this program is when it is animated using the 370 Assembler Option of Mainframe Express provided by Micro Focus. It is possible to watch the actual execution of each individual instruction and to immediately see the results. QSAMIOA1 CSECT *********************************************************************** * QSAMIOA1.MLC - This is an HLASM Program * * Provided by SimoTime Technologies * * (C) Copyright 1987-2019 All Rights Reserved * * Web Site URL: http://www.simotime.com * * e-mail: helpdesk@simotime.com * *********************************************************************** * * * Created: 1987/06/01, Simmons, Larry * * Changed: 1990/06/01, Simmons, added comments for Micro Focus... * * * *********************************************************************** * * * This program will run on an IBM Mainframe using MVS or a PC using * * Micro Focus Mainframe Express, version 2.5 or later (MFE) with * * the Assembler Option. * * * * This program provides an example of an assembler I/O sub-routine * * that provides access to a QSAM or Sequential File. * * * * Using the Micro Focus Animation You can immediately see the results * * of each instruction execution. This is a very effective way to * * become familiar with how these techniques work. * * * *********************************************************************** * R0 EQU 0 R1 EQU 1 R2 EQU 2 R3 EQU 3 R4 EQU 4 R5 EQU 5 R6 EQU 6 R7 EQU 7 R8 EQU 8 R9 EQU 9 R10 EQU 10 R11 EQU 11 R12 EQU 12 R13 EQU 13 R14 EQU 14 R15 EQU 15 *********************************************************************** SAVE (14,12) BALR 12,0 USING *,12 * ST R1,SAVER1 * Save Register 1 L R8,0(,R1) * Get address of PASS-AREA * CLC 0(8,R8),GET * Is this an GET request... BE GETRTN * CLC 0(8,R8),OPEN * Is this an OPEN request... BE OPENRTN * CLC 0(8,R8),CLOSE * Is this an CLOSE request... BE CLOSERTN * LA R15,15 * Set return-code to 15 B RETURN Return to Calling program * *********************************************************************** OPENRTN EQU * OPEN (QSAMFILE,(INPUT)) LTR R15,R15 * Was OPEN successful ??? BNZ BADOPEN If not, then quit TM QSAMFILE+48,X'10' * Was OPEN successful ??? BZ BADOPEN If not, post error ST R15,8(,R8) * Set Return Field in Pass Area LA R9,QSAMFILE * Get Address of DCB using Reg-9 MVC 12(2,R8),82(R9) * Get Record length from DCB B RETURN * Return to Calling program * *********************************************************************** GETRTN EQU * L R1,SAVER1 L R3,0(R1) LA R3,14(,R3) * Get address of COBOL data buffer GET QSAMFILE,(R3) LTR R15,R15 * Is RETURN-CODE = 0 ??? BNZ BADGET If not, then post a message ST R15,8(,R8) Set user RETURN-CODE to ZERO LA R9,QSAMFILE * Get Address of DCB using Reg-9 MVC 12(2,R8),82(R9) * Get Record length from DCB B RETURN * *********************************************************************** CLOSERTN EQU * CLOSE (QSAMFILE) ST R15,8(,R8) * Set user RETURN-CODE... * *********************************************************************** RETURN EQU * SR 15,15 * Set user RETURN CODE to ZERO RETURN (14,12),RC=(15) * ERROR1 EQU * WTO '* QSAMIOA1, QSAMFILE - I/O ERROR' RETURN (14,12),,RC=1 * BADOPEN EQU * ST R15,8(,R8) * Set user RETURN-CODE... WTO '* QSAMIOA1 THE FILE OPEN FAILED...' L R15,8(,R8) RETURN (14,12),RC=(15) * BADGET EQU * ST R15,8(,R8) * Set user RETURN-CODE... WTO '* QSAMIOA1 THE FILE GET FAILED...' L R15,8(,R8) RETURN (14,12),RC=(15) * EODRTN EQU * WTO '* QSAMIOA1 THE END-OF-FILE HAS BEEN PROCESSED' LA R15,16 ST R15,8(,R8) * Set user RETURN-CODE... RETURN (14,12),RC=(15) * *********************************************************************** QSAMFILE DCB MACRF=G,EODAD=EODRTN,SYNAD=ERROR1, X DDNAME=QSAMFILE,DSORG=PS * *********************************************************************** SAVER1 DC F'0' GET DC CL8'GET ' OPEN DC CL8'OPEN ' CLOSE DC CL8'CLOSE ' * END SummaryThis suite of programs provides an example of how a mainline COBOL program calls a mainframe assembler (HLASM) I/O routine to access a QSAM 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.
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. Downloads and LinksThis 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. Current Server or Internet AccessThe 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 single COBOL Program 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 COBOL Connection for more examples of COBOL programming techniques and sample code. Explore the non-Relational Data Connection for more examples of accessing methodologies and coding techniques for Data Files and VSAM Data Sets. 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. Internet Access RequiredThe 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. Glossary of TermsExplore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers. Contact or FeedbackThis document was created and is maintained by SimoTime Technologies. If you have any questions, suggestions, comments or feedback please use the following contact information.
We appreciate hearing from you. Company OverviewSimoTime 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
|