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

Convert all the ',' in a strings with ':'


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

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Fri Dec 12, 2008 3:40 pm
Reply with quote

How can i convert all the ',' in a strings with ':'which comes in between " ".And eliminate the "

For ex.
I have the below string

My I/P: my,address,is,"47/1,neelanchal,nagar",and,end

my desired O/p : my,address,is,47/1:neelanchal:nagar,and,end
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Fri Dec 12, 2008 6:20 pm
Reply with quote

Hi,

You may try using the below approach.

1) UNSTRING the string into 3 parts (first , middle, last) - delimitedd by ".
2) INSPECT the string and replace all ',' to ':' for middle.
3) STRING all the 3 parts back delimited by space.

Try using the above approach, it should give you the desired result.

Thanks,
-Kapil.
Back to top
View user's profile Send private message
dp33770

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Fri Dec 12, 2008 6:33 pm
Reply with quote

Hi kapil,
Thanks for your reply..
But my concern is that there are lot more " " in between the single rec.
Just for Example I have written One string in between " ".
And I am not sure how many " " comes in the record .

Need someone to help in this...

Thanks a lot ...
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: Fri Dec 12, 2008 6:41 pm
Reply with quote

Reference modification comes to mind -- use a separate output string; go through the entire input string. If the current character is a " then flip a switch (initial value off) and go to the next character. If the current character is "," and the switch is set, change it and put in output. Otherwise, put in output.
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Fri Dec 12, 2008 6:46 pm
Reply with quote

Well, I don't know whether we have a simple and straight forward solution for this.

I have one logic to handle this but its a bit complex, I don't know how useful its going to be. Let me try explainng :

Input string = aaa"bb,bb"cccc"dd,dd"eeee"ff,ff"gggg

1) INSPECT string and replace first " to @.
2) INSPECT string and replace first " to @.

Now use the logic posted earlier by me

4) UNSTRING the string into 3 parts (first ,middle, last) - delimitedd by @.
5) INSPECT the string and replace all ',' to ':' for middle.
6) STRING all the 3 parts back delimited by space. (insert# instead of @)

Note- # will let you know that this is the processed part of string.

Now keep on repeating all the above steps until you process the complete string.

Finally replace all # back to ".

Hope this helps.
-Kapil.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Dec 12, 2008 6:48 pm
Reply with quote

dp33770,

I believe you'll have to check every byte of a record for ' " ' and process accordingly
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Dec 12, 2008 10:20 pm
Reply with quote

Hello,

Quote:
Well, I don't know whether we have a simple and straight forward solution for this.
The suggestion Robert posted is simple and straightforward. . . .

One single pass across the data with no limitation of how many "sets" of embedded strings to change. No STRINGs/UNSTRINGs/iterations thru. . .
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: Sat Dec 13, 2008 12:01 am
Reply with quote

The code is very straight forward:
Code:
       01  WS-VARIABLES.
           05  WS-SWITCH               PIC 9(01) VALUE 0.
               88  WS-OFF                        VALUE 0.
               88  WS-ON                         VALUE 1.
           05  WS-INPUT-LOC            PIC 9(02) VALUE 1.
           05  WS-OUTPUT-LOC           PIC 9(02) VALUE 1.
           05  WS-INPUT-STRING         PIC X(80) VALUE
           'MY,ADDRESS,IS,"47/1,NEELANCHAL,NAGAR",AND,END' .
           05  WS-OUTPUT-STRING        PIC X(80) VALUE SPACE.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           PERFORM
           VARYING WS-INPUT-LOC
                   FROM 1 BY 1 UNTIL WS-INPUT-LOC > 80
               EVALUATE WS-INPUT-STRING (WS-INPUT-LOC : 1)
               WHEN '"'
                    COMPUTE WS-SWITCH = 1 - WS-SWITCH
               WHEN ','
                    IF  WS-ON
                        MOVE ':' TO  WS-OUTPUT-STRING
                                     (WS-OUTPUT-LOC : 1)
                    ELSE
                        MOVE ',' TO  WS-OUTPUT-STRING
                                     (WS-OUTPUT-LOC : 1)
                    END-IF
                    ADD 1              TO  WS-OUTPUT-LOC
               WHEN OTHER
                    MOVE WS-INPUT-STRING (WS-INPUT-LOC : 1)
                      TO WS-OUTPUT-STRING (WS-OUTPUT-LOC : 1)
                    ADD 1              TO  WS-OUTPUT-LOC
               END-EVALUATE
           END-PERFORM .
           DISPLAY 'INPUT STRING  ' WS-INPUT-STRING.
           DISPLAY 'OUTPUT STRING ' WS-OUTPUT-STRING.
           GOBACK.
and produces output of
Code:
 INPUT STRING  MY,ADDRESS,IS,"47/1,NEELANCHAL,NAGAR",AND,END
 OUTPUT STRING MY,ADDRESS,IS,47/1:NEELANCHAL:NAGAR,AND,END
Back to top
View user's profile Send private message
dp33770

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Tue Dec 16, 2008 4:20 pm
Reply with quote

Thanks All for your suggestion ....
Thanks Robert for special help ....
Back to top
View user's profile Send private message
dp33770

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Thu Dec 18, 2008 7:01 pm
Reply with quote

Hi all,
For the above requiremnet I struct again.
Can anyone help me in this.

I have Input record - PIC x(30)

and output rec has below fields
Field1 - PIC X(3)
Field2 - PIC X(3)
Field3 - PIC X(6)
field4 - PIC X(6)

Example :
---------
i/p rec -1 : AAA,BBB,"cc,dd",fff,ff"
i/p rec -1 : AAA,CCC,"c,d","xx,xxx"

How shall I unstring it two 4 fields (Field1,Field2,Field3,Field4) of the above o/p rec
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: Thu Dec 18, 2008 7:05 pm
Reply with quote

You could use the same basic code with another flag to indicate which output field should have the character added; probably not more than another 10 - 15 lines of code.
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 Need to convert date format DFSORT/ICETOOL 20
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts convert file from VB to FB and use tr... DFSORT/ICETOOL 8
No new posts Convert HEX to Numeric DB2 3
Search our Forums:

Back to Top