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
 

 

Break up a string having words concated with '.'

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
vinit_infy
Warnings : 1

New User


Joined: 07 Apr 2005
Posts: 56

PostPosted: Mon Mar 05, 2007 4:15 pm    Post subject: Break up a string having words concated with '.'
Reply with quote

I want to break up a string having words concated with '.' as:

aaaa.bbbb.ddddfdfdf.ttrttrtr.eeeee.ffff

but every time the words lengh can be vary. I would like to know can we specify
variables varying with the numbers of words with the INTO clause of UNSTRING

I.e.,

here UNSTRING ..... DELIMITED BY '.'
INTO TEMP1 TEMP2 TEMP3 TEMP4 ..

SO I WANT THE ALLOCATION OF TEMP VARIABLE DYNAMICALLY.
Back to top
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Mon Mar 05, 2007 5:34 pm    Post subject:
Reply with quote

Been discussed lately, start here
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Mon Mar 05, 2007 5:35 pm    Post subject:
Reply with quote

u can use a dynamic array in cobol for this purpose....
then u don't need to specify length of the variable...
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: Tue Mar 06, 2007 1:22 am    Post subject:
Reply with quote

Hello,

Please post some code to show how your solution would be implemented.
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Tue Mar 06, 2007 9:27 am    Post subject:
Reply with quote

u can declare the array as...
Code:
01 ws-array.
    05 ws-var occurs 1 to 999 times
                depending on ws-length.


in this dynamic array you do not need to specify the length. you can dynamically count length (after using unstring operation)and move it to ws-length variable.

hope this works..
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: Tue Mar 06, 2007 9:33 am    Post subject:
Reply with quote

Hello,

Please post the unstring code as well.
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Tue Mar 06, 2007 10:10 am    Post subject:
Reply with quote

suppose you store ur string in a variable WS-STR
then try using this code...
Code:

UNSTRING WS-STR DELIMITED BY '.'
           INTO  WS-ARRAY(1) COUNT  IN WS-LENGTH
                     WS-ARRAY(2) COUNT  IN WS-LENGTH
                      WS-ARRAY(3) COUNT IN WS-LENGTH
                     .........
                     .........
                      WS-ARRAY(999) COUNT IN WS-LENGTH
END-UNSTRING.

hope this works.. :)
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: Tue Mar 06, 2007 8:47 pm    Post subject:
Reply with quote

Hello,

Your unstring does not match your variable names.

WS-ARRAY cannot be subscripted - it is the overall group item.

The UNSTRING moves delimited data from one field (string) into multiple fields. The posted solution only has 1 field. If it worked at all, i do not believe the result would be what is desired. Please try that solution and post your results.

Back to the original question - there is a limit to the number of delimited fields that will be present in the string. Define a series of working data fields (in an array) of that number plus 1 (your "business rules" will determine that maximum number of fields that could be present). Each of these fields must be long enough to hold the largest possible field length. When these fields are defined, also define a second array for a "length field" for each. Process the unstring recording the length for each unstrung field. Include the "tallying" option. After the unstring, the field specified for tallying will have the field count of the number of items that were unstrung. You need to set that field to zero before each unstring. The array needs to be cleared before each unstring also to make sure there is no "leftover" data from the previous unstring. If you use 2 arrays for the fields and the lengths, a simple "move spaces" will clear the field array.

When the unstring completes, you will have a table of the unstrung fields as well as the length of the data in those fields. You will also have a count of how many components the unstring broke the "string" into.

Now, write a loop to process the array one field at a time, doing whatever you need to do.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Tue Mar 06, 2007 11:38 pm    Post subject:
Reply with quote

Quote:
You can unstring each field in a perform loop until overflow using the pointer function of the unstring to maintain position.

And because you are going to ask, something like this:
Code:
move 1 to P
perform varying sub from 1 by 1
             until UOVER
  unstring field delimited by thingy
      into area(sub)
      with pointer P
      on overflow set UOVER to true
  end-unstring
end-perform
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 -> Mainframe Interview Questions 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. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


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