|
|||||
|
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 (refer to http://www.microfocus.com).
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 Pagessection of this document.
Note: The source code for this example is available from the SimoTime Library under Download Directory at http://www.simotime.com
The following is a flowchart of the COBOL calling COBOL example.
|
The JCL member for running the application. | ||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||
|
|
|
|
|
Call QSAMIOA1 from QSAMIOC1 and on return from call display info from pass area. | ||||||||||||||||||||||||||||||||
|
|
|
|
|||||||||||||||||||||||||||||||||||
|
|
|
|
|||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|||||||||||||||||||||||||||||||||
|
The 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 "calling COBOL program" needs the following data structure (PASS-AREA) to be defined in the WORKING-STORAGE section.
WORKING-STORAGE SECTION.
*****************************************************************
* Data Structure used for calling QSAMIOA1.
* The calling statement is as follows...
* CALL 'QSAMIOA1' USING PASS-AREA
*
*****************************************************************
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).
The source code listings for both the "calling COBOL program" and the "called Assembler program" are included within this document.
The 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 Enterprises, LLC * //* (C) Copyright 1987-2003 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 Enterprises //* 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* //* * * //* * * //* * * ************ //* * ************* DISPLAY * //* * ****console* //* * //* * //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //QSAMIOX1 EXEC PGM=QSAMIOC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //QSAMFILE DD DSN=SIMOTIME.DATA.QSAM0080,DISP=SHR //*
This 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 ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2003 SimoTime Enterprises, LLC. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only does not imply publication or *
* disclosure. This software contains confidential information *
* and trade secrets of SimoTime Enterprises, LLC. No part of *
* this program or publication may be reproduced, transmitted, *
* transcribed, stored in a retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of: *
* *
* SimoTime Enterprises *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Enterprises, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
* *
*****************************************************************
* This program is provided by SimoTime Enterprises *
* 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 'v1.1.00 '.
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-2003 '.
05 C3 pic X(28) value ' SimoTime Enterprises, LLC '.
05 C4 pic X(20) value ' All Rights Reserved'.
01 SIM-THANKS-01.
05 C1 pic X(11) value '* QSAMIOC1 '.
05 C2 pic X(32) value 'Thank you for using this sample '.
05 C3 pic X(32) value 'by SimoTime Enterprises, LLC '.
05 C4 pic X(04) value ' '.
01 SIM-THANKS-02.
05 C1 pic X(11) value '* QSAMIOC1 '.
05 C2 pic X(32) value 'Please send comments or suggesti'.
05 C3 pic X(32) value 'ons to helpdesk@simotime.com '.
05 C4 pic X(04) value ' '.
*****************************************************************
01 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).
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 REQUEST-KEY pic X(6).
01 END-OF-FILE pic X(3) value 'NO '.
01 OPERATOR-MESSAGE pic X(48).
*****************************************************************
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
move SPACES to OPERATOR-MESSAGE
exit.
Z-POST-COPYRIGHT.
display SIM-TITLE upon console
display SIM-COPYRIGHT upon console
exit.
*****************************************************************
Z-THANK-YOU.
display SIM-THANKS-01 upon console
display SIM-THANKS-02 upon console
exit.
This program (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
***********************************************************************
* This program is provided by: *
* SimoTime Enterprises, LLC *
* (C) Copyright 1987-2003 All Rights Reserved *
* *
* Web Site URL: http://www.simotime.com *
* e-mail: helpdesk@simotime.com *
***********************************************************************
* *
* Created: 1987/06/01, Simmons, Larry *
* Changed: 1987/06/01, Simmons, no changes to date... *
* *
***********************************************************************
* *
* This program will run an 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
*
***********************************************************************
SAVER1 DC F'0'
GET DC CL8'GET '
OPEN DC CL8'OPEN '
CLOSE DC CL8'CLOSE '
*
END
The purpose of this document is to assist as a tutorial for new assembler programmers or as a quick reference for experienced programmers. The samples focus on the coding techniques of the individual instructions. As always, it is the programmer's responsibility to thoroughly test all programs.
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.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.
You may download this example at http://www.simotime.com/sim4dzip.htm#AsmQSAMIORoutine or view the complete list of SimoTime Examples at http://www.simotime.com/sim4dzip.htm.
The following is a list of programs that take different approaches to accessing QSAM or Sequential files.
| Program | Description |
| cblqsm01 | This program suite uses a mainline program that calls a COBOL I/O program that reads a QSAM or Sequential file. If the call results in a Zero return code the record is display to the screen or SYSOUT. Mainframe ZOS JCL members and Windows Command Files are provided for job execution. |
| cblqsm03 | This program suite provides an example of how a single COBOL program is used to access a QSAM or Sequential file. The COBOL programs are written using COBOL/2 dialect but also works with COBOL for MVS and COBOL/370. |
| qsamio01 | This program suite provides an example of how a mainline COBOL program calls a mainframe Assembler I/O routine to access a QSAM sequential file. The COBOL program is written using the COBOL/2 dialect but also work 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. |
Note: You must be attached to the Internet to download a Z-Pack or view the list.
To create the QSAM file used by this example refer to The VSAM-QSAM Connection, Common Utility Programs section.
This link will provide an example of a COBOL program calling a COBOL Program to access a QSAM or Sequential file. The COBOL program is written using the COBOL/2 dialect but also work with COBOL for MVS and COBOL/370.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
Are you working with files on the mainframe and files downloaded to the PC? Then take a look at the Table of ASCII and EBCDIC values.
Check out The Assembler Connection for more examples of mainframe Assembler coding techniques and sample code.
Check out The COBOL Connection for more examples of mainframe COBOL coding techniques and sample code.
Check out The JCL Connection for more mainframe JCL examples.
Check out The SimoTime Library for a wide range of topics for Programmers, Project Managers and Software Developers.
To review all the information available on this site start at The SimoTime Home Page .
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
Founded in 1987, SimoTime Enterprises is a privately owned, Limited Liability Corporation located in Novato, California. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2008 SimoTime Enterprises, LLC All Rights Reserved |
| When technology complements business |