![]() |
A Text Search and Replace SimoSUB1 - The COBOL Source Code http://www.simotime.com |
| When technology complements business | Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
This document provides a listing of the COBOL source code for viewing. Additional information about this program may be obtained by sending an e-mail to: helpdesk@simotime.com
The SimoSUB1 routine (or callable program) will search a field to find a text string (based on a search-value). If a match is found the matching value will be replaced with a new text string (based on a replacement-value). The text strings for the search-value and replacement-value may be different lengths.
The following will create a new text string in the target field with the "DEF" replaced by "123".
MOVE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' to SUB-BUFFER-SOURCE
MOVE SPACES to SUB-BUFFER-TARGET
MOVE 'DEF' to SUB-SEARCH-STRING
MOVE '123' to SUB-REPLACE-STRING
move 3 to SUB-SEARCH-LENGTH
move 3 to SUB-REPLACE-LENGTH
CALL 'SIMOSUB1' using SUBSTITUTE-PARAMETERS
In the preceding example the contents of SUB-SEARCH-STRING will be 'ABC123GHIJKLMNOPQRSTUVWXYZ' upon return from the call to SIMOSUB1.
A copy file is provided to define the pass area to be used when calling SimoSUB1. The following statement is required in the WORKING STORAGE section of the calling program.
WORKING STORAGE.
...
...
COPY PASSSUB1.
The callable search-replace routine will accept a string of numbers up to twelve (12) digits. A Working Storage data structure for calling the SIMOSUB1 routine is required. A copy file (PASSSUB1.CPY) is provided with the following fields defined.
*****************************************************************
* Data Structure or Pass Area used for calling SIMOSUB1. *
*****************************************************************
* Copyright (C) 1987-2004 SimoTime Enterprises *
* All Rights Reserved *
*****************************************************************
* Provided by SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
*****************************************************************
* SUB-BUFFER-SOURCE - This field contains the text with data *
* to be replaced. This field is not *
* modified by the SimoSUB1 routine. *
* SUB-BUFFER-TARGET - This field contains the text with data *
* that will be modified by the SimoSUB1 *
* routine. *
* SUB-SEARCH-STRING - This field contains the text string for *
* the search value. *
* SUB-REPLACE-STRING - This field contains the text string for *
* the replace value. *
* SUB-SEARCH-LENGTH - This field defines the length of the *
* search string. *
* SUB-REPLACE-LENGTH - This field defines the length of the *
* replace value. *
*****************************************************************
01 SUBSTITUTE-PARAMETERS.
05 SUB-BUFFER-SOURCE pic X(256).
05 SUB-BUFFER-TARGET pic X(320).
05 SUB-SEARCH-STRING pic X(48).
05 SUB-REPLACE-STRING pic X(48).
05 SUB-SEARCH-LENGTH pic 9(2).
05 SUB-REPLACE-LENGTH pic 9(2).
*! PASSSUB1 - End-of-Copy File...
The following is the COBOL Source Code for SimoSUB1.
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMOSUB1.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2009 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 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 and modify 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. *
* *
* 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: SIMOSUB1.CBL
*****************************************************************
*
* SIMOSUB1 - String replacement of varying lengths.
*
* CALLING PROTOCOL
* ----------------
* Use standard procedure to RUN or ANIMATE.
*
* DESCRIPTION
* -----------
* This program provides an example of how to replace a text
* string with is field with a text string of a different length.
*
* ************
* * CBLREPJ1 *
* ********jcl*
* *
* *
* ************ ************
* * CBLREPC1 *-----* CONSOLE *
* ********cbl* ******dsply*
* *
* *
* ************
* * SIMOSUB1 *
* ********cbl*
*
*****************************************************************
*
* MAINTENANCE
* -----------
* 1987/05/22 Simmons, Created program.
* 1994/04/17 Simmons, Updated for PC.
*
*****************************************************************
*
ENVIRONMENT DIVISION.
DATA DIVISION.
*****************************************************************
WORKING-STORAGE SECTION.
01 I-1 pic 9(5) value 0.
01 I-2 pic 9(5) value 0.
01 SUB-PTR pic 9(5) value 0.
01 SOURCE-SIZE pic 9(5) value 0.
01 TARGET-SIZE pic 9(5) value 0.
*****************************************************************
LINKAGE SECTION.
COPY PASSSUB1.
*****************************************************************
PROCEDURE DIVISION using SUBSTITUTE-PARAMETERS .
if SUB-SEARCH-LENGTH = SUB-REPLACE-LENGTH
move SUB-BUFFER-SOURCE to SUB-BUFFER-TARGET
inspect SUB-BUFFER-TARGET replacing
all SUB-SEARCH-STRING(1:SUB-SEARCH-LENGTH)
by SUB-REPLACE-STRING(1:SUB-REPLACE-LENGTH)
else
perform INSPECT-AND-REPLACE-EXTENDED
end-if
GOBACK.
*****************************************************************
INSPECT-AND-REPLACE-EXTENDED.
add length of SUB-BUFFER-SOURCE to ZERO giving SOURCE-SIZE
add length of SUB-BUFFER-TARGET to ZERO giving TARGET-SIZE
move SPACES to SUB-BUFFER-TARGET
subtract SUB-PTR from SUB-PTR
inspect SUB-BUFFER-SOURCE
tallying SUB-PTR
for CHARACTERS
before initial SUB-SEARCH-STRING(1:SUB-SEARCH-LENGTH)
if SUB-PTR < SOURCE-SIZE - 1
add 1 to SUB-PTR giving I-1
add 1 to SUB-PTR giving I-2
move SPACES to SUB-BUFFER-TARGET
move SUB-BUFFER-SOURCE(1:SUB-PTR) to SUB-BUFFER-TARGET
move SUB-REPLACE-STRING(1:SUB-REPLACE-LENGTH)
to SUB-BUFFER-TARGET(I-2:SUB-REPLACE-LENGTH)
add SUB-SEARCH-LENGTH to I-1
add SUB-REPLACE-LENGTH to I-2
move SUB-BUFFER-SOURCE(I-1:SOURCE-SIZE - I-1)
to SUB-BUFFER-TARGET(I-2:TARGET-SIZE - I-2)
else
move SUB-BUFFER-SOURCE to SUB-BUFFER-TARGET
end-if
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 the SimoSUB1 routine at http://www.simotime.com/cblrep01.htm.
You may view the complete list of SimoTime callable Modules or Driver Programs at http://www.simotime.com/simomods.htm.
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. SimoZAPScan 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 Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.
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.
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 .
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 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 |