Page 1 of 1

splitting of records using cobol

Posted: Tue Jun 24, 2014 1:22 pm
by gkrish
I have following input file:

Code:

|aaa|bbbb|
ccccc|ddd
dd|ee|


record length is fixed to 80
I need the following output file:

aaa
bbbb
ccccc
ddddd
ee


here record length has to be 80
i.e. i need the data between any two | as one record of 80 length with padding

Posted: Tue Jun 24, 2014 2:09 pm
by William Collins
Have a look at UNSTRING and see if you'd find it useful.

Posted: Tue Jun 24, 2014 8:12 pm
by gkrish
Thanks willam , had look into it, but if u see the 2 nd and 3 rd line of my input ddd is split into 2 lines if we use unstring it come as separate lines is there any way to concatenate these both

Posted: Tue Jun 24, 2014 8:50 pm
by William Collins
Can you show the code you used, the input you used, the output you received and the output you expected, please?

All inside the Code tags to preserve spacing.

Posted: Wed Jun 25, 2014 3:40 pm
by dhiraj
Inspect the UNSTRING data(only for first character). if matches then STRING those data.

Example:

UNSTRING Record delimited by '|'
into WS-var1 WS-var2 WS-var3 WS-var4......
End-Unstring

If WS-var2(1:1) = WS-var3(1:1)

String WS-var2 DELIMITED BY SIZE
WS-var2DELIMITED BY SIZE
INTO WS-var5.

Posted: Wed Jun 25, 2014 6:45 pm
by William Collins
Dhiraj,

You need to re-think that considerably. Why would ( 1 : 1 ) of anything be equal to ( 1 : 1 ) of anything else? If you delimit by SIZE, you'll get trailing blanks. You'd also need to set all those fields to space first, else you'll get values "left over" from the previous UNSTRING if there are more pipes on the previous than on the current.

Posted: Wed Jun 25, 2014 8:21 pm
by dhiraj
Will, I got your point....so we need exact INPUT data because I thought after 3d there is one | .

|aaa|bbbb|
ccccc|ddd
dd|ee|


gkrish- You need to paste Exact INPUT and desired OUTPUT.