Find a position in variable and update.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Prem_mainframe
New Member
Posts: 6
Joined: Fri Jan 17, 2014 2:04 pm

Find a position in variable and update.

Post by Prem_mainframe »

Hi,

In a COBOL

Variable1 PIC X(36) value '0123456789abcdefghijklmnopqrstuvwxyz'.

I want to firstly search the character, for example 'c', later want to update the character 'c' to '$'. In the output i need to display, the character position, chrrent value and the replaced value - how should I proceed for this.

Thank you
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Find a position in variable and update.

Post by Robert Sample »

Use INSPECT. It allows TALLYING as well as REPLACING.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Find a position in variable and update.

Post by zprogrammer »

Just trying to understand :

Do you want to replace all 'c' in the given string?
zprogrammer
Prem_mainframe
New Member
Posts: 6
Joined: Fri Jan 17, 2014 2:04 pm

Re: Find a position in variable and update.

Post by Prem_mainframe »

Yes, I wanted to replace all the 'c's.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Find a position in variable and update.

Post by William Collins »

Use a loop with PERFORM.
Prem_mainframe
New Member
Posts: 6
Joined: Fri Jan 17, 2014 2:04 pm

Re: Find a position in variable and update.

Post by Prem_mainframe »

Thanks William.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”