Hi friends,
I have a small requirement I want to Unstring a variable Delimited by ','
But I don't know how many commas will be there in the string
Sample Input with 2 records in it:
Input file will look like this
Each field refer to some value for a month.
So, It might have data for any no of months(Max of 1000).
But no of months in every row will be same.
Now I want to Extract each record in to a table of array.
I can't use this as I have to write all the thousand out-variables.
Code:
UNSTRING Input-Var Delimited by ','
into out-var(1)
into out-var(2)
into out-var(3)
into out-var(4)
.......
...and so on...
into out-var(1000)
END-UNSTRING
How can I acheive this?
Hope I am clear
Thanks,
Balu
Hi,
I can use it.
But I am trying for any other solution using loops to unstring one month at a time and populate it to the required variable.
But I am unable to get the desired result.
If I Can split this string to be split into 2 varaibles, then I can use Ustring in a loop and ustring the second variable each time to get the first months value to the required variable.
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
Quote:
But I am trying for any other solution using loops to unstring one month at a time and populate it to the required variable.
Is thsi just to save you a little editing time?
If your file is or will become high-volume, looping will just waste a lot of machine time. Maybe no one managing your system is concerned about resources wasted, but many system mamagers are. The cost of upgrading cpu's due to wasteful programming often not acceptable.
It is even worse when it is just due to a coder being lazy.
As i mention fairly regularly, just because something can be coded some poor-choice way is no reason that the poor choice should be made.
FWIW - the 3 main considerations for code that is to be promoted to production are:
It must run correctly every time
It must only use a reasonable amount of resource (i/o and/or cpu)
It must be easily maintainable.
Thanks Sambhaji for ur solution
Thanks Dick for your valuable advice
I am not a lazy programer but I was curious to know how it can be done
and that too my max no of months are only 40, So, I have already coded it in the manner what I have specified in my first post.
But Slight correction in the code what Sambhaji has given
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
Quote:
I was curious to know how it can be done
Yes, i too believe curious is good. It leads to many interesting discoveries
Quote:
But Slight correction in the code what Sambhaji has given
Possibly. . . Unfortunately, a lot of the code posted is not tested - it is more of "i think this will work". Fortunately, we do have many that post tested code and the result of the tested code from an actual execution. Maybe Sambhaji will have time to compile/test/and post the results here.
But Slight correction in the code what Sambhaji has given
Code:
strfirst(strcnt + 1:strcnt + 1)
I think it should be:
Code:
strfirst(strcnt + 1:1)
No it is correct. This statement is required to add ',' at end of string.
e.g. here in above example after unstring strfirst will have 1330 and strcnt will have 4 so i want ',' to be added at 5th position.
Dick wrote:
Maybe Sambhaji will have time to compile/test/and post the results here
Hi Dick, Output i have posted is tested.
The care Balu has to to be taken when he will put this in loop will be
moving strrest to strwithcomma and break the loop if strfirst is blank after unstring.