Here the ~ signs are the spaces which are part of field value. And # are delimiter spaces. So the only way of finding the start and end positions of the fields is to identify the positions of # in the first line.
The following DFSORT JCL will give you the desired results. I assumed you only have 7 fields and the max of each field can be 20 bytes. If it is more than that you can adjust the length.
I also assumed that you have only 1 field where you want to preserve the space in between.ie. in the sample input your last field. If you have more fields then just enclose them in quotes and you are all set. I also used FINDREP to remove the quotes we added for preserving the spaces. FINDREP function of DFSORT IS available with z/OS DFSORT V1R5 PTF UK90013 (July, 2008) For complete details on the FINDREP function and the other new functions available with PTF UK90013, see:
Thanks a lot for your response. But #, ~ are both spaces. I just used them as a mask for differentiating the delimiter space and the space wich is part of the field value. This is the original input file.
1----- 2-------- 3---------------- 4--- 5------ 6----- 7------------
514 514 A123456789012345 P 1009200 THIS IS TEST1
514 514 B123456789012345 P 1013200 THIS IS TEST2
514 514 C123456789012345 P 1013200 THIS IS TEST3
The number of fields may vary. Also field 7 is not the only field to have spaces in between. More than one fileds can also have spaces as their value.
You need to come up with the max number of fields. If you have more fields where you need to preserve the spaces then you need create them enclosed in quotes or apostrophes, so that it is easy to distinguish them.