Hi.. My requirement is to generate a pipe delimited dataset by reformatting a normal fixed-length input file. The output dataset has around 60 fields, as below.

Code:

|ABC|12.99|DEF GHI JKLMN|34569999000|..........

If one of the input fields have trailing spaces, I am supposed to trim them. If an input field does not contain any value, I am supposed to represent the field as ||, without any spaces in between.

I understand that checking each input field and moving only the bytes with actual data using reference modification is an option. However, since there are 60 such fields, checking each field individually and moving the data to the output makes my code a bit too long.

Is there any other way to go about it? Any pointer will be of great help. Thanks!

The input record would be something like this, where only a subset of the input fields are to be populated into the output. In addition, some of the input fields would contain trailing spaces and some would contain only blank values:

Code:

HIJLK 12.99 ABC 18908.6770 DEF GHI JKLMN 234 34569999000 .........

I do not mind copy pasting, but for the fact that it would affect code readability Writing a sub-routine is also fine (moving each field into the output record using reference modification and calling the routine to remove unwanted spaces). However, there would be 60 calls to the sub-routine, one after each MOVE statement. This is what I plan on doing if there isn't an alternative.

My query was to check if the coding can be done in a simpler way, using something like the INSPECT statement. Please let me know if you need further details. Thanks!

As an alternative to using reference modification, I was trying to check if the fields could be moved AS IS from the input dataset to the output and later have the unwanted spaces removed in one go, using a COBOL command or via a SORT step. Any occurrence of more than one space consecutively is to be removed.

The chances of having leading spaces is low. However, if present, the requirement is that any occurrence of more than one consecutive spaces are to be removed. In case of a non-populated field, the delimiters should appear one after the other, without a single space.

If the input data is in fixed positions then it is very simple in DFSort - parse out each field based on position, squeeze and combine each required field with pipe symbol in between to create your output record.

2. Tell us the source of the data under the pipes?
3.Answer to 2 is DB2 then you can do in the select itself else let us know if you can make this cobol-db2 program as in one select from sysibm.sysdummy1 you can make all 60 in good shape.
4.use SORT SQZ/PARSE as told by Enrico.

In short there are many simple ways, so that beg me to only question; How far you willing to move your legs?

Thank you all for your responses! Sorry for the late reply, I was off sick and had quite a bit of work to catch up on when I got back

The destination system receiving the feed from us mentioned later that they would require one space between pipes if a field is empty. So what I finally did was to move the input data to into fixed positions in the output record using a program (used a program instead of a PARSE as there were a few manipulations to be done on some of the fields) and then a SORT SQZ to remove consecutive spaces.

Code:

OPTION COPY
INREC BUILD=(1,3000,SQZ=(SHIFT=LEFT,MID=C' '))

And for the record, I wasn't sitting idle waiting for the forum reply. There were n number of other things being worked upon in parallel
As I have been out of touch with mainframe for a while, I was only checking if there were methods more efficient than mine to achieve my requirement.

2. Tell us the source of the data under the pipes?
3.Answer to 2 is DB2 then you can do in the select itself else let us know if you can make this cobol-db2 program as in one select from sysibm.sysdummy1 you can make all 60 in good shape.
4.use SORT SQZ/PARSE as told by Enrico.

In short there are many simple ways, so that beg me to only question; How far you willing to move your legs?