|
View previous topic :: View next topic
|
| Author |
Message |
ksk
Active User
.jpg)
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Hi,
I have to remove trailing spaces for a particular field and but the issue is this field can have spaces in between. I am using
| Code: |
1,44,SQZ=(SHIFT=LEFT),C',',45,8,SQZ=(SHIFT=LEFT)
|
But the above one is removing spaces which are in between the value.
My Input looks like (record length=80,Record Format=FB)
| Code: |
Field1 Field2
(1-44) (45-52)
ABC DEF GHI & JKML 135 2432
|
Expected Output
| Code: |
ABC DEF GHI & JKML,135 2432
|
But I am getting as below.
| Code: |
ABCDEFGHI&JKML,1352432
|
How can we handle spaces which are in between of the field? Appreciate your help. |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
ksk,
Assuming there is a single space between words you can use the following DFSORT JCL which will give you the desired results
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
ABC DEF GHI & JKML 135 2432
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC BUILD=(1,44,C',',45,8,53,27)
OUTREC FINDREP=(INOUT=(C' ',C'',C' ,',C',',C', ',C','))
//* |
|
|
| Back to top |
|
 |
ksk
Active User
.jpg)
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Thanks for the immediate reply.
Can you please explain what the below code does?
| Code: |
INOUT=(C' ',C'',C' ,',C',',C', ',C',')
|
Please note that one field can have any number of single spaces in between or cannot have even a single space in between.
For ex,
| Code: |
A B CDE FGHI KDJFJ D S
ABCDEFGRHYSJFDJFKJFK
SFDHDSFSD ASDSD GFG
|
In the above I/P, respective field of the first record has 6 single spaces in between and 2nd record does not have any spaces and the third has 2 spaces so on... |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| ksk wrote: |
| Can you please explain what the below code does? |
The First C'bb' is looking for 2 adjacent spaces(b= blank) and eliminating them. so if there are even number of space at the end they would get all eliminated and the other conditions are checking for odd number of spaces and starting spaces for field 2.
You are fine as long as your field 1 has single spaced words. It doesn't matter how many words you have.
however if your data has
| Code: |
ABC FH <== 2 adjacent spaces between ABC and FH |
Your output would be
So as long as you maintain single spacing between words you are fine.
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:
www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000080 |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
ksk,
Here's another way to do it with DFSORT which will preserve any number of spaces between the words.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
BUILD=(1,44,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'",',LENGTH=47),
45,8,JFY=(SHIFT=LEFT,LEAD=C'"',TRAIL=C'"',LENGTH=10))),
IFTHEN=(WHEN=INIT,BUILD=(1,57,SQZ=(SHIFT=LEFT,PAIR=QUOTE))),
IFTHEN=(WHEN=INIT,FINDREP=(IN=C'"',OUT=C''))
|
For example, if the input is:
| Code: |
ABC DEF GHI & JKML 135 2432
ABC DEF GHI & JKML QR 135 2432
ABC DEF GHI & JKML XYZ AB 135 432
|
The output will be:
| Code: |
ABC DEF GHI & JKML,135 2432
ABC DEF GHI & JKML QR,135 2432
ABC DEF GHI & JKML XYZ AB,135 432
|
|
|
| Back to top |
|
 |
ksk
Active User
.jpg)
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
| Thanks Kolusu and Frank. Worked perfectly for my requirement. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|