Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Replacing variable length of characters

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Replacing variable length of characters
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: 130
Location: Guntur

PostPosted: Wed Jan 02, 2008 3:22 pm    Post subject:
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

Active Member


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

PostPosted: Wed Jan 02, 2008 6:17 pm    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Wed Jan 02, 2008 7:03 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Binary to display characters Roy Ware SYNCSORT 3 Tue Sep 19, 2017 8:46 pm
No new posts Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
This topic is locked: you cannot edit posts or make replies. Selecting two copybooks of different ... Vignesh Sid COBOL Programming 8 Tue Sep 05, 2017 7:28 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us