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
 
Delimit functionality in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Delimit functionality in COBOL
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: 1922
Location: UK

PostPosted: Sat Mar 15, 2014 5:03 pm    Post subject: Reply to: Delimit functionalty
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    Post subject:
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: 8187
Location: East Dubuque, Illinois, USA

PostPosted: Tue Mar 18, 2014 4:38 pm    Post subject:
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    Post subject: Reply to: Delimit functionalty
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: 6970
Location: porcelain throne

PostPosted: Tue Mar 18, 2014 8:30 pm    Post subject:
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    Post subject: Reply to: Delimit functionalty
Reply with quote

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

Senior Member


Joined: 21 Sep 2010
Posts: 1817
Location: NY,USA

PostPosted: Tue Mar 18, 2014 9:05 pm    Post subject:
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    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
This topic is locked: you cannot edit posts or make replies. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm
No new posts VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts COBOL - EXIT statement weird behavior anthony.pangestu COBOL Programming 0 Fri Oct 27, 2017 9:57 am
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am

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