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

Delimit functionality in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Sat Mar 15, 2014 3:57 pm
Reply with quote

Hi All,
This is my requirement. Following is a PS file which will have pipe delimited values, Using one of the fields i have to fetch some fields and populate after the input file fields. Each Input field can vary from 1-10 byte.
I/P:
00000|000000000|0000|00000|0000000000|
00000|000000|0000000|0000000|00000000|
00000|0000000|0000000000|00011110|11111111111|
I am able to do an unstring into seperate fields from the input.
UNSTRING INP-REC DELIMITED BY '|'
INTO VAR1
VAR2....
END-UNSTRING.

After the db2 fetch when i try to string the same for output file, its not happening.
For eg: When i tried
STRING OUT-VAR1 DELIMITED BY SPACES
SPACE DELIMITED BY '|'
OUT-VAR2 DELIMITED BY SPACES
SPACE DELIMITED BY '|'
INTO OUT-REC.
Its not stringing the output based on the space and gives an output without the pipe sybmol like the following........................ 00000 000000 0000000 0000000 00000000 000000000 1111111111

but i want the output to be like.
o/p:
00000|000000000|0000|00000|0000000000|111111111111|000000000|1
00000|000000|0000000|0000000|00000000|000000000|11111111111
00000|0000000|0000000000|00011110|11111111111|11111111111|000|1

Can anyone tell me whats the mistake in my piece.
Thank you in advance for the help.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Sat Mar 15, 2014 5:03 pm
Reply with quote

SPACE is just that - a space. No |. You need to string '|' after your SPACE..

Code:
STRING ...
SPACE,
'|',
blah,
'|'
SPACE
etc.
Back to top
View user's profile Send private message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Tue Mar 18, 2014 2:52 pm
Reply with quote

Nic,
I tried the following

STRING OUT-VAR DELIMITED BY SPACES,'|'
SPACE DELIMITED BY '|'
INTO OUT-VAR1
end-string

but it didn't work.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Mar 18, 2014 4:38 pm
Reply with quote

anandinmainframe, think about your code for a minute:
Code:
STRING OUT-VAR DELIMITED BY SPACES,'|'
SPACE DELIMITED BY '|'
INTO OUT-VAR1
A space is a space is a space -- it will not and CANNOT be delimited by anything. Coding
Code:
SPACE DELIMITED BY '|'
will put a space in your output variable -- it will not, under any circumstances, place a VBAR in the output variable. Why? Because the DELIMITED BY phrase tells COBOL to copy bytes until (1) the end of the variable is reached, or (2) the delimiter is found. Since a space is a single byte variable, with a space in it, then the delimiter will never be tested for as the end of the SPACE is reached first.

What you need, based upon your post, is
Code:
STRING OUT-VAR1 DELIMITED BY SPACES
'|'
OUT-VAR2 DELIMITED BY SPACES
'|'
INTO OUT-REC.
This would generate an output variable with two fields separated by a VBAR. Your original post does NOT show any spaces around the VBAR, so I did not include them.
Back to top
View user's profile Send private message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Tue Mar 18, 2014 8:24 pm
Reply with quote

Hi Robert,
When i use the syntax you give.
STRING WS-VAR1 DELIMITED BY SPACES
'|'
WS-VAR2 DELIMITED BY SPACES
'|'
WS-VAR3 DELIMITED BY SPACES
'|'
WS-VAR4 DELIMITED BY SPACES
'|'
WS-VAR5 DELIMITED BY SPACES
'|'
WS-VAR6 DELIMITED BY SPACES
'|'
WS-VAR7 DELIMITED BY SPACES
'|'
WS-VAR8 DELIMITED BY SPACES
'|'
INTO OUT-REC.
I am getting a compilation errror as
The "STRING" statement was invalid. Expected "DELIMITED",but found "INTO". The statement was discarded.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Mar 18, 2014 8:30 pm
Reply with quote

simply code
'|'
as
'|' DELIMITED BY LENGTH



yes, you are correct, the syntax provided was incomplete,
but
WTF,
can you not look at the manual and determine what was wrong?
Back to top
View user's profile Send private message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Tue Mar 18, 2014 8:56 pm
Reply with quote

Dick,
Thanks
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Tue Mar 18, 2014 9:05 pm
Reply with quote

Quote:
I did that already, but just want to show that everyone will make mistakes, Humans are errors


Are you here to find mistakes of others ? Perhaps, You need to honor their time given to you ( and others including me) as you are unable to do a string by your own.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top