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

Replacing a char by using INSPECT.


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

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Fri Mar 20, 2009 6:42 pm
Reply with quote

Hi All,

I have a requirement which needs to check a char in a string and instead of that char i need to replace with a string. is it possible by using INSPECT REPLACING function.

For Ex:

i am having a string like:

ABCD&EFGG

i want the output like below after replacing & with &amp:

ABCD&EFGG.

same thing i want for the characters

< to &lt;
> to &gt;
' to &apos;
" to &quot;

Please help me on this.


Thanks in Advance.

Regards,
Nath.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Mar 20, 2009 7:04 pm
Reply with quote

Quote:
is it possible by using INSPECT REPLACING function.


manuals are found with the buttons at top of page. why don't you look up the inspect command in a cobol manual and see what you can do?
Back to top
View user's profile Send private message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Fri Mar 20, 2009 7:11 pm
Reply with quote

Hi dbzTHEdinosauer,

i checked the manuals. but i didn't found related to my requirement. There is only have example for same length of string replacing. mine is not in that case. so please help me if you/anybody knows on this..

Thanks,
Nath.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Mar 20, 2009 7:26 pm
Reply with quote

ok, you now know that inspect does a one to one replacement.

you could use inspect to determine if any of the sub-strings are present in the input string and require replacement.

Then you could walk thru with either an index (if you declare the input string as a table consisting of single char) or use reference modification to move the input to the output, testing constantly if the input field is a sub-string that requires replacement.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Fri Mar 20, 2009 8:12 pm
Reply with quote

rguhanath,
You can try this piece of code:
Code:
WORKING STORAGE
01 I PIC 9(02)  VALUE 1.
01 KT PIC 9(02)  VALUE 1.
01 WS-A1  PIC X(05) VALUE '&AMP;'.       
01 WS-A2  PIC X(03) VALUE '&LT'.         
01 WS-A3  PIC X(03) VALUE '&GT'.         
01 WS-A   PIC X(80) VALUE SPACES.         
01 INPUT-FIELD    PIC X(1) VALUE SPACES. 
   88 A-1                  VALUE '&'.     
   88 A-2                  VALUE '<'.     
   88 A-3                  VALUE '>'. 

PROCEDURE DIVISION

PERFORM UNTIL I = LENGTH OF A 
MOVE A(I:1) TO INPUT-FIELD     
EVALUATE TRUE                 
WHEN A-1                       
MOVE WS-A1 TO WS-A(KT:5)       
COMPUTE KT = KT + 5           
WHEN A-2                       
MOVE WS-A2 TO WS-A(KT:3)       
COMPUTE KT = KT + 3           
WHEN A-3                       
MOVE WS-A3 TO WS-A(KT:3)       
COMPUTE KT = KT + 3           
WHEN OTHER                     
MOVE A(I:1) TO WS-A(KT:1)     
COMPUTE KT = KT + 1           
END-EVALUATE                   
COMPUTE I = I + 1             
END-PERFORM     

Quote:
INPUT A:9999&99999<999999>99999999&
OUTPUT WS-A:9999&AMP;99999&LT999999&GT99999999&AMP;

Similarly you can test for other conditions as well.
Do remember that your output field should be big enough to accomodate the replacements.

WTF
Back to top
View user's profile Send private message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 81
Location: chennai

PostPosted: Sat Mar 21, 2009 2:50 pm
Reply with quote

Hi Succor,

i have tried this piece of code and its working fine.. Thanks a lot...

-Nath
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 SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Finding record and replacing with val... DFSORT/ICETOOL 3
No new posts Replacing character string in file th... JCL & VSAM 9
Search our Forums:

Back to Top