|
|||||
|
This document provides a listing of the COBOL source code for the callable routine SimoBSIO. SimoBSIO is a callable routine that uses the Micro Focus Byte-Stream I/O capability to access a file. This routine may access a single byte or multiple bytes of data at the specified offset into the file. SimoBSIO is written and tested using the Micro Focus COBOL dialect (it will only execute in a Micro Focus envirnment, it will not compile and run on a mainframe system).
Additional information about this program may be obtained by sending an e-mail to: helpdesk@simotime.com
The SimoBSIO routine (or callable program) will provide access to a file at the byte level. The routine may access a single byte or multiple bytes in a single access.
The following is the source code for the copy file (PASSBSIO.CPY) that defines the parameters used by the byte-stream I/O routine.
01 PSIO-PASS-AREA.
05 PSIO-REQUEST pic X(8).
05 PSIO-RETURN pic 9(4).
05 PSIO-FILENAME pic X(256).
05 PSIO-FILE-SIZE pic 9(12).
05 PSIO-OFFSET pic 9(12).
05 PSIO-LENGTH pic 9(7).
05 PSIO-MAX-SIZE pic 9(7).
05 PSIO-BUFFER pic X(32760).
The following is a list of the parameters that are required to use the byte-stream I/O routine.
| Parameter | Description | ||||||||||||||||||||
| PSIO-REQUEST | This parameter identifies the request of the calling program or the
function to be performed by the byte-stream I/O routine. This parameter should
contain one of the following.
|
||||||||||||||||||||
| PSIO-RETURN | This parameter is modified by the SimoBSIO routine. A zero (0) value indicates a successful completion of the request. A non-zero value indicates an invalid request, an end-of-file condition or an error condition. | ||||||||||||||||||||
| PSIO-FILENAME | This parameter must be provided by the calling routine. It should contain the physical name of the file to be accessed. | ||||||||||||||||||||
| PSIO-FILE-SIZE | This parameter is modified by the SimoBSIO routine after the initial call that opens the file. The value will be the size of the file in bytes. | ||||||||||||||||||||
| PSIO-OFFSET | This parameter must be provided by the calling routine and is the offset into the file where the requested access will begin. | ||||||||||||||||||||
| PSIO-LENGTH | This parameter must be provided by the calling routine and is the length or number of btes to be accessed. | ||||||||||||||||||||
| PSIO-MAX-SIZE | This parameter must be provided by the calling routine and is the maximum size of the buffer that holds the data string that will be accessed. | ||||||||||||||||||||
| PSIO-BUFFER | This is the data buffer. For a write or update it must be provided by the calling program. For a read it will be modified by SimoBSIO and contain the text string that was read from the file. |
The following will OPEN the file.
move 'C:\MYFILE.DAT' to PSIO-FILENAME
move 'OPEN ' to PSIO-REQUEST
call 'SIMOBSIO' using PSIO-PASS-AREA
The following will CLOSE the file. Since the file name was established during the OPEN request it should still be available in the pass area.
move 'CLOSE ' to PSIO-REQUEST
call 'SIMOBSIO' using PSIO-PASS-AREA
The preceding examples are dependent on the pass area definitions provided by the COBOL copy file that should be included in the WORKING-STORAGE section of the calling program and is included in LINKAGE section of the SimoBSIO program.
COPY PASSBSIO.
The following is the COBOL Source Code.
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMOBSIO.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
*
* Source Module: SIMOBSIO.CBL
*
* CALL Interface
* ------------
* call 'SIMOBSIO' using PSIO-PASS-AREA
*
* DESCRIPTION
* -----------
* This callable program uses the Byte-Stream I/O capabilities
* provided by Micro Focus to acces a file by reading a single
* byte or multiple bytes based on the caller's request.
*
* MAINTENANCE
* -----------
* 04/27/1992 Provided by SimoTime Enterprises
*
*****************************************************************
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SIM-TITLE.
05 T1 pic X(11) value '* SIMOBSIO '.
05 T2 pic X(34) value 'Byte-Stream I/O Routine '.
05 T3 pic X(10) value ' v06.06.01'.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* SIMOBSIO '.
05 C2 pic X(20) value 'Copyright 1987-2006 '.
05 C3 pic X(28) value ' SimoTime Enterprises, LLC '.
05 C4 pic X(20) value ' All Rights Reserved'.
*****************************************************************
* Data-structure for byte stream files...
*****************************************************************
* Byte Stream Files *
* ----------------- *
* For all the routines the RETURN-CODE register is set to *
* zero if the routine is successful. *
*****************************************************************
* Open a file, Byte Stream File...
* filename space or null terminated
* access-mode 01=read only
* 02=write only, deny-mode must=0
* 03=read/write
* When the x'40' bit is on then large file
* access is enabled (larger than 4-gig)
* 65=read only
* 66=write only, deny-mode must=0
* 67=read/write
* deny-mode 0=deny read/write(exclusive)
* 1=deny write
* 2=deny read
* 3=deny neither read nor write
* device future use, must=0
* file-handle if succesful open
* ------------------------------------------------------------
*
01 BSIO-FILENAME pic X(256) value SPACES.
01 BSIO-ACCESS-MODE pic X comp-x value 1.
01 BSIO-DENY-MODE pic X comp-x value 0.
01 BSIO-DEVICE pic X comp-x value 0.
01 BSIO-FILE-HANDLE pic X(4) value LOW-VALUES.
01 BSIO-FILE-OFFSET pic X(8) comp-x value 1.
01 BSIO-FILE-COUNT pic X(4) comp-x value 1.
01 BSIO-FLAGS pic X comp-x value 0.
01 BSIO-BUFFER pic X(32760) value SPACES.
* One of the following must be moved to BSIO-ACCESS-MODE.
* Standard, File size < 4 gigabytes.
01 BSIO-S-READ pic X comp-x value 1.
01 BSIO-S-WRITE pic X comp-x value 2.
01 BSIO-S-READ-WRITE pic X comp-x value 3.
* Extended, File size = or > 4 gigabytes.
01 BSIO-X-READ pic X comp-x value 65.
01 BSIO-X-WRITE pic X comp-x value 66.
01 BSIO-X-READ-WRITE pic X comp-x value 67.
01 BIG-FILE-SUPPORT pic X value 'Y'.
*****************************************************************
* Data structure for message display and logging... *
*****************************************************************
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* SIMOBSIO '.
05 MESSAGE-TEXT.
10 MESSAGE-TEXT-1 pic X(68) value SPACES.
10 MESSAGE-TEXT-2 pic X(188) value SPACES.
01 FIRST-TIME pic X value 'Y'.
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.
*****************************************************************
LINKAGE SECTION.
COPY PASSBSIO.
*****************************************************************
PROCEDURE DIVISION using PSIO-PASS-AREA.
if FIRST-TIME = 'Y'
perform Z-POST-COPYRIGHT
move 'N' to FIRST-TIME
end-if
* Set Access-Mode to Read-Only...
add 1 to ZERO giving BSIO-ACCESS-MODE
evaluate PSIO-REQUEST
when 'READBSIO' perform BSIOX-FILE-READBSIO
when 'OPEN ' perform BSIOX-FILE-OPEN
when 'OPENPUT ' perform BSIOX-FILE-OPEN-PUT
when 'FILEINFO' perform BSIOX-GET-FILE-INFO
when 'CLOSE ' perform BSIOX-FILE-CLOSE
when 'WRITE ' perform BSIOX-FILE-WRITE
when 'CREATE ' perform BSIOX-FILE-CREATE
when '64BITON ' move 'Y' to BIG-FILE-SUPPORT
move ZERO to RETURN-CODE
move ZERO to PSIO-RETURN
when '64BITOFF' move 'N' to BIG-FILE-SUPPORT
move ZERO to RETURN-CODE
move ZERO to PSIO-RETURN
when other perform ABEND-QUIT
end-evaluate
* add RETURN-CODE to ZERO giving PSIO-RETURN
if PSIO-RETURN not = ZERO
perform BSIOX-FILE-CLOSE
end-if
GOBACK.
*****************************************************************
* Do an Abnormal termination of the program...
*****************************************************************
ABEND-QUIT.
if MESSAGE-TEXT not = SPACES
perform Z-DISPLAY-CONSOLE-MESSAGE
end-if
move 'Program return-to-caller with ABEND'
to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add 16 to ZERO giving RETURN-CODE
add RETURN-CODE to ZERO giving PSIO-RETURN
GOBACK
exit.
*****************************************************************
BSIOX-FILE-READBSIO.
subtract BSIO-FLAGS from BSIO-FLAGS *> normal read
add PSIO-OFFSET to ZERO giving BSIO-FILE-OFFSET
if PSIO-LENGTH > PSIO-MAX-SIZE
add PSIO-MAX-SIZE to zero giving BSIO-FILE-COUNT
move 'ERROR, Short READ, Requested length exceeds MAX'
to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
else
add PSIO-LENGTH to zero giving BSIO-FILE-COUNT
end-if
perform BSIO-READ
if RETURN-CODE = 0
move BSIO-BUFFER to PSIO-BUFFER
move ZERO to PSIO-RETURN
else
if RETURN-CODE = 12592
add 10 to ZERO giving RETURN-CODE
end-if
add RETURN-CODE to ZERO giving PSIO-RETURN
display RETURN-CODE
if RETURN-CODE = 10
add RETURN-CODE to ZERO giving PSIO-RETURN
move SPACES to PSIO-BUFFER
move "End of File..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
else
move "Error during file READ..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add RETURN-CODE to ZERO giving TWO-BYTES-BINARY
move TWO-BYTES to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform ABEND-QUIT
end-if
end-if
exit.
*---------------------------------------------------------------*
BSIOX-FILE-OPEN.
move PSIO-FILENAME to BSIO-FILENAME
if BIG-FILE-SUPPORT = 'N'
add BSIO-S-READ to ZERO giving BSIO-ACCESS-MODE
else
add BSIO-X-READ to ZERO giving BSIO-ACCESS-MODE
end-if
* display BSIO-FILENAME
perform BSIO-OPEN
if RETURN-CODE = 0
add RETURN-CODE to ZERO giving PSIO-RETURN
else
move "Error during file OPEN..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add RETURN-CODE to ZERO giving TWO-BYTES-BINARY
move TWO-BYTES to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform ABEND-QUIT
end-if
exit.
*---------------------------------------------------------------*
BSIOX-FILE-CREATE.
move PSIO-FILENAME to BSIO-FILENAME
if BIG-FILE-SUPPORT = 'N'
add BSIO-S-WRITE to ZERO giving BSIO-ACCESS-MODE
else
add BSIO-X-WRITE to ZERO giving BSIO-ACCESS-MODE
end-if
* display BSIO-FILENAME
perform BSIO-CREATE
if RETURN-CODE = 0
add RETURN-CODE to ZERO giving PSIO-RETURN
else
move "Error during file CREATE..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add RETURN-CODE to ZERO giving TWO-BYTES-BINARY
move TWO-BYTES to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform ABEND-QUIT
end-if
exit.
*---------------------------------------------------------------*
BSIOX-FILE-OPEN-PUT.
move PSIO-FILENAME to BSIO-FILENAME
if BIG-FILE-SUPPORT = 'N'
add BSIO-S-WRITE to ZERO giving BSIO-ACCESS-MODE
else
add BSIO-X-WRITE to ZERO giving BSIO-ACCESS-MODE
end-if
* display BSIO-FILENAME
perform BSIO-OPEN
if RETURN-CODE = 0
add RETURN-CODE to ZERO giving PSIO-RETURN
else
move "Error during file OPENPUT..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add RETURN-CODE to ZERO giving TWO-BYTES-BINARY
move TWO-BYTES to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform ABEND-QUIT
end-if
exit.
*---------------------------------------------------------------*
BSIOX-FILE-CLOSE.
perform BSIO-CLOSE
if RETURN-CODE = 0
if PSIO-RETURN not = 10
add RETURN-CODE to ZERO giving PSIO-RETURN
end-if
else
move "Error during file CLOSE..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add RETURN-CODE to ZERO giving TWO-BYTES-BINARY
move TWO-BYTES to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform ABEND-QUIT
end-if
exit.
*---------------------------------------------------------------*
BSIOX-FILE-WRITE.
subtract BSIO-FLAGS from BSIO-FLAGS
add PSIO-OFFSET to ZERO giving BSIO-FILE-OFFSET
if PSIO-LENGTH > PSIO-MAX-SIZE
add PSIO-MAX-SIZE to zero giving BSIO-FILE-COUNT
move 'ERROR, Short WRITE, Requested length exceeds MAX'
to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
else
add PSIO-LENGTH to zero giving BSIO-FILE-COUNT
end-if
move PSIO-BUFFER to BSIO-BUFFER
perform BSIO-WRITE
if RETURN-CODE = 0
add RETURN-CODE to ZERO giving PSIO-RETURN
move BSIO-BUFFER to PSIO-BUFFER
else
move "Error during file WRITE..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add RETURN-CODE to ZERO giving TWO-BYTES-BINARY
move TWO-BYTES to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform ABEND-QUIT
end-if
exit.
*---------------------------------------------------------------*
BSIOX-GET-FILE-INFO.
* Get file size into BSIO-FILE-OFFSET
subtract BSIO-FLAGS from BSIO-FLAGS
add 128 to BSIO-FLAGS
perform BSIO-READ
if RETURN-CODE = 0
add RETURN-CODE to ZERO giving PSIO-RETURN
else
move "Error during file READ..." to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add RETURN-CODE to ZERO giving TWO-BYTES-BINARY
move TWO-BYTES to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform ABEND-QUIT
end-if
add BSIO-FILE-OFFSET to ZERO giving PSIO-FILE-SIZE
exit.
*---------------------------------------------------------------*
* Byte Stream Files *
* ----------------- *
* For all the routines the RETURN-CODE register is set to *
* zero if the routine is successful. *
*---------------------------------------------------------------*
* Open a file, Byte Stream File... *
* filename space or null terminated *
* access-mode 1=read only *
* 2=write only, deny-mode must=0 *
* 3=read/write *
* deny-mode 0=deny read/write(exclusive) *
* 1=deny write *
* 2=deny read *
* 3=deny neither read nor write *
* device future use, must=0 *
* file-handle if succesful open *
*---------------------------------------------------------------*
BSIO-OPEN.
call "CBL_OPEN_FILE" using BSIO-FILENAME
BSIO-ACCESS-MODE
BSIO-DENY-MODE
BSIO-DEVICE
BSIO-FILE-HANDLE
exit.
*---------------------------------------------------------------*
BSIO-CREATE.
call "CBL_CREATE_FILE" using BSIO-FILENAME
BSIO-ACCESS-MODE
BSIO-DENY-MODE
BSIO-DEVICE
BSIO-FILE-HANDLE
exit.
*---------------------------------------------------------------*
* Read a file, Byte Stream File... *
* file-handle returned from open *
* file-offset offset in file to start read *
* file-count nnn=bytes to read *
* flags 0=standard read *
* 128=return size in file-offset *
* buffer data buffer for read *
*---------------------------------------------------------------*
BSIO-READ.
call "CBL_READ_FILE" using BSIO-FILE-HANDLE
BSIO-FILE-OFFSET
BSIO-FILE-COUNT
BSIO-FLAGS
BSIO-BUFFER
exit.
*---------------------------------------------------------------*
BSIO-WRITE.
call "CBL_WRITE_FILE" using BSIO-FILE-HANDLE
BSIO-FILE-OFFSET
BSIO-FILE-COUNT
BSIO-FLAGS
BSIO-BUFFER
exit.
*---------------------------------------------------------------*
BSIO-CLOSE.
call "CBL_CLOSE_FILE" using BSIO-FILE-HANDLE
exit.
*****************************************************************
* The following Z-Routines perform administrative tasks *
* for this program. *
*****************************************************************
* ABEND the program, post a message to the console and issue *
* a STOP RUN. *
*****************************************************************
Z-ABEND-PROGRAM.
if MESSAGE-TEXT not = SPACES
perform Z-DISPLAY-CONSOLE-MESSAGE
end-if
move 'PROGRAM-IS-ABENDING...' to MESSAGE-TEXT
perform Z-DISPLAY-CONSOLE-MESSAGE
add 12 to ZERO giving RETURN-CODE
STOP RUN
exit.
*****************************************************************
* Display CONSOLE messages... *
*****************************************************************
Z-DISPLAY-CONSOLE-MESSAGE.
if MESSAGE-TEXT-2 = SPACES
display MESSAGE-BUFFER(1:79) upon console
else
display MESSAGE-BUFFER upon console
end-if
move all SPACES to MESSAGE-TEXT
exit.
*****************************************************************
* 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 '* SIMOBSIO File-Status-' IO-STAT1 '/'
TWO-BYTES-BINARY upon console
else
display '* SIMOBSIO File-Status-' IO-STATUS upon console
end-if
exit.
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE upon console
display SIM-COPYRIGHT 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 *
*****************************************************************
The purpose of this document is to provide a COBOL Source member for viewing.
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.
Permission to use, copy, modify and distribute this software for a 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.
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 view an example of a COBOL program that uses SimoBSIO at http://www.simotime.com/vrecex01.htm.
You may view the complete list of SimoTime callable Modules or Driver Programs at http://www.simotime.com/simomods.htm.
This item will provide a link to an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
To review all the information available on this site start at The SimoTime Home Page .
This link provides information about The Training Sessions and Self-Study Courses available from SimoTime Enterprises.
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
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 |