Hi,
I am trying to replace a larger byte string with a smaller byte string. I tried using cobol INSPECT - REPLACING.. As both operands are not of equal size, it is throwing an error.
Suppose in a 2000 byte string, if there is any "SHOULD BE", should be replaced with "S/B". i.e., a 9 bytes string should be replaced with a 3 bytes string. cant tell where this string may come and how many times it may come.
Eg:(for reference)
"THIS SHOULD BE DONE TODAY" ===> "THIS S/B DONE TODAY"
Could someone suggest me how I can do this.
Thanks,
Raju
Replacing a larger string with smaller string
Moderators: dbzTHEdinosauer, Moderator Group
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
how many times can/could the string 'SHOULD BE' occur within the 2000 char string?
i would UNSTRING text DELIMITED BY 'SHOULD BE'
and then STRING the components inserting 'S/B' between each component.
of course you need to define your receiving fields of the UNSTRING to insure enough length.
i would INSPECT TALLYING FOR 'SHOULD BE' before I UNSTRING,
not bothering to UNSTRING if no occurances,
and the TALLY special register will tell you how many components you will have (TALLY + 1)
to make it easy, i would:
1. INITIALIZE the receiving fields group area with '@".
thus the STRING of the components would by DELIMITED BY '@"
2. have several STRING statements, depending on the TALLY value.
i.e. if tally is 1, then use
if tally is 2, then use
if tally is 3, then use
ETC....
i would UNSTRING text DELIMITED BY 'SHOULD BE'
and then STRING the components inserting 'S/B' between each component.
of course you need to define your receiving fields of the UNSTRING to insure enough length.
i would INSPECT TALLYING FOR 'SHOULD BE' before I UNSTRING,
not bothering to UNSTRING if no occurances,
and the TALLY special register will tell you how many components you will have (TALLY + 1)
to make it easy, i would:
1. INITIALIZE the receiving fields group area with '@".
thus the STRING of the components would by DELIMITED BY '@"
2. have several STRING statements, depending on the TALLY value.
i.e. if tally is 1, then use
Code: Select all
STRING receiving-field-1
DELIMITED BY '@'
'S/B'
DELIMITED BY SIZE
receiving-field-2
DELIMITED BY '@'
INTO new-2000-byte-area
END-STRING
Code: Select all
STRING receiving-field-1
DELIMITED BY '@'
'S/B'
DELIMITED BY SIZE
receiving-field-2
DELIMITED BY '@'
'S/B'
DELIMITED BY SIZE
receiving-field-3
DELIMITED BY '@'
INTO new-2000-byte-area
END-STRING
Code: Select all
STRING receiving-field-1
DELIMITED BY '@'
'S/B'
DELIMITED BY SIZE
receiving-field-2
DELIMITED BY '@'
'S/B'
DELIMITED BY SIZE
receiving-field-3
DELIMITED BY '@'
'S/B'
DELIMITED BY SIZE
receiving-field-4
DELIMITED BY '@'
INTO new-2000-byte-area
END-STRING
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
Got it....
Thank you dick for your suggestion..
I did this way..
Thank you dick for your suggestion..
I did this way..
Code: Select all
inspect msg-2000-chars tallying cnt-sb for all "should be"
perform cnt-sb times
inspect msg-2000-chars replacing first "should be" by "s/b{*}{@}"
unstring msg-2000-chars delimited by "{@}"
into receiving-field1
receiving-filed2
end-unstring
string receiving-field1 delimited by "{*}"
receiving-field2 delimited by size
into msg-2000-chars
end-string
end-perform.
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
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page