| Author |
Message |
bharath_gct2002
New User
Joined: 08 Oct 2007 Posts: 17 Location: Chennai, Tamil Nadu, India
|
|
|
|
Hi,
I have a requirement to sort a file with a different value for a field. I am not sure of how to do it. Please help me.
Input File:
------------
| Code: |
0413....GNL......1.
0413....DDA......2.
0774....DDA......1.
0885....DDA......1.
0885....DDA......2;
0365....DDA......1; |
I want to sort ths i/p file with the bytes (2-4) but I need to interpret the values of those fields with someother values and sort it. For example, a values in bytes 2-4 should be interpreted to the following:
| Code: |
413 - 280
774 - 280
885 - 096 |
So my i/p is sorted with interpreted values in the above table, but in the o/p my orginal values should come.
Output file:
-------------
| Code: |
0885....DDA......1.
0885....DDA......2;
0413....GNL......1.
0413....DDA......2.
0774....DDA......1.
0365....DDA......1; |
Please someone help me doing this.
|
|
| Back to top |
|
 |
References
|
Posted: Mon May 12, 2008 6:47 am Post subject: Re: Sorting a file with a different value for a field |
 |
|
|
 |
gcicchet
Active User
Joined: 28 Jul 2006 Posts: 156
|
|
|
|
Hi,
try this
| Code: |
//S1 EXEC PGM=ICEMAN
//SORTIN DD *
0413....GNL......1.
0413....DDA......2.
0774....DDA......1.
0885....DDA......1.
0885....DDA......2;
0365....DDA......1;
/*
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(81,3,BI,A)
INREC IFTHEN=(WHEN=(02,3,CH,EQ,C'413'),
OVERLAY=(81:C'280')),
IFTHEN=(WHEN=(02,3,CH,EQ,C'774'),
OVERLAY=(81:C'280')),
IFTHEN=(WHEN=(02,3,CH,EQ,C'885'),
OVERLAY=(81:C'096')),
IFTHEN=(WHEN=(02,3,CH,EQ,C'365'),
OVERLAY=(81:C'395'))
OUTREC BUILD=(1,80)
|
Gerry |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Moderator
Joined: 15 Feb 2005 Posts: 3804 Location: San Jose, CA
|
|
|
|
bharath,
Gerry's "solution" works for the data given but will not work for other variations of the data because there's no IFTHEN NONE clause. For example, if the input included this record:
0285....NEW......1.
It would be sorted as the first record instead of after the "280" records.
Here's a DFSORT job that will work for all variations of the data:
| Code: |
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD *
0285....NEW......1.
0413....GNL......1.
0413....DDA......2.
0774....DDA......1.
0885....DDA......1.
0885....DDA......2;
0365....DDA......1;
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC IFTHEN=(WHEN=(2,3,SS,EQ,C'413,774'),
OVERLAY=(81:C'280')),
IFTHEN=(WHEN=(2,3,CH,EQ,C'885'),
OVERLAY=(81:C'096')),
IFTHEN=(WHEN=NONE,
OVERLAY=(81:2,3))
SORT FIELDS=(81,3,ZD,A)
OPTION EQUALS
OUTREC BUILD=(1,80)
/*
|
|
|
| Back to top |
|
 |
pavans_here Warnings : 1 New User
Joined: 12 Aug 2005 Posts: 4 Location: hyderabad
|
|
|
|
Why did you choose 81 position to write to output file..
Is the requirement to write to 81 position. |
|
| Back to top |
|
 |
bharath_gct2002
New User
Joined: 08 Oct 2007 Posts: 17 Location: Chennai, Tamil Nadu, India
|
|
|
|
Thanks Frank n Gerry. The solution worked just fine!!.
Pavan,
My requirement is to add it in the position 4001 of the file cos my input record length is 4000 |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Moderator
Joined: 15 Feb 2005 Posts: 3804 Location: San Jose, CA
|
|
|
|
| Quote: |
| Why did you choose 81 position to write to output file.. |
Since the OP didn't originally give the LRECL of the input file, I assumed for the example that it was LRECL=80. The job would need to be changed appropriately for a different LRECL. |
|
| Back to top |
|
 |
|
|
|