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
 

 

Unstring delimited by spaces and then load into table

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

New User


Joined: 24 Mar 2008
Posts: 29
Location: mumbai

PostPosted: Tue Jul 28, 2009 4:44 pm    Post subject: Unstring delimited by spaces and then load into table
Reply with quote

Hi Everybody,

I have a string of length 1000. I need to unstring it based on interim spaces and then load these unstringed strings into internal table.

For Example:
01 ws-string pic x(1000).
ws-string having the below data:
AB RES MAIN ADA JCL CICS

And i have a internal table defined like:
01 ws-table.
05 ws-unstring pic x(4) occurs 250 times.

After unstring the above exampled string Iam expecting to load the ws-table like
ws-unstring(1) - AB
ws-unstring(2) - RES
ws-unstring(3) - MAIN
ws-unstring(4) - ADA
ws-unstring(5) - JCL
ws-unstring(6) - CICS


Can we do this by using UNSTRING or INSPECT verbs. If so Please update me.
Back to top
View user's profile Send private message

bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 208
Location: Cochin/Kerala/India

PostPosted: Tue Jul 28, 2009 4:49 pm    Post subject:
Reply with quote

i think the better option is UNSTRING DELIMITED BY SPACES option
Back to top
View user's profile Send private message
hemantasr

New User


Joined: 28 Jan 2006
Posts: 1

PostPosted: Tue Jul 28, 2009 5:16 pm    Post subject:
Reply with quote

See if the below Code works :-

PERFORM UNTIL WS-COUNT-SPACES > 0
Unstring WS-STRING delimited by Spaces into
WS-UNSTRING(W-IDX),WS-STRING-REST

MOVE WS-STRING-REST to WS-STRING
INSPECT WS-STRING TALLYING WS-COUNT-SPACES FOR ALL SPACES
ADD +1 TO WS-IDX
END-PERFORM

I think above code should work.I did not test it but just wrote it over a paper to test if it work fine.
Back to top
View user's profile Send private message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Tue Jul 28, 2009 5:21 pm    Post subject:
Reply with quote

Hi rajeshwarch,

We had similar condition in one of our program. I specified below what we did to achieve this task.

1. UNSTRING WS-STRING (WS-START-POS:WS-STR-LEN)
DELIMITED BY SPACE
INTO WS-UNSTRING (WS-IDX)
COUNT IN WS-UNSTRING-LEN
2. ADD WS-UNSTRING-LEN TO WS-START-POS
3. ADD 1 TO WS-START-POS
4. SUBTRACT WS-START-POS FROM WS-STR-LEN
5. SUBTRACT 1 FROM WS-STR-LEN
6. Repeat the steps 1 to 5 until input string extraction completes(if you know how manu sub strings you are expecting in the input string) OR
WS-STRING (WS-START-POS:WS-STR-LEN) equal to SPACES

Hope this information is useful to you icon_smile.gif
Back to top
View user's profile Send private message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Tue Jul 28, 2009 5:36 pm    Post subject:
Reply with quote

oops,
I missed WS-IDX increment inside the loop in my earlier reply.
We have to have that statement inside the loop icon_smile.gif
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 Jul 29, 2009 7:16 am    Post subject:
Reply with quote

Hello,

Possibly there is something i misunderstand, but why is anything more than the single UNSTRING needed?
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Wed Jul 29, 2009 10:03 am    Post subject:
Reply with quote

Hi Dick,

I guess more than one will be required as rajesh wants the output in a table. If i am correct, we can do the same in a single UNSTRING, but the code would look something like this
Code:
UNSTRING ws-string
DELIMITED BY SPACE INTO
ws-unstring (1)
ws-unstring (2)
ws-unstring (3)
ws-unstring (4)
    :::::
ws-unstring(249)
ws-unstring(250)

which i guess is not appreciated... icon_razz.gif

Please do correct me if i am wrong... icon_smile.gif
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 Jul 29, 2009 10:17 am    Post subject:
Reply with quote

Hello,

Quote:

which i guess is not appreciated..
Possibly. . . I'd not want to sacrifice all of the cpu cycles needed to do this using iterative loops to accomplish the moves.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Wed Jul 29, 2009 10:29 am    Post subject:
Reply with quote

Hi,

I guess the performance v/s readability is an argument which will always be there... icon_biggrin.gif

Some time back i remember our clients had raised a concern coz we included an IF condition which looked like
Code:
if <cond1>
  stat1
else if <cond2>
  stat2
else if <cond3>
  stat3
 ::  ::
else
  statn

which was spread across a couple of pages. They were concerned that a single statement ( IF ) is taking more than one page. I guess they were okay with having everything as simple IF statments with no ELSE so that the same is a little more readable... icon_wink.gif
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: Thu Jul 30, 2009 5:20 am    Post subject:
Reply with quote

Hello,

Quote:
I guess the performance v/s readability is an argument which will always be there.
Please explain how an unstring is less readable than the convoluted looping. . . icon_confused.gif

From my perspective, the unstring both reads easily and far outperforms looping.

I also believe that it is quite do-able to write code that both performs well and is easily maintainable/readable.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Jul 30, 2009 6:10 am    Post subject:
Reply with quote

Hi,

Quote:
Please explain how an unstring is less readable than the convoluted looping. . .


I was merely trying to say that some clients dont consider it readable, as a single statement takes more than one page... icon_redface.gif

And to be frank... i also do think its better to loop than have it as a single statement... icon_wink.gif
Maybe as time goes on i might realize that its stupid... icon_cool.gif
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: Thu Jul 30, 2009 6:44 am    Post subject:
Reply with quote

Hello,

Quote:
Maybe as time goes on i might realize that its stupid...
There are many things to learn and there are many opinions that vary. . . icon_smile.gif

In program code (as with sql) often the smallest amount code is not the better alternative.

Quote:
some clients dont consider it readable, as a single statement takes more than one page
If such code is performed, there is only 1 line of code in the mainline. This retains the readability and the performance. . . icon_wink.gif
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Jul 30, 2009 6:54 am    Post subject:
Reply with quote

Thanks for the inputs Dick... icon_smile.gif
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 SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Copybook structure in Load module Vai123 COBOL Programming 7 Fri Sep 16, 2016 8:29 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm


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