Search and Replace
Different Length Text Strings
  Table of Contents  v-16.01.01 - cblrep01.htm 
  Introduction
  Call Interface
  Sample Output
  CMD Member
  JCL Member
  COBOL Demonstration Program
  COBOL Search-&-Replace Routine
  Pass Area, COBOL Copy File
  Summary
  Software Agreement and Disclaimer
  Downloads and Links
  Current Server or Internet Access
  Internet Access Required
  Glossary of Terms
  Comments or Feedback
  Company Overview
The SimoTime Home Page 

Table of Contents Previous Section Next Section Introduction

This suite of sample COBOL programs 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.

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.

             
Entry Point
ZOS or MFE
Entry Point
Windows
   
   
CBLREPJ1
jcl
CBLREPE1
cmd
Submit the Job
   
   
 
 
   
   
 
 
   
   
CBREPC1
cbl
   
   
CONSOLE
display
Replace string within Field
   
   
   
   
   
SIMOSUB1
cbl
Callable Search/Replace Routine
   
EOJ
End-Of-Job
 
Replacing a String within a Field

Color Associations: The  light-green  boxes are unique to the Mainframe and Micro Focus Enterprise Server/Studio (or Micro Focus Mainframe Express). The  light-red  boxes are unique to a Windows System and Micro Focus technologies. The  light-yellow  boxes are decision points or program transitions in the processing logic or program generations. The  light-blue  boxes identify the input/output data structures such as Documents, Spreadsheets, Data Files, VSAM Data Sets or Relational Tables. The  light-gray  boxes identify a system function or information item.


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-2017
SimoTime Technologies
All Rights Reserved

Table of Contents Previous Section Next Section Call Interface

The 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).

Parameter Description
SUB-BUFFER-SOURCE This field should contain the data with the possible text string to be changed.
SUB-BUFFER-TARGET The contents of this field is modified by the COBOL search-and-replace routine (SIMOSUB1). If a match is found from the search argument (SUB-SEARCH-STRING) it is replaced with the replacement value (SUB-REPLACE-STRING).
SUB-SEARCH-STRING This field is the search argument.
SUB-REPLACE-STRING This field is the replacement value.
SUB-SEARCH-LENGTH This field is the length of the search argument.
SUB-REPLACE-LENGTH This field is the length of the replacement value.
  A Description of the Fields in the Pass Area

Table of Contents Previous Section Next Section Sample Output

The 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
set SYSOUT=C:\MYDIR\SYSOUT_CBLREP01.TXT
will map the logical SYSOUT device to a physical file name.

Table of Contents Previous Section Next Section CMD Member

The 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-2017 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

Table of Contents Previous Section Next Section JCL Member

The 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-2017 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=*
//*

Table of Contents Previous Section Next Section COBOL Demonstration Program

The 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-2017 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-2017 '.
           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       *
      *****************************************************************

Table of Contents Previous Section Next Section COBOL Search-&-Replace Routine

The 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-2017 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  *
      *          ********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
           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.

      *****************************************************************
       INSPECT-AND-REPLACE-EXTENDED-OLD.
           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 Technologies        *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

Table of Contents Previous Section Next Section Pass Area, COBOL Copy File

The 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-2017 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 *
      *****************************************************************
      *

Table of Contents Previous Section Next Section Summary

This 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 document and the links to other documents are intended to provide a greater awareness of the Data Management and Application Processing alternatives.

The 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 send an e-mail to: helpdesk@simotime.com or call 415 883-6565. We appreciate hearing from you.

Table of Contents Previous Section Next Section Software Agreement and Disclaimer

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.

Table of Contents Previous Section Next Section Downloads and Links

This 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.

Table of Contents Previous Section Next Section Current Server or Internet Access

The 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 Link to Internet 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 Link to Server icon.

Link to Internet   Link to Server   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.

Link to Internet   Link to Server   Explore the JCL Connection for more examples of JCL functionality with programming techniques and sample code.

Link to Internet   Link to Server   Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.

Link to Internet   Link to Server   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.

Link to Internet   Link to 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.

Link to Internet   Link to Server   Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and/or QSAM files.

Table of Contents Previous Section Next Section Internet Access Required

The 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 and services available from Micro Focus. This link requires an Internet Connection.

Table of Contents Previous Section Next Section Glossary of Terms

Link to Internet   Link to Server   Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.

Table of Contents Previous Section Next Section Comments or Feedback

This document was created and is copyrighted and maintained by SimoTime Technologies.

If you have any questions, suggestions, comments or feedback please call or send an e-mail to: helpdesk@simotime.com

We appreciate hearing from you.

Table of Contents Previous Section Next Section Company Overview

SimoTime 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


Return-to-Top
Search and Replace, Different Length Text Strings
Copyright © 1987-2017
SimoTime Technologies and Services
All Rights Reserved
When technology complements business
http://www.simotime.com