|
|||||
|
This suite of programs provides an example of how a mainline COBOL program calls a mainframe COBOL I/O routine to access a QSAM or Sequential file. Both COBOL programs are written using the VS COBOL II dialect and should work with COBOL for MVS, COBOL/370, OS390 and Enterprise COBOL. 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. A suite of Windows Command files is provided to run in a Windows environment with Micro Focus Net Express or Application Servers without JCL.
Another example of accessing QSAM files that uses a called Assembler 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, JCL or QSAM and as a reference for experienced programmers. Additional information is provided in the Downloads and Links to Similar Pagessection of this document.
The following is a flowchart of the COBOL calling COBOL example. The BLUE boxes are unique to the mainframe and Micro Focus Mainframe Express. The RED boxes are unique to the PC with Windows and Micro Focus Net Express. The GREEN boxes are platform independent and will execute on the mainframe or a PC with Windows. Also, the GREEN boxes may be ported to a UNIX platform that is supported by Micro Focus COBOL.
|
|
The JCL or CMD member for running the application. | |||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
|
|
On return from call display info from pass area. | |||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
Call CBLQSMC2 from CBLQSMC1. | |||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
|
Record Sequential with fixed, 80-byte records. | |||||||||||||||||||||||||||||||||||||||||
|
The following summarizes the items needed for a "calling program" (CBLQSMC1.CBL) to call a "called program" (CBLQSMC2).
The "calling program" contains the following statement to make the call to the "called program".
CALL 'CBLQSMC2' USING PASS-AREA
The "calling program" needs the following data structure (PASS-AREA) to be defined in the WORKING-STORAGE section.
*****************************************************************
* Data Structure used for calling CBLQSMC2.
* The calling statement is as follows...
* CALL 'CBLQSMC2' 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 "called-program" needs the following Linkage Section defined for the pass area.
*****************************************************************
LINKAGE SECTION.
* Data Structure used for passing the address or an address
* list of a data string or strings..
* The Procedure Division statement must also be as follows...
* The PROCEDURE DIVISION 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).
*****************************************************************
In addition to defining the pass area in the Linkage Section the "called program" needs the Procedure Division statement to be coded as follows.
PROCEDURE DIVISION using PASS-AREA.
The source code listings for both the "calling program" and the "called program" are included within this document.
The following section describes three (3) JCL members. The first JCL member will execute a COBOL program that calls a second COBOL to access a sequential file. The second JCL member is used to create and populate a sequential file. The third JCL member will delete the sequential file.
The following is the mainframe JCL (CBLQSMJ1.JCL) required to run the mainline program. The coding technique is used with the expectation the JCL would be used as a stand alone procedure. The job and DD statements will need to be modified for different mainframe environments.
//CBLQSMJ1 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. //* //* ************ //* * CBLQSMJ1 * //* ********jcl* //* * //* ************ ************ //* * CBLQSMC1 ************call**** CBLQSMC1 * //* ********cbl* * ********cbl* //* * * * //* * * * //* * * ************ //* * * * QSAMFILE * //* * * *******data* //* * * //* * * //* * * ************ //* * ************* DISPLAY * //* * ****console* //* * //* * //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //CBLQSMX1 EXEC PGM=CBLQSMC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //QSAMFILE DD DSN=SIMOTIME.DATA.QSAM0080,DISP=SHR //*
The following is the mainframe JCL (QSMCRTJ1.JCL) to create a new sequential file. Also, this member will delete any previously created file.
//QSMCRTJ1 JOB SIMOTIME,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //* ******************************************************************* //* This program is provided by: * //* SimoTime Enterprises, LLC * //* (C) Copyright 1987-2008 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - Create a Sequential Data Set on disk using IEBGENER. //* Author - SimoTime Enterprises //* Date - January 24, 1996 //* //* The first job step (QSAMDELT) will delete any previously created //* file. The second job step (QSAMCRT1) will create a new file. //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express. //* //* ************ //* * QSMCRTJ1 * //* ********jcl* //* * //* * //* ************ ************ //* * IEFBR14 ******* QSAM0080 * //* ********utl* ***delete*** //* * //* * //* ************ ************ ************ //* * SYSIN ******* IEBGENER ******* QSAM0080 * //* ********jcl* ********utl* *******qsam* //* * //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 of 2 Delete any previously created file... //* //QSAMDELT EXEC PGM=IEFBR14 //QSAM0080 DD DSN=SIMOTIME.DATA.QSAM0080,DISP=(MOD,DELETE,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //* //* ******************************************************************* //* Step 2 of 2 Create and populate a new QSAM file... //* //QSAMCRT1 EXEC PGM=IEBGENER //SYSPRINT DD SYSOUT=* //SYSIN DD DUMMY //* :....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8 //SYSUT1 DD * 000100 Anderson Adrian 111 Peachtree Plaza Atlanta GA 000200 Brown Billie 222 Baker Boulevard Baltimore MD 000300 Carson Cameron 333 Crenshaw Blvd. Cupertino CA 000400 Davidson Dion 444 Main Street Wilmington DE 000500 Everest Evan 555 5TH Avenue New York NY 000600 Franklin Francis 666 66TH Avenue Bedrock NY 000700 Garfunkel Gwen 777 77TH Street New York NY 000800 Harrison Hilary 888 88TH Street Pocatello ID 000900 Isley Isabel 999 99TH Avenue Indianapolis IN 001000 Johnson Jamie 1010 Paradise Drive Larkspur CA 001100 Kemper Kelly 1111 Oak Circle Kansas City KS 001200 Lemond Lesley 1212 Lockwood Road Mohave Desert AZ 001300 Mitchell Marlow 1313 Miller Creek Road Anywhere TX 001400 Newman Noel 1414 Park Avenue Santa Monica CA 001500 Osborn Owen 1515 Center Stage Rolling Rock PA 001600 Powell Pierce PO Box 1616 Ventura CA 001700 Quigley Quincy 1717 Farm Hill Road Oshkosh WI 001800 Ripley Ray 1818 Alien Lane Wayout KS 001900 Smith Sammy 1919 Carnoustie Drive Novato CA 002000 Tucker Taylor 2020 Sanger Lane St. Paul MN 002100 Underwood Ulysses 2121 Wall Street New York NY 002200 Van Etten Valerie 2222 Vine Street Hollywood CA 002300 Wilson Wiley 2323 Main Street Boston MA 002400 Xray Xavier 2424 24TH Street Nashville TN 002500 Young Yanni 2525 Yonge Street Toronto ON 002600 Zenith Zebulon 2626 26TH Street Dallas TX 123456 Doe John 123 Main Street Anywhere OR /* //SYSUT2 DD DSN=SIMOTIME.DATA.QSAM0080, // DISP=(NEW,CATLG,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //
The following is the mainframe JCL (QSMDELJ1.JCL) to delete the sequential file.
//QSMDELJ1 JOB SIMOTIME,CLASS=1,MSGCLASS=0,NOTIFY=CSIP1 //* ******************************************************************* //* This program is provided by: * //* SimoTime Enterprises, LLC * //* (C) Copyright 1987-2008 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - Delete a Sequential File on disk using IEFBR14. //* Author - SimoTime Enterprises //* Date - January 24, 1996 //* //* ******************************************************************* //* //QSAMDELT EXEC PGM=IEFBR14 //QSAM0080 DD DSN=SIMOTIME.DATA.QSAM0080,DISP=(MOD,DELETE,DELETE), // STORCLAS=MFI, // SPACE=(TRK,5), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800,DSORG=PS) //*
The following section describes three (3) Windows Command files. The first CMD member will execute a COBOL program that calls a second COBOL to access a sequential file. The second CMD member is used to create and populate a sequential file. The third CMD member will delete the sequential file.
The following is the Windows Command file (CBLQSME1.CMD) required to run the COBOL program without using mainframe JCL.
@echo OFF
rem * *******************************************************************
rem * This program is provided by: *
rem * SimoTime Enterprises, LLC *
rem * (C) Copyright 1987-2007 All Rights Reserved *
rem * Web Site URL: http://www.simotime.com *
rem * e-mail: helpdesk@simotime.com *
rem * *******************************************************************
rem *
rem * Text - COBOL calls COBOL I/O Routine for QSAM access.
rem * Author - SimoTime Enterprises
rem * Date - January 01, 2006
rem *
rem * This set of COBOL programs will use a standard calling interface
rem * between a mainline program and an I/O module to read and display
rem * the contents 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 Env1PROD
if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
set CmdName=CblQsmE1
rem *
call SimoNOTE "*******************************************************%CmdName%"
call SimoNOTE "Starting JobName %CmdName%"
rem * ********************************************************************
rem * Step 2 of 2, Execute the sample program...
rem *
set QSAMFILE=%BaseLib1%\DataLibA\Asc1\SIMOTIME.DATA.QSAM0080.DAT
rem *
run CBLQSMC1
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%
The following is the Windows Command file (QSMCRTE1.JCL) to create a new sequential file. Also, this member will delete any previously created files.
@echo OFF
rem * *******************************************************************
rem * This program is provided by: *
rem * SimoTime Enterprises, LLC *
rem * (C) Copyright 1987-2008 All Rights Reserved *
rem * Web Site URL: http://www.simotime.com *
rem * e-mail: helpdesk@simotime.com *
rem * *******************************************************************
rem *
rem * Text - Create a Sequential Data Set on disk using IEBGENER.
rem * Author - SimoTime Enterprises
rem * Date = January 24, 1996
rem *
rem * The first job step (DeleteTEXT) will delete any previously created
rem * files.
rem * The second job step (CreateTEXT) will create a new ASCII/Text file.
rem * The third step will convert the Line Sequential file to a Record
rem * Sequential file.
rem *
rem * This set of programs will run on a Personal Computer with Windows
rem * and Micro Focus Net Express.
rem *
rem *
rem * ************
rem * * QSMCRTE1 *
rem * ********cmd*
rem * *
rem * *
rem * ************
rem * * Env1PROD *
rem * ********cmd*
rem * *
rem * *
rem * ************ ************
rem * * if exist ******* TEXT0080 *
rem * ************ ***delete***
rem * *
rem * *
rem * ************ ************ ************
rem * * SYSIN ******* echo ******* TEXT0080 *
rem * ********cmd* ********utl* *******qsam*
rem * *
rem * *
rem * ************
rem * * EOJ *
rem * ************
rem *
rem * *******************************************************************
call Env1PROD
if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
set JobName=QsmCrtE1
rem *
call SimoNOTE "*******************************************************%JobName%"
call SimoNOTE "Starting JobName %JobName%, User is %USERNAME%"
call SimoNOTE "Identify JobStep DeleteQSAM"
set TEXT0080=%BaseLib1%\DataLibA\Txt1\TEXT0080.TXT
rem *
rem * *******************************************************************
rem * Step 1 of 2 Create and populate a new ASCII/TEXT file...
rem *
call SimoNOTE "Identify JobStep Create an ASCII/Text File"
if exist %TEXT0080% del %TEXT0080%
rem * ..1....:....2....:....3....:....4....:....5....:....6....:....7.
echo 000100 Anderson Adrian 111 Peachtree Plaza Atlanta GA 26101 >%TEXT0080%
echo 000200 Brown Billie 222 Baker Boulevard Baltimore MD 35702 >>%TEXT0080%
echo 000300 Carson Cameron 333 Crenshaw Blvd. Cupertino CA 96154 >>%TEXT0080%
echo 000400 Davidson Dion 444 Main Street Wilmington DE 27323 >>%TEXT0080%
echo 000500 Everest Evan 555 5TH Avenue New York NY 10341 >>%TEXT0080%
echo 000600 Franklin Francis 666 66TH Avenue Bedrock NY 11903 >>%TEXT0080%
echo 000700 Garfunkel Gwen 777 77TH Street New York NY 16539 >>%TEXT0080%
echo 000800 Harrison Hilary 888 88TH Street Pocatello ID 79684 >>%TEXT0080%
echo 000900 Isley Isabel 999 99TH Avenue Indianapolis IN 38762 >>%TEXT0080%
echo 001000 Johnson Jamie 1010 Paradise Drive Larkspur CA 90504 >>%TEXT0080%
echo 001100 Kemper Kelly 1111 Oak Circle Kansas City KS 55651 >>%TEXT0080%
echo 001200 Lemond Lesley 1212 Lockwood Road Mohave Desert AZ 80303 >>%TEXT0080%
echo 001300 Mitchell Marlow 1313 Miller Creek Road Anywhere TX 77123 >>%TEXT0080%
echo 001400 Newman Noel 1414 Park Avenue Santa Monica CA 90210 >>%TEXT0080%
echo 001500 Osborn Owen 1515 Center Stage Rolling Rock PA 36613 >>%TEXT0080%
echo 001600 Powell Pierce PO Box 1616 Ventura CA 97712 >>%TEXT0080%
echo 001700 Quigley Quincy 1717 Farm Hill Road Oshkosh WI 43389 >>%TEXT0080%
echo 001800 Ripley Ray 1818 Alien Lane Wayout KS 55405 >>%TEXT0080%
echo 001900 Smith Sammy 1919 Carnoustie Drive Novato CA 94919 >>%TEXT0080%
echo 002000 Tucker Taylor 2020 Sanger Lane St. Paul MN 43998 >>%TEXT0080%
echo 002100 Underwood Ulysses 2121 Wall Street New York NY 17623 >>%TEXT0080%
echo 002200 Van Etten Valerie 2222 Vine Street Hollywood CA 98775 >>%TEXT0080%
echo 002300 Wilson Wiley 2323 Main Street Boston MA 01472 >>%TEXT0080%
echo 002400 Xray Xavier 2424 24TH Street Nashville TN 44190 >>%TEXT0080%
echo 002500 Young Yanni 2525 Yonge Street Toronto ON 6B74A6>>%TEXT0080%
echo 002600 Zenith Zebulon 2626 26TH Street Dallas TX 71922 >>%TEXT0080%
echo 123456 Doe John 123 Main Street Anywhere OR 88156 >>%TEXT0080%
if exist %TEXT0080% call SimoNOTE "Produced DataSet %TEXT0080%"
if not exist %TEXT0080% set JobStatus=9001
if not %JobStatus% == 0000 goto :EojNok
rem *
rem * *******************************************************************
rem * Step 2 of 2 Convert ASCII/TEXT file to Record Sequential File...
rem *
call SimoNOTE "Identify JobStep Convert Line Sequential to Record Sequential"
set GETLS080=%TEXT0080%
set PUTRS080=%BaseLib1%\DataLibA\Asc1\SIMOTIME.DATA.QSAM0080.DAT
if exist %PUTRS080% del %PUTRS080%
run ALAR80C1
if exist %PUTRS080% call SimoNOTE "Produced DataSet %PUTRS080%"
if not exist %PUTRS080% set JobStatus=9002
if not %JobStatus% == 0000 goto :EojNok
rem *
:EojAok
call SimoNOTE "Finished JobName %JobName%, Job Status is %JobStatus%"
goto :End
:EojNok
call SimoNOTE "NOTE ABENDING JobName %JobName%, Job Status is %JobStatus%"
:End
call SimoNOTE "Conclude SysLog is %SYSLOG%"
if not "%1" == "nopause" pause
The following is the Windows Command file (QSMDELE1.JCL) to delete the sequential files.
@echo OFF
rem * *******************************************************************
rem * This program is provided by: *
rem * SimoTime Enterprises, LLC *
rem * (C) Copyright 1987-2008 All Rights Reserved *
rem * Web Site URL: http://www.simotime.com *
rem * e-mail: helpdesk@simotime.com *
rem * *******************************************************************
rem *
rem * Text - Delete the Sequential Data Sets for QSAM0080.
rem * Author - SimoTime Enterprises
rem * Date = January 24, 1996
rem *
rem * The 1st job step (DeleteTEXT) will delete TEXT0080.TXT
rem * The 2nd job step (DeleteQSAM) will delete QSAM0080.DAT
rem *
rem * This set of programs will run on a Personal Computer with Windows
rem * and Micro Focus Net Express.
rem *
rem * *******************************************************************
call Env1PROD
if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
set JobName=QsmDelE1
rem *
call SimoNOTE "*******************************************************%JobName%"
call SimoNOTE "Starting JobName %JobName%, User is %USERNAME%"
rem *
:DeleteTEXT
set TEXT0080=%BaseLib1%\DataLibA\Txt1\TEXT0080.TXT
call SimoNOTE "Identify JobStep Delete %TEXT0080%"
if exist %TEXT0080% del %TEXT0080%
:DeleteQSAM
set QSAM0080=%BaseLib1%\DataLibA\Asc1\SIMOTIME.DATA.QSAM0080.DAT
call SimoNOTE "Identify JobStep Delete %QSAM0080%"
if exist %QSAM0080% del %QSAM0080%
rem *
:EojAok
call SimoNOTE "Finished JobName %JobName%, Job Status is %JobStatus%"
goto :End
:End
call SimoNOTE "Conclude SysLog is %SYSLOG%"
if not "%1" == "nopause" pause
This program (CBLQSMC1.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. CBLQSMC1.
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: CBLQSMC1.CBL
*****************************************************************
*
* CBLQSMC1 - Call CBLQSMC2 to access a KSDS, VSAM file.
*
* CALLING PROTOCOL
* ----------------
* Use standard procedure to RUN or ANIMATE.
*
* DESCRIPTION
* -----------
* This program will call a COBOL routine to access a
* KSDS, VSAM file for sequential processing.
*
*
* ************
* * CBLCBLJ1 *
* ********jcl*
* *
* ************
* * IEFBR14 *
* ********utl*
* *
* ************ ************
* * CBLQSMC1 *-------------------* Display *
* ********cbl* ************
* *
* *-------call-------------------*
* * *
* * *
* * ************ ************
* * * QSAM0080 *-----* CBLQSMC2 *
* * ********get* ********cbl*
* *
* ************
* * EOJ *
* ************
*
*
*
*****************************************************************
*
* 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 '* CBLQSMC1 '.
05 T2 pic X(34) value ' Sample, COBOL calls COBOL for 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 '* CBLQSMC1 '.
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 '* CBLQSMC1 '.
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 '* CBLQSMC1 '.
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 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).
*****************************************************************
* Data Structure used for calling CBLQSMC2.
* The calling statement is as follows...
* CALL 'CBLQSMC2' 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).
*****************************************************************
PROCEDURE DIVISION.
perform Z-POST-COPYRIGHT
display '* CBLQSMC1 OPEN Request...' upon console.
perform OPEN-THE-FILE.
display '* CBLQSMC1 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 '* CBLQSMC1 has COMPLETED...' upon console
perform Z-THANK-YOU.
GOBACK.
*****************************************************************
GET-NEXT-RECORD.
call 'CBLQSMC2' using PASS-AREA.
if NORMAL-RESULT
CONTINUE
else
if EOF-RESULT
move 'YES' to END-OF-FILE
else
move '* CBLQSMC1 QKSD001F, Failure, GET...'
to OPERATOR-MESSAGE
perform Z-ABEND-MESSAGE
add 12 to ZERO giving RETURN-CODE
STOP RUN
end-if
end-if
exit.
*---------------------------------------------------------------*
OPEN-THE-FILE.
add 8 to ZERO giving PASS-RESULT.
move REQUEST-OPEN to PASS-REQUEST.
call 'CBLQSMC2' using PASS-AREA.
if NORMAL-RESULT
CONTINUE
else
move '* CBLQSMC1 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 'CBLQSMC2' using PASS-AREA.
if NORMAL-RESULT
CONTINUE
else
move '* CBLQSMC1 QSAM0080, Failure, CLOSE...'
to OPERATOR-MESSAGE
perform Z-ABEND-MESSAGE
add 12 to ZERO giving RETURN-CODE
add 12 to 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 '* CBLQSMC1 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.
The following is the source listing for the I/O routine (CBLQSMC2.CBL) . When an I/O failure occurs the file status code will be displayed. Displaying the file status code takes a little extra effort. Many times the file status code is a two character field and each character is a printable numeric value. However, in some cases the second character may be a COMP value. The error handling in the following program will display the file status code correctly for either format.
IDENTIFICATION DIVISION.
PROGRAM-ID. CBLQSMC2.
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: CBLQSMC2.CBL
*****************************************************************
*
*>CBLQSMC2 - This is a called routine for KSDS,VSAM file I/O.
*
* CALLING PROTOCOL
* ----------------
* USE STANDARD PROCEDURE TO RUN OR ANIMATE.
*
* DESCRIPTION
* -----------
* This program will do KSDS, VSAM file I/O.
*
****************************************************************
*
* MAINTENANCE
* -----------
* 1997/02/27 Simmons, Created program.
* 1997/04/04 Simmons, Added code to display file status.
*
*****************************************************************
*
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
*
FILE-CONTROL.
*
SELECT QSAMFILE-FILE
ASSIGN to QSAMFILE
FILE STATUS is QSAMFILE-STATUS
ORGANIZATION is SEQUENTIAL
ACCESS MODE is SEQUENTIAL.
*
DATA DIVISION.
FILE SECTION.
*
FD QSAMFILE-FILE.
01 QSAMFILE-RECORD.
02 QSAMFILE-KEY pic X(6).
02 QSAMFILE-DATA pic X(74).
WORKING-STORAGE SECTION.
*
*****************************************************************
* Data-structure for Title and Copyright...
* ------------------------------------------------------------
01 SIM-TITLE.
05 T1 pic X(11) value '* CBLQSMC2 '.
05 T2 pic X(34) value ' Sample COBOL for Sequential I/O '.
05 T3 pic X(10) value ' v1.1.01 '.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* CBLQSMC2 '.
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'.
*
*****************************************************************
* Data-structure used within this program...
* ------------------------------------------------------------
01 QSAMFILE-STATUS.
05 QSAMFILE-STAT1 pic X.
05 QSAMFILE-STAT2 pic X.
01 IO-STATUS.
05 IO-STAT1 pic X.
05 IO-STAT2 pic X.
01 TWO-BYTES.
05 TWO-BYTES-LEFT pic X.
05 TWO-BYTES-RIGHT pic X.
01 TWO-BYTES-BINARY redefines TWO-BYTES pic 9(4) comp.
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 FIRST-TIME pic X value 'Y'.
*****************************************************************
LINKAGE SECTION.
* Data Structure used for passing the address or an address
* list of a data string or strings..
* The Procedure Division statement must also be as follows...
* The PROCEDURE DIVISION 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).
*****************************************************************
PROCEDURE DIVISION using PASS-AREA.
MAIN-ROUTINE.
if FIRST-TIME not = 'N'
perform Z-POST-COPYRIGHT
move 'N' to FIRST-TIME
end-if
evaluate PASS-REQUEST
when REQUEST-GET perform QSAMFILE-GET
when REQUEST-OPEN perform QSAMFILE-OPEN
when REQUEST-CLOSE perform QSAMFILE-CLOSE
when OTHER perform INVALID-REQUEST
end-evaluate
GOBACK.
*****************************************************************
INVALID-REQUEST.
display '* CBLQSMC2, Invalid Request, ' PASS-REQUEST
add 24 to ZERO giving PASS-RESULT
exit.
*****************************************************************
QSAMFILE-GET.
read QSAMFILE-FILE INTO PASS-RECORD
if QSAMFILE-STATUS = '00'
subtract PASS-RESULT from PASS-RESULT
else
if QSAMFILE-STATUS = '10'
add 16 to ZERO giving PASS-RESULT
else
add 12 to ZERO giving PASS-RESULT
display '* CBLQSMC2 QSAMFILE-Failed-READ-attempt...'
upon console
move QSAMFILE-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
end-if
end-if
exit.
*---------------------------------------------------------------*
QSAMFILE-OPEN.
open input QSAMFILE-FILE
if QSAMFILE-STATUS = '00'
subtract PASS-RESULT from PASS-RESULT
else
add 12 to ZERO giving PASS-RESULT
display '* CBLQSMC2 QSAMFILE-Failed-OPEN-attempt...'
upon console
move QSAMFILE-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
end-if
exit.
*---------------------------------------------------------------*
QSAMFILE-CLOSE.
close QSAMFILE-FILE
if QSAMFILE-STATUS = '00'
subtract PASS-RESULT from PASS-RESULT
else
add 12 to ZERO giving PASS-RESULT
display '* CBLQSMC2 QSAMFILE-Failed-CLOSE-attempt...'
upon console
move QSAMFILE-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
end-if
exit.
*****************************************************************
* The following Z-Routines perform administrative functions *
* for this program. *
*****************************************************************
*****************************************************************
* Display the file status bytes. This routine will display as *
* two digits if the full two byte file status is numeric. If *
* second byte is non-numeric then it will be treated as a *
* binary number. *
*****************************************************************
Z-DISPLAY-IO-STATUS.
if IO-STATUS not NUMERIC
or IO-STAT1 = '9'
subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
move IO-STAT2 to TWO-BYTES-RIGHT
display '* CBLQSMC2 FILE-STATUS-' IO-STAT1 '/'
TWO-BYTES-BINARY upon console
else
display '* CBLQSMC2 FILE-STATUS-' IO-STATUS upon console
end-if
exit.
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE upon console
display SIM-COPYRIGHT upon console
exit.
This program 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 Mainframe Express provided by Micro Focus. It is possible to watch the actual execution of each individual instruction and to immediately see the results.
The purpose of this document is to assist as a tutorial for new programmers or as a quick reference for experienced programmers. These sample programs are made available on an "as-is" basis and may be downloaded, copied and modified for specific situations as long as the copyright information is not removed or changed. 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#cblqsm01 as a Z-Pack. The Z-Packs provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download.
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. |
Please view the complete list of SimoTime Z-Pack 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.
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 an Assembler 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. The Assembler program was written using Assembler/H on the mainframe.
The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPS can also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements.
The following is a list of sample conversion programs created by the GENERATE function of SimoZAPS.
| Program | Description |
| cble2a01 | Convert from an EBCDIC-Sequential file to an ASCII-Sequential file. This example includes a mainframe JCL member. |
| zap00101 | Convert from an EBCDIC-Sequential file to an ASCII-Text file. |
| zap00201 | Convert from an EBCDIC-Sequential file to an ASCII-Indexed file (Sequential-Add). |
| zap00301 | Convert from an EBCDIC-Sequential file to an ASCII-Sequential file. |
| zap00401 | Convert from an ASCII-Text file to an EBCDIC-Indexed file (Sequential-Add). |
| zap00501 | Convert from an ASCII-Text file to an EBCDIC-Indexed file (Random-Add). |
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 |
| http://www.simotime.com |