Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Dynamic Unstring

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

New User


Joined: 16 Apr 2008
Posts: 86
Location: Bangalore

PostPosted: Tue Oct 14, 2008 11:37 am    Post subject: Dynamic Unstring
Reply with quote

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:
Code:

1330,0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,1030,1085,870,1030,1085,870,1030,0,335,349,0,335
335,349,298,335,349,298,335,349,298,335,349,298,335,34,349,0,335,349,0,335,349,0,335,349,0,335,349,0,335,349,0,335

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
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 Oct 14, 2008 11:52 am    Post subject:
Reply with quote

Hello,

Quote:
I can't use this as I have to write all the thousand out-variables.
Why is that a reason that you cannot use this? If there 1000 source fields, you must provide for getting them into individual target fields.
Back to top
View user's profile Send private message
vvmanyam

New User


Joined: 16 Apr 2008
Posts: 86
Location: Bangalore

PostPosted: Tue Oct 14, 2008 12:19 pm    Post subject:
Reply with quote

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.

Code:

1330,0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,1030,1085,870,1030,1085,870,1030,0,335,349,0,335

One varaiable with first month qty and the rest in to different variables
First variable:
Code:

1330

Second variable:
Code:

0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,1030,1085,870,1030,1085,870,1030,0,335,349,0,335

Can this be done?

Thanks,
Balu
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Oct 14, 2008 3:24 pm    Post subject:
Reply with quote

Quote:

One varaiable with first month qty and the rest in to different variables
First variable:
Code:

1330


Second variable:
Code:

0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,0,158,0,1030,1085,870,1030,1085,870,1030,0,335,349,0,335


Can this be done?


Yes this can be achieved using below code. Then you can use below in loop to achieve your original task

Code:

MOVE "1330,0,0,158,0,0,158" to STRWITHCOMMA.             
unstring strwithcomma delimited by ','                   
into strfirst                                           
count in strcnt.                                         
move ',' to strfirst(strcnt + 1:strcnt + 1).             
unstring strwithcomma delimited by strfirst(1:strcnt + 1)
into strrest                                             
     strrest.                                           
DISPLAY strfirst(1:strcnt).                             
DISPLAY strrest.                                         

Output will be:
Code:

1330           
0,0,158,0,0,158
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 Oct 14, 2008 7:56 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
vvmanyam

New User


Joined: 16 Apr 2008
Posts: 86
Location: Bangalore

PostPosted: Wed Oct 15, 2008 8:56 am    Post subject:
Reply with quote

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
Code:

strfirst(strcnt + 1:strcnt + 1)   

I think it should be:
Code:

strfirst(strcnt + 1:1)


Thanks,
Balu
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: Wed Oct 15, 2008 9:29 am    Post subject: Reply to: Dynamic Unstring
Reply with quote

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 icon_smile.gif

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.

Good luck icon_smile.gif

d
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 15, 2008 11:55 am    Post subject:
Reply with quote

Balu wrote:

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.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 15, 2008 1:33 pm    Post subject:
Reply with quote

May be putting above in loop will be complex.
below is code in loop using one unstring
Code:

01 STRWITHCOMMA PIC X(20).
01 STRfirst PIC X(20).   
01 STRrest PIC X(20).     
01 strcnt PIC 99.         
01 strend PIC 99.         
'
'
'
MOVE "1330,1,0,158,0,0,15 " to STRWITHCOMMA.       
perform  find-first                                 
 until strcnt = (function length(strwithcomma) + 2).
'
'
find-first.                                     
    unstring strwithcomma delimited by ','       
    into strfirst                               
    count in strcnt.                             
    compute strcnt = strcnt + 2.                 
    compute strend = 20 - strcnt + 1.           
    move strwithcomma(strcnt:strend) to strrest.
    DISPLAY 'strfirst is:' strfirst.             
    move strrest to strwithcomma.               

Output is:
Code:

strfirst is:1330 
strfirst is:1     
strfirst is:0     
strfirst is:158   
strfirst is:0     
strfirst is:0     
strfirst is:15   
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 REXX - Dynamic file Creation d_sarlie CLIST & REXX 7 Tue Jun 27, 2017 7:30 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Dynamic split of files under groups sril.krishy DFSORT/ICETOOL 4 Mon Apr 17, 2017 1:09 pm
No new posts Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am
No new posts REXX DB2: Dynamic allocation of DB2.D... BHAS CLIST & REXX 3 Mon Dec 19, 2016 8:26 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us