View previous topic :: View next topic
|
Author |
Message |
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
SPACE is just that - a space. No |. You need to string '|' after your SPACE..
Code: |
STRING ...
SPACE,
'|',
blah,
'|'
SPACE
etc. |
|
|
Back to top |
|
|
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
Dick,
Thanks |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
|
|
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 |
|
|
|