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 a char by using INSPECT.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rguhanath

New User


Joined: 16 Oct 2006
Posts: 80
Location: chennai

PostPosted: Fri Mar 20, 2009 6:42 pm    Post subject: Replacing a char by using INSPECT.
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: 6968
Location: porcelain throne

PostPosted: Fri Mar 20, 2009 7:04 pm    Post subject:
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: 80
Location: chennai

PostPosted: Fri Mar 20, 2009 7:11 pm    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Fri Mar 20, 2009 7:26 pm    Post subject:
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    Post subject: Reply to: Replacing a char by using INSPECT.
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: 80
Location: chennai

PostPosted: Sat Mar 21, 2009 2:50 pm    Post subject:
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    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 Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am
No new posts replacing junk with hyphen Nitin32 DFSORT/ICETOOL 10 Fri Jun 02, 2017 7:47 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm

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