IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Replacing variable length of characters


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
soundari

New User


Joined: 23 Feb 2007
Posts: 7
Location: chennai

PostPosted: Wed Jan 02, 2008 2:37 pm
Reply with quote

hi,

how to replace the variable length of string in a string.
for Eg. i want to replace "ABC" by "WXYZ". it is not working by INSPECT Verb.
could you please help me in this case
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Wed Jan 02, 2008 3:22 pm
Reply with quote

Hi Soundari,


Quote:

i want to replace "ABC" by "WXYZ". it is not working by INSPECT Verb


Inspect with replace option will only work if length of source string is equal to the destination string you want to replace with.

If you post your requirement fully, There is a possibility to solve it with some other means.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Jan 02, 2008 6:17 pm
Reply with quote

You may need to program this yourself.

Identify the position and length of the orig string, then via STRING verb set a new var = left substring || new string || right substring, using reference modification for the substrings.

You must check that each substring exists - e.g., the left one does not if the orig string starts in pos=1.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jan 02, 2008 7:03 pm
Reply with quote

Code:

WS-FIRST-PART         PIC X(40).
WS-REST-OF-AREA       PIC X(40).


Code:

INITIALIZE WS-FIRST-PART,
           WS-REST-OF-AREA

UNSTRING <string>
    DELIMITED BY <old-string>
        INTO  WS-FIRST-PART
              WS-REST-OF-AREA
END-UNSTRING

IF WS-FIRST-PART = SPACES
THEN
    CONTINUE
ELSE
    STRING WS-FIRST-PART
                    DELIMITED BY SPACES
           <new-string>
                    DELIMITED BY SIZE
           WS-REST-OF-AREA
                     DELIMITED BY SPACES
     END-STRING
END-IF


If your original string has embedded spaces, first do an INSPECT REPLACING ALL SPACES BY HIGH-VALUES.

Execute the above code.

INSPECT REPLACING ALL HIGH-VALUES BY SPACES.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top