![]() |
COBOL Copy File The REPLACING Function http://www.simotime.com Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| Table of Contents | Version 09.05.17 |
This suite of sample programs describes how to use a the REPLACING function with a COPY file statement within a COBOL program. The REPLACING function allows a programmer to use a single copy file to define multiple data structures of identical format with different field names.
Note: The COBOL language also has an INSPECT REPLACING function that is used to replace characters or text strings in a field at program execution time. For more information about this function refer to the INSPECT REPLACING document. available on the SimoTime web site.
The following (CPYREPB1.CPY) is a sample of the Micro Focus COBOL demonstration program. This program was tested using Micro Focus Net Express, version 4.0 and Mainframe Express running on Windows/XP.
*****************************************************************
* The following is used with a copy statement with replace to
* create a multiple number of uniquely named data structures of
* similar format.
01 :ZZZZ:-BUFFER.
05 :ZZZZ:-01 pic x value SPACE.
05 :ZZZZ:-02 pic x(2) value SPACES.
05 :ZZZZ:-03 pic x(3) value SPACES.
* CPYREPB1, End of Copy File...
The following (CPYREPC1.CBL) is a sample of the Micro Focus COBOL demonstration program. This program was tested using Micro Focus Net Express, version 4.0 and Mainframe Express running on Windows/XP.
IDENTIFICATION DIVISION.
PROGRAM-ID. CPYREPC1.
DATA DIVISION.
*****************************************************************
WORKING-STORAGE SECTION.
* The following copy file defines two alphabetic tables to be
* used for case conversion.
copy CASEVARY.
* The following uses the same copy file to create three uniquely
* named buffers or data structures of identical format.
copy CPYREPB1 replacing ==:ZZZZ:== by ==WORK==.
copy CPYREPB1 replacing ==:ZZZZ:== by ==TEST==.
copy CPYREPB1 replacing ==:ZZZZ:== by ==LAST==.
*****************************************************************
PROCEDURE DIVISION.
move 0 to RETURN-CODE
display 'CPYREPC1 is Starting...' upon console
* Move lower case letters to WORK-BUFFER and display contents
* by indivdual fields within buffer.
move 'a' to WORK-01
move 'ab' to WORK-02
move 'abc' to WORK-03
display WORK-01 upon console
display WORK-02 upon console
display WORK-03 upon console
* Move the lower-case content of the WORK-BUFFER to the
* TEST-BUFFER. The three inspect statements will do a lower to
* UPPER case conversion of the letters a, b and c. To convert
* the entire alphabet would take 26 inspect statements.
move WORK-BUFFER to TEST-BUFFER
inspect TEST-BUFFER replacing all 'a' by 'A'
inspect TEST-BUFFER replacing all 'b' by 'B'
inspect TEST-BUFFER replacing all 'c' by 'C'
display TEST-01 upon console
display TEST-02 upon console
display TEST-03 upon console
* Move the UPPER-case content of the TEST-BUFFER to the
* STOP-BUFFER. The single inspect statements will do an UPPER
* to lower case conversion.
move TEST-BUFFER to LAST-BUFFER
inspect LAST-BUFFER converting UPPER-CASE to LOWER-CASE
display LAST-01 upon console
display LAST-02 upon console
display LAST-03 upon console
* At this point the lower case content of the primary
* WORK-BUFFER should equal the content of the STOP-BUFFER
* that is the result of multiple conversions of the data that
* wraps around back to lower case content.
if LAST-BUFFER = WORK-BUFFER
display 'CPYREPC1 is Finished...' upon console
move 0 to RETURN-CODE
else
display 'CPYREPC1 is ABENDING...' upon console
move 16 to RETURN-CODE
end-if
GOBACK.
The following (CPYREPC1.LST) is a sample of the Micro Focus COBOL demonstration program. This program was tested using Micro Focus Net Express, version 4.0 and Mainframe Express running on Windows/XP.
* C:\Assist01\MFE1\COBOL\CPYREPC1.CBL
* Options: NOLIST NOASMLIST OBJ(.\) GNT(.\) wb3 nocoboldir DIALECT(ENTCOBOL)
* AMODE(31) DATA(31) FLAGAS(S) NOTRUNC NOCOMP ADV NOSSRANGE NOCMPR2
* DEFAULTBYTE(00) NODYNAM NOFLAGMIG NOSEQCHK ZWB FORM(60)
* LISTWIDTH(80) MAX-ERROR(100) NOPANVALET NOLIBRARIAN WARNING(1)
* NODATAMAP ANIM CSI LIST() NORESEQ NOXREF NOGNT NOSETTING
* COPYEXT(CPY) assign(external) LISTPATH("C:\Assist01\MFE1\LISTING/")
* COBIDY INT("C:\Assist01\MFE1\LOADLIB/") DELGNT wb3 ensuite"3"
* editor"MF2"
IDENTIFICATION DIVISION.
PROGRAM-ID. CPYREPC1.
DATA DIVISION.
*****************************************************************
WORKING-STORAGE SECTION.
* The following copy file defines two alphabetic tables to be
* used for case conversion.
*copy CASEVARY.
*****************************************************************
* The following two data structures are used to convert data
* strings between lower and UPPER case.
01 LOWER-CASE PIC X(26) VALUE 'abcdefghijklmnopqrstuvwxyz'.
01 UPPER-CASE PIC X(26) VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
* CASEVARY, End of Copy File...
* The following uses the same copy file to create three uniquely
* named buffers or data structures of identical format.
*copy CPYREPB1 replacing ==:ZZZZ:== by ==WORK==.
*****************************************************************
* The following is used with a copy statement with replace to
* create a multiple number of uniquely named data structures of
* similar format.
01 WORK-BUFFER.
05 WORK-01 pic x value SPACE.
05 WORK-02 pic x(2) value SPACES.
05 WORK-03 pic x(3) value SPACES.
* CPYREPB1, End of Copy File...
*copy CPYREPB1 replacing ==:ZZZZ:== by ==TEST==.
*****************************************************************
* The following is used with a copy statement with replace to
* create a multiple number of uniquely named data structures of
* similar format.
01 TEST-BUFFER.
05 TEST-01 pic x value SPACE.
05 TEST-02 pic x(2) value SPACES.
05 TEST-03 pic x(3) value SPACES.
* CPYREPB1, End of Copy File...
*copy CPYREPB1 replacing ==:ZZZZ:== by ==LAST==.
*****************************************************************
* The following is used with a copy statement with replace to
* create a multiple number of uniquely named data structures of
* similar format.
01 LAST-BUFFER.
05 LAST-01 pic x value SPACE.
05 LAST-02 pic x(2) value SPACES.
05 LAST-03 pic x(3) value SPACES.
* CPYREPB1, End of Copy File...
*****************************************************************
* C:\Assist01\MFE1\COBOL\CPYREPC1.CBL REPB1.CPY)
PROCEDURE DIVISION.
move 0 to RETURN-CODE
display 'CPYREPC1 is Starting...' upon console
* Move lower case letters to WORK-BUFFER and display contents
* by indivdual fields within buffer.
move 'a' to WORK-01
move 'ab' to WORK-02
move 'abc' to WORK-03
display WORK-01 upon console
display WORK-02 upon console
display WORK-03 upon console
* Move the lower-case content of the WORK-BUFFER to the
* TEST-BUFFER. The three inspect statements will do a lower to
* UPPER case conversion of the letters a, b and c. To convert
* the entire alphabet would take 26 inspect statements.
move WORK-BUFFER to TEST-BUFFER
inspect TEST-BUFFER replacing all 'a' by 'A'
inspect TEST-BUFFER replacing all 'b' by 'B'
inspect TEST-BUFFER replacing all 'c' by 'C'
display TEST-01 upon console
display TEST-02 upon console
display TEST-03 upon console
* Move the UPPER-case content of the TEST-BUFFER to the
* STOP-BUFFER. The single inspect statements will do an UPPER
* to lower case conversion.
move TEST-BUFFER to LAST-BUFFER
inspect LAST-BUFFER converting UPPER-CASE to LOWER-CASE
display LAST-01 upon console
display LAST-02 upon console
display LAST-03 upon console
* At this point the lower case content of the primary
* WORK-BUFFER should equal the content of the STOP-BUFFER
* that is the result of multiple conversions of the data that
* wraps around back to lower case content.
if LAST-BUFFER = WORK-BUFFER
display 'CPYREPC1 is Finished...' upon console
move 0 to RETURN-CODE
else
display 'CPYREPC1 is ABENDING...' upon console
move 16 to RETURN-CODE
end-if
GOBACK.
*
*
* Errors
* -Line- Col Code/severity Description
* Micro Focus IDE V3.0 revision 000 Compiler
* Total Messages: 0
* Data: 1436 Code: 1321
The purpose of this program is to provide an example of using the "REPLACING" function within a copy file used within a COBOL program.
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 download this example at http://www.simotime.com/sim4dzip.htm#COBOLCopyReplacing 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.
To review all the information available on this site start at The SimoTime Home Page .
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 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 complimentary 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 |
| Version 06.09.27 |