Replacing '&' by 'AND' in a variable

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
ShilpaA
Member
Posts: 2
Joined: Thu Sep 24, 2009 2:19 am
Location: Pune

Replacing '&' by 'AND' in a variable

Post by ShilpaA » Thu Sep 24, 2009 2:44 am

There is a variable 'ws-var pic x(10) values ABCDE&123F'. Is it possible to replace '&' by 'AND'? If it is possible then will there be any change in the length of ws-var? Or will it give an error & which error code?
Shilpa

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Thu Sep 24, 2009 11:12 am

You can do this by using INSPECT... REPLACE... Try it.
There wont be any change in the ws-var length.
Natarajan
Chennai

User avatar
Chanti
Member
Posts: 32
Joined: Thu Nov 27, 2008 4:31 pm

Post by Chanti » Fri Sep 25, 2009 2:05 pm

Hi,

I think, with the inspect verb
"The size of the replacement string must be the same size as the string it replaces"

So, it is better to use perform loop, reading character by character and replace the string '&' by AND

will there be any change in the length of ws-var?

Yes there will be change

will it give an error & which error code?

it will not give error, but the data gets truncated!!, as the size is greater than before!!

Thanks,
Chanti

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others