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

Replace function


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

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 10:12 am
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: 184
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 10:19 am
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Sep 12, 2016 11:21 am
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: 184
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 11:49 am
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: 184
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 1:30 pm
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: 184
Location: Coimbatore

PostPosted: Mon Sep 12, 2016 5:06 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Mon Sep 12, 2016 8:02 pm
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Wed Sep 14, 2016 3:31 am
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
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

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Thu Sep 15, 2016 10:34 am
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 15, 2016 11:34 am
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
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: 2455
Location: Hampshire, UK

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

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3048
Location: NYC,USA

PostPosted: Thu Sep 15, 2016 10:19 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts replace word 'MONTH' with current mon... SYNCSORT 11
Search our Forums:

Back to Top