Search and Replace Different Length Text Strings |
The SimoTime Home Page |
This suite of COBOL programs and Job Scripts will show how to search and replace a text string value within a field with a text string value of a different length. This example contains two COBOL programs. The first is a demonstration program that creates fields with text, replacement arguments and replacement values. The second COBOL routine does the actual searching and replacement of the text string.
This may appear like a simple task that could be solved by a single line of code using the INSPECT statement as follows.
INSPECT field-name REPLACING FIRST 'abc' BY 'uvwxyz'.
However, the preceding statement will generate an error since the INSPECT statement requires the search value and the replacement value to be of equal lengths.
This suite of programs contains three job scripts. A JCL member is provided to run the job as an MVS batch job on an IBM Mainframe System or as a project with Micro Focus Mainframe Express (MFE) running on a Windows System. A CMD member is provided to run the job with Micro Focus Net Express (MFE) running on a Windows System. A Bash Script File is provided to run the job on a Linux or UNIX System and GnuCOBOL (formerly known as Open COBOL) is used to compile the COBOL Programs.
Note: The COBOL language also has a REPLACING function that is used to replace text strings in a COBOL copy file at compile time. For more information about this function refer to the COPY REPLACING document available on the SimoTime web site. Refer to the Downloads and Links to Similar Pages section of this document.
We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.
Copyright © 1987-2025
SimoTime Technologies and Services
All Rights Reserved
This suite of samples programs will run on the following platforms.
| ||||||
Supported Operating Systems and COBOL Technologies |
The following diagram is an overview of the program flow during job execution.
Color Associations: The Call InterfaceThe following is the call statement that is used to call the COBOL routine that does the string substitution within a field. CALL 'SIMOSUB1' USING SUBSTITUTE-PARAMETERS. The following are the fields that are passed from the demonstration program to the routine that does the actual string substitution within the field. 01 SUBSTITUTE-PARAMETERS. 05 SUB-BUFFER-SOURCE pic X(128). 05 SUB-BUFFER-TARGET pic X(256). 05 SUB-SEARCH-STRING pic X(32). 05 SUB-REPLACE-STRING pic X(32). 05 SUB-SEARCH-LENGTH pic 9(2). 05 SUB-REPLACE-LENGTH pic 9(2). The following describes each of the fields that are passed to the COBOL routine. The SUB-BUFFER-TARGET field is the only field that is modified by the search-and-replace routine (SIMOSUB1).
Sample OutputThe following is the output produced by this suite of programs. * CBLREPC1 Text String Replacement v15.01.24 http://www.simotime.com * CBLREPC1 Copyright 1987-2015 SimoTime Technologies All Rights Reserved * CBLREPC1 1-Before, replace >abc< with xyz * CBLREPC1 1-After, replace >xyz< with xyz * CBLREPC1 2-Before, replace >abc< with uvwxyz * CBLREPC1 2-After, replace >uvwxyz< with uvwxyz * CBLREPC1 3-Before, replace >abc< with M * CBLREPC1 3-After, replace >M< with M * CBLREPC1 ENTER, EXAMPLE-004 * CBLREPC1 ABCDEFGHIJKLMNOPQRSTUVWXYZ * CBLREPC1 ABC123GHIJKLMNOPQRSTUVWXYZ * CBLREPC1 LEAVE, EXAMPLE-004 * CBLREPC1 ENTER, EXAMPLE-005 * CBLREPC1 Hello World... * CBLREPC1 Goodbye World... * CBLREPC1 LEAVE, EXAMPLE-005 * CBLREPC1 ENTER, EXAMPLE-006 * CBLREPC1 # to the World... * CBLREPC1 Joy to the World... * CBLREPC1 LEAVE, EXAMPLE-006 * CBLREPC1 Thank you for using this program provided from SimoTime Technologies * CBLREPC1 Please send all inquires or suggestions to the helpdesk@simotime.com This output is written to the file that is mapped to the SYSOUT environment variable. For example Job ScriptsA job script may be defined as a text file containing job setup information followed by job steps that identify programs to be executed along with parameters unique to the job step. A job script may be created using a text editor. The naming of a job script is determined by the Operating System. A simple job script may contain a single job step that performs a single function. A typical job script will contain multiple job steps executed in a predefined sequence. The status of each job step may be tested at the end of each job step. CMD MemberThe following is the CMD member (CBLREPE1.cmd) used to run the job on a Windows System using Micro Focus Enterprise Server. @echo OFF rem * ******************************************************************* rem * CBLREPE1.cmd - a Windows Command File * rem * This program is provided by SimoTime Technologies * rem * (C) Copyright 1987-2019 All Rights Reserved * rem * Web Site URL: http://www.simotime.com * rem * e-mail: helpdesk@simotime.com * rem * ******************************************************************* rem * rem * Text - COBOL does string replacment for different length items rem * Author - SimoTime Technologies rem * Date - January 01, 1987 rem * Version - 04.08.20 rem * rem * This set of programs illustrate the use a COBOL program to do rem * replacement of a text string with a text string of a different rem * length. rem * rem * This set of programs will run on a Personal Computer with Windows rem * and Micro Focus Net Express. rem * rem * ************ rem * * CBLREPE1 * rem * ********cmd* rem * * rem * ************ ************ rem * * SIMOEXEC ******* CONSOLE * rem * ********exe* ************ rem * * * rem * * * rem * * * ************ ************ rem * * ***call*** CBLREPC1 ******* CONSOLE * rem * * ********cbl* ************ rem * * * rem * * * rem * * ************ rem * * * SIMOSUB1 * rem * * ********cbl* rem * * rem * ************ rem * * EOJ * rem * ************ rem * rem * ******************************************************************** rem * Step 1 of 2 Set the global environment variables... rem * call ..\Env1BASE if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG set CmdName=CBLREPE1 rem * call SimoNOTE "*******************************************************%CmdName%" call SimoNOTE "Starting JobName %CmdName%" rem * ******************************************************************** rem * Step 2 of 2 Execute the sample program... rem * call SimoNOTE "SYSOUT is %SYSOUT%" run CblRepC1 rem * call SimoNOTE "Finished JobName %CmdName%, Job Status is %JobStatus%" start NOTEPAD.exe %SYSOUT% :End if not "%1" == "nopause" pause JCL MemberThe following is the JCL member (CBLREPJ1.jcl) used to run the job on an IBM Mainframe System with ZOS or a Linux, UNIX or Windows System using Micro Focus Enterprise Server. //CBLREPJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=A,NOTIFY=CSIP1 //* ******************************************************************* //* CBLREPJ1.JCL - a JCL Member for Batch Job Processing * //* This JCL Member is provided by SimoTime Technologies * //* (C) Copyright 1987-2019 All Rights Reserved * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - COBOL does string replacement for different length items //* Author - SimoTime Technologies //* Date - January 01, 1987 //* //* This set of programs illustrate the use a COBOL program to do //* replacement of a text string with a text string of a different //* length. //* //* This set of programs will run on a mainframe under MVS or on //* a Personal Computer running Windows and Mainframe Express by //* Micro Focus. //* //* ************ //* * CBLREPJ1 * //* ********jcl* //* * //* * //* ************ ************ //* * CBLREPC1 *-----* CONSOLE * //* ********cbl* ************ //* * * //* * * //* * * ************ //* * ***call*** SIMOSUB1 * //* * ********cbl* //* * //* ************ //* * EOJ * //* ************ //* //* ******************************************************************* //* Step 1 of 1, This is a single step job. //* //CBLREPS1 EXEC PGM=CBLREPC1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //SYSOUT DD SYSOUT=* //* Bash Script FileThe following is the Bash Shell Script (cblreps1.sh) that is required to run as a job on a Linux or UNIX System. For this test case the COBOL programs were compiled and executed on a Linux (Ubuntu) System using GnuCOBOL. #!/bin/bash JOBNAME=cblreps1 # * ******************************************************************* # * Bash Script File - provided by SimoTime Technologies * # * (C) Copyright 1987-2018 All Rights Reserved * # * Web Site URL: http://www.simotime.com * # * e-mail: helpdesk@simotime.com * # * ******************************************************************* # * # * Text - COBOL does string replacment for different length items # * Author - SimoTime Technologies # * Date - November 11, 2003 # * Version - 06.07.16 # * # * This set of programs illustrate the use a COBOL program to do # * replacement of a text string with a text string of a different # * length. # * # * ************ # * * cblreps1 * # * *********sh* # * * # * * # * ************ ************ ************ # * * cobrunc ******* CBLREPC1 ******* CONSOLE * # * ************ ********cbl* ************ # * * * # * * * # * * ************ # * * * SIMOSUB1 * # * * ********cbl* # * * # * ************ # * * EOJ * # * ************ # * # * ******************************************************************** # * Step 1 of 2, Set the environment variables... # * JOBSTATUS=0 export BASESYS1=/home/larry/SIMOSY76 export COB_LIBS=$BASESYS1/SIMOSAM1/DEVL/LOADLIB:$BASESYS1/SIMOLIBR export COB_LIBRARY_PATH=$BASESYS1/SIMOSAM1/DEVL/LOADLIB:$BASESYS1/SIMOLIBR export SIMONOTE=$BASESYS1/LOGS/SYSOUT_BASHUSER_$JOBNAME.txt simonote.sh "Starting - Job Name is $JOBNAME" # * # * ******************************************************************** # * Step 2 of 2, Run the programs, COBOL doing Search and Replace... # * cobcrun CBLREPC1 rc=$? if [ $rc != 0 ] then simonote.sh "# ABENDING $name - Return Code is $rc" fi # * # * ******************************************************************** # * Step 3 of 3, End of Job Processing. # * if [ "$JOBSTATUS" = "0" ] then simonote.sh "# Finished Job Name $JOBNAME" else simonote.sh "# ABENDING Job Name $JOBNAME" fi COBOL Demonstration ProgramThe following is the source code (CBLREPC1.cbl) for the COBOL demonstration program that contains test data and calls the search-and-replace routine. IDENTIFICATION DIVISION. PROGRAM-ID. CBLREPC1. AUTHOR. SIMOTIME TECHNOLOGIES. ***************************************************************** * Copyright (C) 1987-2019 SimoTime Technologies. * * * * 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 Technologies. 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 * * Technologies. * * * * 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 * * Technologies. * * * * SimoTime Technologies makes no warranty or representations * * about the suitability of the software for any purpose. It is * * provided "AS IS" without any expressed or implied warranty, * * including the implied warranties of merchantability, fitness * * for a particular purpose and non-infringement. SimoTime * * Technologies 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 Technologies * * 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 Technologies, * * 15 Carnoustie Drive, Novato, CA 94949-5849. * * * ***************************************************************** * This program is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * * * ***************************************************************** * ***************************************************************** * Source Member: CBLREPC1.CBL * Copy Files: PASSSUB1.CPY * Calls to: SIMOSUB1 ***************************************************************** * * CBLREPC1 - 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 within a field with a text string of a different length. * * ************ * * CBLREPJ1 * * ********jcl* * * * * * ************ ************ * * CBLREPC1 *-----* CONSOLE * * ********cbl* ******dsply* * * * * * * * * * ************ * * ***call*** SIMOSUB1 * * * ********cbl* * * * * * ************ * * EOJ * * ************ * ***************************************************************** * * MAINTENANCE * ----------- * 1987/05/22 Simmons, Created program. * 1994/04/17 Simmons, Updated for PC. * ***************************************************************** * ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. ***************************************************************** * Data-structure for Title and Copyright... * ------------------------------------------------------------ 01 SIM-TITLE. 05 T1 pic X(11) value '* CBLREPC1 '. 05 T2 pic X(34) value 'Text String Replacement '. 05 T3 pic X(10) value ' v15.01.24'. 05 T4 pic X(24) value ' http://www.simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* CBLREPC1 '. 05 C2 pic X(20) value 'Copyright 1987-2019 '. 05 C3 pic X(28) value ' SimoTime Technologies '. 05 C4 pic X(20) value ' All Rights Reserved'. 01 SIM-THANKS-01. 05 C1 pic X(11) value '* CBLREPC1 '. 05 C2 pic X(32) value 'Thank you for using this program'. 05 C3 pic X(32) value ' provided from SimoTime Technolo'. 05 C4 pic X(04) value 'gies'. 01 SIM-THANKS-02. 05 C1 pic X(11) value '* CBLREPC1 '. 05 C2 pic X(32) value 'Please send all inquires or sugg'. 05 C3 pic X(32) value 'estions to the helpdesk@simotime'. 05 C4 pic X(04) value '.com'. ***************************************************************** * Message Buffer used by the Z-DISPLAY-MESSAGE-TEXT routine. * ***************************************************************** 01 MESSAGE-BUFFER. 05 MESSAGE-HEADER pic X(11) value '* CBLREPC1 '. 05 MESSAGE-TEXT. 10 MESSAGE-TEXT-1 pic X(68) value SPACES. 10 MESSAGE-TEXT-2 pic X(188) value SPACES. COPY PASSSUB1. ***************************************************************** PROCEDURE DIVISION. perform Z-POST-COPYRIGHT perform EXAMPLE-001 perform EXAMPLE-002 perform EXAMPLE-003 perform EXAMPLE-004 perform EXAMPLE-005 perform EXAMPLE-006 perform Z-THANK-YOU. GOBACK. ***************************************************************** * Example 1, Replace a text string with a text string * of equal size. EXAMPLE-001. move '1-Before, replace >abc< with xyz' to SUB-BUFFER-SOURCE move 'abc' to SUB-SEARCH-STRING move 'xyz' to SUB-REPLACE-STRING add 3 to ZERO giving SUB-SEARCH-LENGTH add 3 to ZERO giving SUB-REPLACE-LENGTH call 'SIMOSUB1' using SUBSTITUTE-PARAMETERS * Display the contents of the Source and Target Buffers. move SUB-BUFFER-SOURCE(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT inspect SUB-BUFFER-TARGET replacing first 'Before, ' by 'After, ' move SUB-BUFFER-TARGET(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * Example 2, Replace a text string with a text string * of greater size. EXAMPLE-002. move '2-Before, replace >abc< with uvwxyz' to SUB-BUFFER-SOURCE move 'abc' to SUB-SEARCH-STRING move 'uvwxyz' to SUB-REPLACE-STRING add 3 to ZERO giving SUB-SEARCH-LENGTH add 6 to ZERO giving SUB-REPLACE-LENGTH call 'SIMOSUB1' using SUBSTITUTE-PARAMETERS * Display the contents of the Source and Target Buffers. move SUB-BUFFER-SOURCE(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT inspect SUB-BUFFER-TARGET replacing first 'Before, ' by 'After, ' move SUB-BUFFER-TARGET(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * Example 3, Replace a text string with a text string * of smaller size. EXAMPLE-003. move '3-Before, replace >abc< with M' to SUB-BUFFER-SOURCE move 'abc' to SUB-SEARCH-STRING move 'M' to SUB-REPLACE-STRING add 3 to ZERO giving SUB-SEARCH-LENGTH add 1 to ZERO giving SUB-REPLACE-LENGTH call 'SIMOSUB1' using SUBSTITUTE-PARAMETERS * Display the contents of the Source and Target Buffers. move SUB-BUFFER-SOURCE(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT inspect SUB-BUFFER-TARGET replacing first 'Before, ' by 'After, ' move SUB-BUFFER-TARGET(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * Example 4, Replace a text string with a text string * of equal size. EXAMPLE-004. move 'ENTER, EXAMPLE-004' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' to SUB-BUFFER-SOURCE move 'DEF' to SUB-SEARCH-STRING move '123' to SUB-REPLACE-STRING add 3 to ZERO giving SUB-SEARCH-LENGTH add 3 to ZERO giving SUB-REPLACE-LENGTH call 'SIMOSUB1' using SUBSTITUTE-PARAMETERS * Display the contents of the Source and Target Buffers. move SUB-BUFFER-SOURCE(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move SUB-BUFFER-TARGET(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move 'LEAVE, EXAMPLE-004' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * Example 5, Replace a text string with a text string * of a larger size size. EXAMPLE-005. move 'ENTER, EXAMPLE-005' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move 'Hello World...' to SUB-BUFFER-SOURCE move 'Hello' to SUB-SEARCH-STRING move 'Goodbye' to SUB-REPLACE-STRING add 5 to ZERO giving SUB-SEARCH-LENGTH add 7 to ZERO giving SUB-REPLACE-LENGTH call 'SIMOSUB1' using SUBSTITUTE-PARAMETERS * Display the contents of the Source and Target Buffers. move SUB-BUFFER-SOURCE(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move SUB-BUFFER-TARGET(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move 'LEAVE, EXAMPLE-005' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * Example 6, Replace a text string with a text string * of a larger size size. EXAMPLE-006. move 'ENTER, EXAMPLE-006' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move '# to the World...' to SUB-BUFFER-SOURCE move '#' to SUB-SEARCH-STRING move 'Joy' to SUB-REPLACE-STRING add 1 to ZERO giving SUB-SEARCH-LENGTH add 3 to ZERO giving SUB-REPLACE-LENGTH call 'SIMOSUB1' using SUBSTITUTE-PARAMETERS * Display the contents of the Source and Target Buffers. move SUB-BUFFER-SOURCE(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move SUB-BUFFER-TARGET(1:71) to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT move 'LEAVE, EXAMPLE-006' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * The following Z-Routines perform administrative tasks * * for this program. * ***************************************************************** Z-POST-COPYRIGHT. move SIM-TITLE to MESSAGE-BUFFER perform Z-DISPLAY-MESSAGE-TEXT move SIM-COPYRIGHT to MESSAGE-BUFFER perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * Display CONSOLE messages... * ***************************************************************** Z-DISPLAY-MESSAGE-TEXT. if MESSAGE-TEXT-2 = SPACES display MESSAGE-BUFFER(1:79) else display MESSAGE-BUFFER end-if move all SPACES to MESSAGE-TEXT exit. ***************************************************************** Z-THANK-YOU. move SIM-THANKS-01 to MESSAGE-BUFFER perform Z-DISPLAY-MESSAGE-TEXT move SIM-THANKS-02 to MESSAGE-BUFFER perform Z-DISPLAY-MESSAGE-TEXT exit. ***************************************************************** * This example is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * ***************************************************************** COBOL Search-&-Replace RoutineThe following is the source code (SIMOSUB1.cbl) for the COBOL search and replace routine. If the length of the search-text and replacement-text are equal then a simple INSPECT statement will perform the task, If the lengths are different then additional processing is required. IDENTIFICATION DIVISION. PROGRAM-ID. SIMOSUB1. *AUTHOR. SIMOTIME TECHNOLOGIES. ***************************************************************** * Copyright (C) 1987-2019 SimoTime Technologies. * * * * 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 Technologies. 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 * * Technologies. * * * * 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 * * Technologies. * * * * SimoTime Technologies makes no warranty or representations * * about the suitability of the software for any purpose. It is * * provided "AS IS" without any expressed or implied warranty, * * including the implied warranties of merchantability, fitness * * for a particular purpose and non-infringement. SimoTime * * Technologies 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 Technologies * * 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 Technologies, * * 15 Carnoustie Drive, Novato, CA 94949-5849. * * * ***************************************************************** * This program is provided by SimoTime Technologies * * 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 * * *---call---* ******dsply* * * SIMOSUB1 * * ********cbl* * * * * * ************ * * EOJ * * ************ * ***************************************************************** * * 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 add 1 to ZERO giving I-1 add 1 to ZERO giving I-2 perform until I-1 > SOURCE-SIZE - SUB-SEARCH-LENGTH or I-2 > TARGET-SIZE - SUB-REPLACE-LENGTH if SUB-BUFFER-SOURCE(I-1:1) not = SUB-SEARCH-STRING(1:1) move SUB-BUFFER-SOURCE(I-1:1) to SUB-BUFFER-TARGET(I-2:1) add 1 to I-1 add 1 to I-2 else if SUB-BUFFER-SOURCE(I-1:SUB-SEARCH-LENGTH) not = SUB-SEARCH-STRING move SUB-BUFFER-SOURCE(I-1:1) to SUB-BUFFER-TARGET(I-2:1) add 1 to I-1 add 1 to I-2 else move SUB-REPLACE-STRING to SUB-BUFFER-TARGET(I-2:SUB-REPLACE-LENGTH) add SUB-SEARCH-LENGTH to I-1 add SUB-REPLACE-LENGTH to I-2 end-if end-if end-perform exit. ***************************************************************** * This example is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * ***************************************************************** Pass Area, COBOL Copy FileThe following is the source listing for the COBOL Copy File (PASSSUB1.cpy) that defines the structure for a pass area in memory and is referenced when calling the search-and-replace routine. ***************************************************************** * Data Structure or Pass Area used for calling SIMOSUB1. * ***************************************************************** * Copyright (C) 1987-2019 SimoTime Technologies * * All Rights Reserved * ***************************************************************** * Provided by SimoTime Technologies * * 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(1024). 05 SUB-BUFFER-TARGET pic X(1024). 05 SUB-SEARCH-STRING pic X(128). 05 SUB-REPLACE-STRING pic X(128). 05 SUB-SEARCH-LENGTH pic 9(3). 05 SUB-REPLACE-LENGTH pic 9(3). *** PASSSUB1 - End-of-Copy File - - - - - - - - - - - PASSSUB1 * ***************************************************************** * SummaryThis suite of programs is provided as a COBOL programming example of one of the possible solutions to the problem of searching a data field and replacing a text string within the field with a text string of a different length. This document may be used as a tutorial for new programmers or as a quick reference for experienced programmers. In the world of programming there are many ways to solve a problem. This documentation and software were developed and tested on systems that are configured for a SIMOTIME environment based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be needed to execute the jobs and programs when transferred to a system of a different architecture or configuration. SIMOTIME Services has experience in moving or sharing data or application processing across a variety of systems. For additional information about SIMOTIME Services or Technologies please contact us using the information in the Contact or Feedback section of this document.
Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Technologies. Once the fee is received by SimoTime the latest version of the software, documentation or training material 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 Technologies. SimoTime Technologies makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Technologies 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, documentation or training material. Downloads and LinksThis section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an internet connection, the second group of documents will require an internet connection. Note: A SimoTime License is required for the items to be made available on a local system or server. Current Server or Internet AccessThe following links may be to the current server or to the Internet. Note: The latest versions of the SimoTime Documents and Program Suites are available on the Internet and may be accessed using the icon. If a user has a SimoTime Enterprise License the Documents and Program Suites may be available on a local server and accessed using the icon. Explore COPY REPLACING function defined by the COBOL specifications. This suite of sample programs describes how to use the replacing function with a copy file in a COBOL program. Explore the JCL Connection for more examples of JCL functionality with programming techniques and sample code. Explore the COBOL Connection for more examples of COBOL programming techniques and sample code. Explore An Enterprise System Model that describes and demonstrates how Applications that were running on a Mainframe System and non-relational data that was located on the Mainframe System were copied and deployed in a Microsoft Windows environment with Micro Focus Enterprise Server. Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats. Explore The File Status Return Codes that are used to interpret the results of accessing VSAM data sets and/or QSAM files. Internet Access RequiredThe following links will require an internet connect. This suite of programs and documentation is available to download for review and evaluation purposes. Other uses will require a SimoTime Software License. Link to an Evaluation zPAK Option that includes the program members, documentation and control files. A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection Explore The Micro Focus Web Site for more information about products (including Micro Focus COBOL) and services available from Micro Focus. This link requires an Internet Connection. Glossary of TermsExplore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers. Contact or FeedbackThis document was created and is maintained by SimoTime Technologies. If you have any questions, suggestions, comments or feedback please use the following contact information.
We appreciate hearing from you. Company OverviewSimoTime Technologies was founded in 1987 and 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. Our customers include small businesses using Internet technologies to corporations using very large mainframe systems. 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. We specialize in preparing applications and the associated data that are currently residing on a single platform to be distributed across a variety of platforms. Preparing the application programs will require the transfer of source members that will be compiled and deployed on the target platform. The data will need to be transferred between the systems and may need to be converted and validated at various stages within the process. SimoTime has the technology, services and experience to assist in the application and data management tasks involved with doing business in a multi-system environment. 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
|