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

Break up a string having words concated with '.'


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
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
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: 3156
Location: Tucson AZ

PostPosted: Mon Mar 05, 2007 5:34 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Mar 06, 2007 1:22 am
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
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

Moderator Emeritus


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

PostPosted: Tue Mar 06, 2007 9:33 am
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
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

Moderator Emeritus


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

PostPosted: Tue Mar 06, 2007 8:47 pm
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: 3156
Location: Tucson AZ

PostPosted: Tue Mar 06, 2007 11:38 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top