Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Replace function

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

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 10:12 am    Post subject: Replace function
Reply with quote

Hi,

I have a variable as below,

Code:
01  WS-VAR      PIC X(21) VALUE '"PAIN PROTECT""ONLY""'.


I am using the below function,
Code:
INSPECT WS-VAR REPLACING ALL '"'   BY SPACES



But I need the output as, PAIN PROTECT "ONLY" but it comes as
PAIN PROTECT ONLY

I tried giving,
Code:
INSPECT WS-VAR REPLACING ALL '"'   BY SPACES 
INSPECT WS-VAR REPLACING ALL '""'  BY '" ' 



but even then I received the same output.

Can you help me out on this ?.[/code]
Back to top
View user's profile Send private message

abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 10:19 am    Post subject:
Reply with quote

The problem arouse when I inputted a CSV file to mainframe.

csv file input: PAIN PROTECT "ONLY"
when ftp'd to mainframe it became: "PAIN PROTECT ""ONLY"""

So now I need to make it back to PAIN PROTECT "ONLY".

Could you please let me know if there is a replace option to do this ?.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7234

PostPosted: Mon Sep 12, 2016 11:21 am    Post subject: Reply to: Replace function
Reply with quote

In a CSV quotes are used to "protect" data which contains values which otherwise would confuse the processing of the CSV (like values of " and ,).

If the first byte of a field is a '"', you need to remove it, and you need to remove the final byte of the data (which will also be a '"').

I'd not involve INSPECT (which is not a function, please note) in that. Just a small bit of code.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 11:49 am    Post subject:
Reply with quote

I can remove the '"' padded towards the start and end. But in my example, I need the value as it as which is like PAIN PROTECT "ONLY". Here you can see the '"' in the middle which is getting doubled.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 1:30 pm    Post subject:
Reply with quote

It would be great if I am able to remove the quotes inserted when FTP'ing the file from CSV to Mainframe so that I can get the exact value from the CSV file. But I am stuck as I am unable to identify the quotes inserted when transferred to mainframe.
Back to top
View user's profile Send private message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 135
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 5:06 pm    Post subject:
Reply with quote

Hi,

I am half way through. I got the output as PAIN PROTECT " ONLY".
I want it as PAIN PROTECT "ONLY" ie. without spaces between " and O.

Can you please help me out. I tried with REPLACE but wasn't able to trim the spaces. Is there any other way to do it ?.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Mon Sep 12, 2016 8:02 pm    Post subject:
Reply with quote

Use INSPECT and reference modification:
Code:
     INSPECT WS-SOURCE                           
         TALLYING WS-INIT-CHARS FOR CHARACTERS   
         BEFORE '" ONLY'.                         
                                                 
     MOVE WS-SOURCE TO WS-TARGET.                 
     MOVE WS-SOURCE (WS-INIT-CHARS + 3 : )       
       TO WS-TARGET (WS-INIT-CHARS + 2 : ).       
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Wed Sep 14, 2016 3:31 am    Post subject:
Reply with quote

Why even bother doing in Cobol, try doing it in DFSROT after FTP and get well formatted and a clean file out and then pass it to Cobol program otherwise I would agree to Bill's point.
Back to top
View user's profile Send private message
Kerry Ropar

New User


Joined: 14 Sep 2016
Posts: 25
Location: Australia

PostPosted: Thu Sep 15, 2016 10:18 am    Post subject:
Reply with quote

Bill and/or Rohit - please help me understand as well on this. If the user replaces first and last byte to eliminate ' " ', how will this remove the ' " ' that is appearing somewhere in the middle of the string?

abdulrafi - It appears you have tried to modify the upload of CSV where you somehow converted " to spaces. It appears to me that you might have (accidentally?) added an additional space at the beginning of your string as well.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Thu Sep 15, 2016 10:34 am    Post subject:
Reply with quote

Kerry,
Welcome!!
I agree to the point of the approach of checking byte by byte instead of INSPECT. So for the given situation the first byte should be skipped and one of any consecutive '"' should be skipped and certainly the last one.
this is hard coded solution to TS requirements and as you pointed out that for any other situations it will be incorrect.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7234

PostPosted: Thu Sep 15, 2016 11:34 am    Post subject: Reply to: Replace function
Reply with quote

Well, Kerry, it won't. And since that is not what the OP wanted (the whole point is about retaining the quotes that are actual data, which discarding the quotes which are protecting the data), that is generally considered a "good thing".
Back to top
View user's profile Send private message
Kerry Ropar

New User


Joined: 14 Sep 2016
Posts: 25
Location: Australia

PostPosted: Thu Sep 15, 2016 12:14 pm    Post subject:
Reply with quote

Thank you Rohit for the warming welcome, and thank you Rohit and Bill for your thoughts.

It seems I will still take some more time before I stop putting tomato in my fruit salad icon_biggrin.gif
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Thu Sep 15, 2016 2:47 pm    Post subject:
Reply with quote

Well, tomato is a fruit!
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Thu Sep 15, 2016 10:19 pm    Post subject:
Reply with quote

Quote:
And since that is not what the OP wanted
OP wants none of '"' anywhere except wrapped around 'ONLY' word, Please ignore if you mean to imply the same.
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
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Replace repeated JCL with looping REXX prino CLIST & REXX 3 Thu Oct 13, 2016 5:30 am
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
This topic is locked: you cannot edit posts or make replies. Sort card to replace text using cross... Susanta SYNCSORT 32 Tue Sep 13, 2016 4:17 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us