Home      Mainframe Forum      Mainfarme Tutorials      IBM Manuals      Mainframe Interview Questions      Mainframe Books      IT News     SiteMap     Downloads


     
 
MAINFRAME - TIP OF THE DAY : When you specified V for RECFM parameter, LRECL value is largest record in the file plus 4 bytes. These four bytes contain the actual length of each variable length record in the file

Google
 
Web mainframegurukul.com

Replace special characters with spaces in a string

 
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> COBOL
  View previous topic :: View next topic  
Author Message
Salman
Member


Joined: 08 Sep 2013
Posts: 6

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
1 salutes

PostPosted: Tue Feb 25, 2014 4:15 pm    Post subject: Replace special characters with spaces in a string Reply with quote

Hi Folks,

Can anyone please let me know how can i replace the special characters in a string with spaces?
Ex: If i have a string 'ABC@123#d_efg)'
then it should give me 'ABC 123 d efg '

By using INSPECT we can do it provided if we know the special characters in advance but in my case i can't do it either because there are numerous special characters in my project and i can't use INSPECT for every special character and for every time.

so,I used the below logic to fix this but this seems not working.

77 ws-add pic x(50).
77 ws-var pic x(50).

move '1!2@cd#ef$gh%ij^klmn*&' to ws-add
*'1 2 cd ef gh ij klmn ' is my desired output
move ws-add to ws-var

PERFORM para-1 VARYING ws-index FROM 1 BY 1
UNTIL ws-index > 50

para-1:
if ws-var(ws-index:1) is numeric
move ws-var(ws-index:1) to ws-add(ws-index:1)

else if ws-var(ws-index:1) is alphabetic
move ws-var(ws-index:1) to ws-add(ws-index:1)
else
move spaces to ws-add(ws-index:1).

Can anyone throw some light on this ?

Thanks & Regards,
AAkheel.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.

William Collins
Active Member


Joined: 24 May 2012
Posts: 732

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Tue Feb 25, 2014 5:11 pm    Post subject: Reply with quote

You don't say what isn't working.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
DikDude
Moderator


Joined: 22 Jul 2011
Posts: 1001
Location: usa

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Tue Feb 25, 2014 10:29 pm    Post subject: Reply with quote

Hello,

Quote:

but in my case i can't do it either because there are numerous special characters in my project and i can't use INSPECT for every special character and for every time.
Why not?

As asked - what is Not working?
_________________
Have a good one
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Salman
Member


Joined: 08 Sep 2013
Posts: 6

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Wed Feb 26, 2014 9:48 am    Post subject: Reply with quote

Hi Folks,

Sorry for incomplete post.
But as i mentioned, using Refernce Modification for every Feild,
like if it is of x(250),then it has to check for 250 times and it will make it very tedious and hence the performance of the program degrades.
So, i request to provide me an optimized way to fix this thing.

Thanks & Regards,
Aakheel.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
William Collins
Active Member


Joined: 24 May 2012
Posts: 732

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Wed Feb 26, 2014 1:28 pm    Post subject: Reply with quote

What is the purpose of this removal of "special" characters?

If you can answer that, you may get some useful replies.

Perhaps you can explain what you mean by "tedious". It is a computer. It finds nothing tedious.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Salman
Member


Joined: 08 Sep 2013
Posts: 6

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
1 salutes

PostPosted: Wed Feb 26, 2014 2:34 pm    Post subject: Reply with quote

Hi William,

Actually its an address feild to which it receives from another system so there might be some junk values like 'square'.*/.... for which i need to remove it and fill it with spaces(Only Numerics and Alphabetics allowed).
By performing the above code it satisfies but it will degrade the performance.
For example, if i have to generate a memo with x(1000), then it will check for all the 1000 letters present in the feild which i feel is not the better way and hence finding for an alternate way to optimize it.

Any help would be appretiable.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
payilagamch
Member


Joined: 14 Jan 2014
Posts: 12

Answer was approved by Question owner.
Useful Post
1 votes
Not an useful post
Greate Post!! Salute Author
1 salutes

PostPosted: Wed Feb 26, 2014 2:48 pm    Post subject: Reply with quote

If you have a list of possible special characters you can use INSPECT with REPLACING.

INSPECT source-string REPLACING ALL '#' BY ' '
ALL '_' BY ' '
_________________
Payilagam Chennai
www.payilagam.com
Back to top
View user's profile Send private message Visit poster's website
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Salman
Member


Joined: 08 Sep 2013
Posts: 6

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Wed Feb 26, 2014 3:34 pm    Post subject: Reply with quote

Hi Payilagamch,

As I mentioned above we can use Inspect only in the case if we know the special characters in advance but in my case there are large number of special charcters and sometimes may be junnk(square...).
Hence, it will not work here.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Salman
Member


Joined: 08 Sep 2013
Posts: 6

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Wed Feb 26, 2014 3:41 pm    Post subject: Reply with quote

Hi Payilagamch,

As I mentioned above we can use Inspect only in the case if we know the special characters in advance but in my case there are large number of special charcters and sometimes may be junnk(square...).
Hence, it will not work here.
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
William Collins
Active Member


Joined: 24 May 2012
Posts: 732

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Wed Feb 26, 2014 5:47 pm    Post subject: Reply with quote

This, then, is something to be done at the time the data is captured. You do it once, it is done.

If there is some absurd reason that it can't be done at data-capture, then how does the data get to your system? Is it stored on the other system then passed to you every time? Or is it passed to you once, so you have your "capture" and you do it at that point, once only.

If it is passed every time, you (your boss) should insist that the system which passes it does the validation. Then, when they realise what a pain that is, they will do it themselves at the point of capture.

Don't look at REPLACING, look at INSPECT .... CONVERTING, but you'd have to convert every unwanted value.

If you can't get good data given to you, then you have to look at making your code better. Although I don't like destorying the contents of a field, since you are doing it anyway, why have two copies of the field?

Also, since you only want to space-out the values you don't want, you doin't need to MOVE the bytes when you discover they are OK. Since you are looking at text, and fields will allow for maximum size, you should identify trailing space and stop your tests when you reach that. Do that with the same looping, but starting from the end of the field and going "backwards" until you get the first non-blank.

That'll speed your code up, but even more so if you don't have to do it because it is done at the correct point...
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
DikDude
Moderator


Joined: 22 Jul 2011
Posts: 1001
Location: usa

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Wed Feb 26, 2014 10:13 pm    Post subject: Reply with quote

One thing you might do is look for the valid characters rather than the invalid ones.

Then define an 88 level that includes all valid codes. A simple IF will do for each position (reference modification to move across the input data). When valid, leave alone otherwise move space.

What testing have yuou done to verify how much resource is needed.

It really doesn't matter as the data Must be correct.
_________________
Have a good one
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
NicC
Active Member


Joined: 24 Jul 2011
Posts: 650
Location: Down on the pig farm

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Thu Feb 27, 2014 3:13 am    Post subject: Reply with quote

Probably a reddefines of the field as a table would be more efficient than ref. mod. You could check each byte is NUMERIC or ALPHA nd set to BLANK if neither.
_________________
Regards
Nic
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
devendar
Member


Joined: 14 Jun 2017
Posts: 1
Location: Hyderabad

Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Wed Jun 14, 2017 4:29 pm    Post subject: Reply with quote

Below condition will help to remove the unwanted values from field, if we receives the value other than the ALPHABETIC and NUMERIC below code will replaces the JUNK or unwanted values with "spaces".

01 STREET1-ADDRESS X(25)
01 ADDR1 REDEFINES STREET1-ADDRESS OCCURS 25 TIMES

PROCEDURE DIVISION.

OPEN INPUT INPUT-FILE
OUTPUT OUTPUT-FILE,

MOVE INPUT-ADDR1 TO STREET1-ADDRESS

IF (ADDR1 (SUB1) ALPHABETIC) OR
(ADDR1 (SUB1) NUMERIC)
NEXT SENTENCE
ELSE
MOVE SPACES TO ADDR1 (SUB1)
END-IF.
_________________
Thanks
Devendar
Back to top
View user's profile Send private message Yahoo Messenger
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Display posts from previous:   
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> COBOL All times are GMT + 5 Hours
Page 1 of 1



 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Cobol Tutorial
This cobol tutorial covers most of the important topics like STRING, UNSTRING, COMP, COMP-3.....
DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. Explains in simple language. Some Chapters are locked, Forum members have free access to these chapters
CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming...
JCL Tutorial
This is most popular JCL tutorial from mainframegurukul. It does contain important jcl ....
SORT Tutorial
This Tutorial covers all important aspects of DFSORT. Has more SORT examples
INTERVIEW Questions
This page covers important interview questions
Mainframe Jobs
Mainframe Jobs posted by members of mainframegurukul forum
FaceBook Page
MainframeGurukul FaceBook Page
LinkedIn Page
MainframeGurkul Linkedin Page

This widget requires Flash Player 9 or better







Go to top of the page
 

Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  DB2 INTERVIEW QUESTIONS ||  COBOL INTERVIEW QUESTIONS  ||  JCL INTERVIEW QUESTIONS ||  JCL2 INTERVIEW QUESTIONS ||  VSAM INTERVIEW QUESTIONS ||  CICS INTERVIEW QUESTIONS  ||  Online tutorials ||  Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  SiteMap  ||  Expeditor Tutorial  ||  FILE-AID Tutorial  ||  Changeman Tutorial  ||  COBOL   ||  DB2   ||  JCL  ||  CICS  ||  VSAM  ||  DB2 Interview Questions ( 110 )   || Simple JCL Tutorials  || JCL Tutorial from MainframeGurukul.com   || Simple JCL Tutorial - Chapter1 ;|| Mainframe Forum - Tutorials  || Mainframe Tutorials || Mainframe CICS tutorial|| Mainframe COBOL Tutorial

Drona Educational Forums - Mainframe Cobol DB2 CICS Board
Powered by phpBB

mainframetopic-7469.html