|
|
Assembler
I/O Routine COBOL calls Assembler, VSAM Access http://www.simotime.com |
|
This suite of programs provides an example of how a mainline COBOL program calls a mainframe assembler (HLASM) I/O routine to access a VSAM data set. The VSAM data set is a Keyed-Sequential-Data-Set (KSDS). 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).
This program may serve as a tutorial for programmers that are new to COBOL, 370 Assembler or VSAM and as a reference for experienced programmers.
Note: The source code for this example is available from the SimoTime Library under Download Directory at http://www.simotime.com
The followiing is a flowchart of the COBOL calling COBOL example.
|
The JCL member for running the application. | ||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||
|
|
|
|
Call CBLASMA1 from CBLASMC1. On return from call display info from pass area. | |||||||||||||||||||||||
|
|
|
|
|||||||||||||||||||||||||
|
|
|
|
|||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
|
|
|
||||||||||||||||||||||||
|
The following summarizes the items needed for a "calling program" (CBLASMC1.CBL) to call a "called program" (CBLASMA1).
The "calling program" contains the following statement to make the call to the "called program".
CALL 'CBLASMA1' USING PASS-AREA
The "calling program" needs the following data structure (PASS-AREA) to be defined in the WORKING-STORAGE section.
WORKING-STORAGE SECTION.
*****************************************************************
* Data Structure used for calling CBLCBLC2.
* The calling statement is as follows...
* CALL 'CBLASMA1' 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-RECORD.
10 PASS-KEY pic X(6).
10 PASS-INFO pic X(74).
The source code listings for both the "calling program" and the "called program" are included within this document.
The following is the mainframe JCL (CBLASMJ1.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.
//CBLASMJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1, // COND=(0,LT) //* ******************************************************************* //* This program is provided by: * //* SimoTime Enterprises, LLC * //* (C) Copyright 1987-2010 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - COBOL calling 370 Assembler for VSAM I/O. //* Author - SimoTime Enterprises //* Date - January 01, 1997 //* //* This set of programs illustrate the use of COBOL calling a 370 //* assembler program to do VSAM sequential I/O. The purpose is to //* show the processing of a VSAM Keyed Sequential Data Set (KSDS). //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express. //* //* ************ //* * CBLASMJ1 * //* ********jcl* //* * //* ************ ************ //* * CBLASMC1 *****call*** CBLASMA1 * //* ********cbl* * ********asm* //* * * * //* * * * //* * * ************ //* * * * VKSD0080 * //* * * ********get* //* * * //* * * ************ //* * ********* DISPLAY * //* * ************ //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Instream PROC to execute the program. //* //CBLASMP1 PROC PROGNAME= //CBLASMX1 EXEC PGM=&PROGNAME;//STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //VKSD0080 DD DSN=SIMOTIME.DATA.VKSD0080,DISP=SHR // PEND //* //* ******************************************************************* //* Step 1 of 1 This is a single step job. //* // EXEC CBLASMP1,PROGNAME=CBLASMC1 //*
This program (CBLASMC1.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. CBLASMC1.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2010 SimoTime Enterprises, LLC. *
* *
* 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 *
* Enterprises. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Enterprises. 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 *
* Enterprises. *
* *
* 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 *
* *
* 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: CBLASMC1.CBL
* Calls to: CBLASMA1
*****************************************************************
*
* CBLASMC1 - Call CBLASMA1 to access a VSAM Keyed Sequential
* Data Set (KSDS).
*
* EXECUTION or CALLING PROTOCOL
* -----------------------------
* Use standard JCL to EXECUTE or ANIMATE.
*
* DESCRIPTION
* -----------
* This program will call a 370 Assembler routine to access a
* VSAM Keyed Sequential Data Set (KSDS).
*
* ************
* * CBLASMJ1 *
* ********jcl*
* *
* *
* ************ ************
* * CBLASMC1 *-----* CONSOLE *
* ********cbl* ******dsply*
* *
* *
* ************ ************
* * VKSD0080 *-----* CBLASMA1 *
* *******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 '* CBLASMC1 '.
05 T2 pic X(34) value 'Sample, COBOL calls Assembler 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 '* CBLASMC1 '.
05 C2 pic X(20) value 'Copyright 1987-2010 '.
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 '* CBLASMC1 '.
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 '* CBLASMC1 '.
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-RECORD.
10 PASS-KEY pic X(6).
10 PASS-INFO pic X(74).
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 '* CBLASMC1 OPEN Request...' upon console.
perform OPEN-THE-FILE.
display '* CBLASMC1 OPEN Complete...' upon console.
perform until END-OF-FILE = 'YES'
if END-OF-FILE = 'NO '
move REQUEST-GET to PASS-REQUEST
move REQUEST-KEY to PASS-KEY
perform GET-NEXT-RECORD
if END-OF-FILE = 'NO '
display PASS-INFO upon console
end-if
end-if
end-perform.
perform CLOSE-THE-FILE.
display '* CBLASMC1 has COMPLETED...' upon console
perform Z-THANK-YOU.
GOBACK.
*****************************************************************
GET-NEXT-RECORD.
call 'CBLASMA1' using PASS-AREA.
if NORMAL-RESULT
CONTINUE
else
if EOF-RESULT
move 'YES' to END-OF-FILE
else
move '* CBLASMC1, 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 'CBLASMA1' using PASS-AREA.
if NORMAL-RESULT
CONTINUE
else
move '* CBLASMC1, 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 'CBLASMA1' using PASS-AREA.
if NORMAL-RESULT
CONTINUE
else
move '* CBLASMA1, QKSD001F, 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 '* CBLASMC1 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 example is provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
This program (CBLASMA1.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.
CBLASMA1 CSECT
***********************************************************************
* This program is provided by: *
* SimoTime Enterprises, LLC *
* (C) Copyright 1987-2010 All Rights Reserved *
* *
* Web Site URL: http://www.simotime.com *
* e-mail: helpdesk@simotime.com *
***********************************************************************
* *
* Created: 1993/06/01, Simmons *
* Changed: 1993/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 VSAM Keyed-Sequential-Data-Set (KSDS). *
* *
* 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. *
* *
***********************************************************************
* CBLASMA1, This program will read a KSDS, VSAM file sequentially. *
* *
* *
* From To Length Description *
* 1 6 6 Primary Key *
* 7 7 1 Space *
* 8 17 10 Alpha-Numeric "RECORD nn" *
* 18 18 1 Space *
* 19 22 4 Alpha-Numeric "KSDS" *
* 23 23 1 Space *
* 24 30 7 Alpha-Numeric "xxxxxxx" where x = A-Z *
* 31 50 20 Secondary-Key "CONSONANT " *
* "VOWEL " *
* "VOWEL/CONSONANT " *
* 51 80 30 Alpha-Numeric "xxx..." where x = A-Z *
* *
***********************************************************************
*
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
B RETURN
*
OPENRTN EQU *
OPEN (VSAMFILE,(INPUT))
LTR R15,R15 * WAS OPEN SUCCESSFUL ???
BNZ BADOPEN * IF NOT, THEN QUIT
TESTCB ACB=VSAMFILE,OFLAGS=OPEN
BNZ BADOPEN
ST R15,8(,R8)
B RETURN
*
GETRTN EQU *
MVC USERKEY(6),12(R8) * MOVE REQ KEY RPL KEY FIELD
MVI RECORD,C' ' * PREPARE TO INIT RECORD AREA
MVC RECORD+1(79),RECORD INITIALIZE RECORD AREA
MVC 12(80,R8),RECORD * CLEAR PASS-AREA BUFFER
GET RPL=SEQRET
ST R15,SAVE15 * SAVE RETURN CODE
LTR R15,R15 * IS RETURN CODE = 0 ???
BNZ BADGET IF NOT, THEN POST A MESSAGE
MVC 12(80,R8),RECORD * MOVE DATA TO USER PASS AREA
ST R15,8(,R8) SET USER RETRUN CODE TO ZERO
B RETURN
*
CLOSERTN EQU *
CLOSE VSAMFILE
LTR 15,15
BNZ BADCLOSE
ST R15,8(,R8)
B RETURN
*
RETURN EQU *
SR 15,15 SET USER RETURN CODE TO ZERO
RETURN (14,12),RC=(15)
*
EODRTN EQU *
WTO '* CBLASMA1 THE END-OF-FILE HAS BEEN PROCESSED'
LA R15,16
ST R15,8(,R8) * SET USER RETURN CODE TO ZERO
RETURN (14,12),RC=(15)
*
BADTEST EQU *
ST R15,8(,R8) * SET USER RETURN CODE TO ZERO
WTO '* CBLASMA1 THE TESTCB FOR VSAM FEEDBACK CODE FAILED'
L R15,8(,R8)
RETURN (14,12),RC=(15)
*
ERROR1 EQU *
ST R15,8(,R8) * SET USER RETURN CODE TO ZERO
WTO '* CBLASMA1 SYNAD ERROR PROCESSING'
L R15,8(,R8)
RETURN (14,12),RC=(15)
*
BADOPEN EQU *
ST R15,8(,R8) * SET USER RETURN CODE TO ZERO
WTO '* CBLASMA1 THE FILE OPEN FAILED...'
L R15,8(,R8)
RETURN (14,12),RC=(15)
*
BADGET EQU *
ST R15,8(,R8) * SET USER RETURN CODE TO ZERO
WTO '* CBLASMA1 THE FILE GET FAILED...'
L R15,8(,R8)
RETURN (14,12),RC=(15)
*
BADCLOSE EQU *
ST R15,8(,R8) * SET USER RETURN CODE TO ZERO
WTO '* CBLASMA1 THE FILE CLOSE FAILED...'
L R15,8(,R8)
RETURN (14,12),RC=(15)
*
VSAMFILE ACB AM=VSAM,EXLST=MSTEXL,DDNAME=VKSD0080,MACRF=(SEQ,IN)
MSTEXL EXLST EODAD=EODRTN,SYNAD=ERROR1
SEQRET RPL AM=VSAM,ACB=VSAMFILE,AREA=RECORD,AREALEN=80, X
OPTCD=(KEY,SEQ),KEYLEN=6,ARG=USERKEY
*
SEQRETA DC A(SEQRET)
USERKEY DC F'0'
SAVE15 DS F'0'
RECORD DS CL256
*
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 without the written permission of SimoTime Enterprises.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to Simotime Enterprises. 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 Enterprises.
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.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
You may download this example at http://www.simotime.com/sim4dzip.htm#AsmIORoutine or view the complete list of SimoTime Examples at http://www.simotime.com/sim4dzip.htm.
Note: You must be attached to the Internet to download a Z-Pack or view the list.
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 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. 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-2010 SimoTime Enterprises All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |