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
 

 

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

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

New User


Joined: 04 Jul 2007
Posts: 92
Location: Hyderabad

PostPosted: Fri Dec 12, 2008 3:40 pm    Post subject: Convert all the ',' in a strings with ':'
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    Post subject: Reply to: Unstring
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: 92
Location: Hyderabad

PostPosted: Fri Dec 12, 2008 6:33 pm    Post subject:
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: 7932
Location: Bellevue, IA

PostPosted: Fri Dec 12, 2008 6:41 pm    Post subject:
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    Post subject: Reply to: Unstring
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: 2180
Location: @my desk

PostPosted: Fri Dec 12, 2008 6:48 pm    Post subject:
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

Site Director


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

PostPosted: Fri Dec 12, 2008 10:20 pm    Post subject:
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: 7932
Location: Bellevue, IA

PostPosted: Sat Dec 13, 2008 12:01 am    Post subject:
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: 92
Location: Hyderabad

PostPosted: Tue Dec 16, 2008 4:20 pm    Post subject:
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: 92
Location: Hyderabad

PostPosted: Thu Dec 18, 2008 7:01 pm    Post subject:
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: 7932
Location: Bellevue, IA

PostPosted: Thu Dec 18, 2008 7:05 pm    Post subject:
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    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
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am
No new posts help: convert C'00AB' to X'00AB' alan_gu DFSORT/ICETOOL 1 Thu Sep 29, 2016 12:22 pm


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