View previous topic :: View next topic
|
Author |
Message |
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
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 |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
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 |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
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 |
|
|
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
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 |
|
|
Kerry Ropar
New User
Joined: 14 Sep 2016 Posts: 25 Location: Australia
|
|
|
|
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 |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Kerry Ropar
New User
Joined: 14 Sep 2016 Posts: 25 Location: Australia
|
|
|
|
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 |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Well, tomato is a fruit! |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
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 |
|
|
|