Search and Replace
When technology complements business   Different Length Text Strings
Copyright © 1987-2008  SimoTime Enterprises, LLC  All Rights Reserved  http://www.simotime.com

 
Introduction Version 04.08.23
  Call Interface
  The CMD Member for Net Express
  The JCL Member for OS/390 or Mainframe Express
  The COBOL Demonstration Program
  The COBOL Search-and-Replace Routine
  The Copy File for Pass Area
  Summary
 
  Software Agreement and Disclaimer
  Downloads and Links to Similar Pages
  Comments or Suggestions
  About SimoTime

Introduction
(Next) (Previous) (Table-of-Contents)

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.

The following is a flowchart of the search and replace process using COBOL. The BLUE boxes are unique to the mainframe and Micro Focus Mainframe Express. The RED boxes are unique to the PC with Windows and Micro Focus Net Express. The GREEN boxes are platform independent and will execute on the mainframe or a PC with Windows. Also, the GREEN boxes may be ported to a UNIX platform that is supported by Micro Focus COBOL.

Entry Point
OS390 or MFE
     
Entry Point
Net Express
  Entry for OS/390 or Windows platform
 
     
 
   
CBLREPJ1
jcl
     
CBLREPE1
cmd
  Start the Job
 
     
 
   
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
   
   
 
       
   
CBLREPC1
cobol
     
     
     
CONSOLE
display
  Example of calling the substitution routine
   
 
     
     
     
SIMOSUB1
cobol
  Replace a text-string within a field
   
 
       
   
EOJ
      End-of-Job
             

Call Interface
(Next) (Previous) (Table-of-Contents)

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.

The CMD Member
(Next) (Previous) (Table-of-Contents)

The following is the CMD member (CBLREPE1.CMD) used to run the job on a PC using Micro Focus Net Express Express.

@echo OFF
rem  * *******************************************************************
rem  *                   This program is provided by:                    *
rem  *                    SimoTime Enterprises, LLC                      *
rem  *           (C) Copyright 1987-2006 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 Enterprises
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  *
     set JobStatus=0000
     if "%SYSLOG%" == "" set syslog=c:\SimoLIBR\LOGS\SimoTime.LOG
rem  *
     SimoEXEC NOTE  *******************************************************CblRepE1
     SimoEXEC NOTE  Starting JobName CblRepE1
rem  * ********************************************************************
rem  * Step   2 of 2  Execute the sample program...
rem  *
     SimoEXEC EXEC CblRepC1
rem  *
     SimoEXEC NOTE Finished JobName CblRepE1, Job Status is %JobStatus%
:End
     SimoEXEC NOTE Conclude SysLog is %SYSLOG%
     if not "%1" == "nopause" pause

The JCL Member
(Next) (Previous) (Table-of-Contents)

The following is the JCL member (CBLREPJ1.JCL) used to run the job on an IBM Mainframe with OS/390 or the PC using Micro Focus Mainframe Express.

//CBLREPJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=A,NOTIFY=CSIP1
//* *******************************************************************
//*                   This program is provided by:                    *
//*                    SimoTime Enterprises, LLC                      *
//*           (C) Copyright 1987-2003 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 Enterprises
//* 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 *-----* DISPLAY  *
//*   ********cbl*     ************
//*        *
//*        *
//*   ************
//*   *   EOJ    *
//*   ************
//*
//CBLREPS1 EXEC PGM=CBLREPC1
//STEPLIB  DD  DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR
//SYSOUT   DD  SYSOUT=*
//*

The COBOL Demonstration Program
(Next) (Previous) (Table-of-Contents)

The following is the source listing for the COBOL demonstration program(CBLREPC1.CBL).

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    CBLREPC1.
       AUTHOR.        SIMOTIME ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2006 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: 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 ' v04.08.23'.
           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-2006 '.
           05  C3 pic X(28) value '  SimoTime Enterprises, LLC '.
           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 sample '.
           05  C3 pic X(32) value 'by SimoTime Enterprises, LLC    '.
           05  C4 pic X(04) value '    '.

       01  SIM-THANKS-02.
           05  C1 pic X(11) value '* CBLREPC1 '.
           05  C2 pic X(32) value 'Please send comments or suggesti'.
           05  C3 pic X(32) value 'ons to helpdesk@simotime.com    '.
           05  C4 pic X(04) value '    '.

      *****************************************************************
      * 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 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 '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
           inspect SUB-BUFFER-TARGET
                   replacing first 'Before, ' by 'After,  '
           move SUB-BUFFER-TARGET(1:71) 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) upon console
           else
               display MESSAGE-BUFFER       upon console
           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 Enterprises         *
      *        Our e-mail address is: helpdesk@simotime.com           *
      *     Also, visit our Web Site at http://www.simotime.com       *
      *****************************************************************

The COBOL Search-and-Replace Routine
(Next) (Previous) (Table-of-Contents)

The following is the source listing for the COBOL search and replace routine(SIMOSUB1.CBL). 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 ENTERPRISES.
      *****************************************************************
      * Copyright (C) 1987-2006 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 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.                                                  *
      *                                                               *
      * 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.                                                  *
      *                                                               *
      * 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(3) value 0.
       01  I-2            pic 9(3) value 0.
       01  SUB-PTR        pic 9(3) 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 Copy File for Pass Area
(Next) (Previous) (Table-of-Contents)

The following is the source listing for the COBOL Copy File (PASSSUB1.CPY) used to call the search and replace routine.

      *****************************************************************
      *     Data Structure or Pass Area used for calling SIMOSUB1.    *
      *****************************************************************
      *         Copyright (C) 1987-2006 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 modofied 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...

Summary
(Next) (Previous) (Table-of-Contents)

The purpose of this document is to assist 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 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.

Software Agreement and Disclaimer
(Next) (Previous) (Table-of-Contents)

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.

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

Downloads and Links to Similar Pages
(Next) (Previous) (Table-of-Contents)

You may download this example at http://www.simotime.com/sim4dzip.htm#COBOLZipStringReplace as a Z-Pack. The Z-Packs provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download.

Please view the complete list of SimoTime Z-Pack Examples at http://www.simotime.com/sim4dzip.htm.

Note: You must be attached to the Internet to download a Z-Pack or view the list.

The hexadecimal dump of the parameter-buffer uses the same technique as describe in another SimoTime example that describes the dumping of a data string using COBOL. The name of the member that does the actual hexadecimal dump is called SimoDUMP. A copy file (PASSDUMP.CPY) is provided for defining the pass area.

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. SimoZAPS can 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.

Check out   The COBOL Connection  for more examples of mainframe COBOL coding techniques and sample code.

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 .

Comments or Suggestions
(Next) (Previous) (Table-of-Contents)

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

About SimoTime Enterprises, LLC
(Next) (Previous) (Table-of-Contents)

Founded in 1987, SimoTime Enterprises is a privately owned, Limited Liability Corporation located in Novato, California. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com.


Return-to-Top
Copyright © 1987-2008  SimoTime Enterprises, LLC  All Rights Reserved
When technology complements business
http://www.simotime.com