|
View previous topic :: View next topic
|
| Author |
Message |
Lord.of.Wind
New User
Joined: 17 Nov 2005 Posts: 60
|
|
|
|
Hello experts:
I have such a file and want to output the whole file(including the 1st record) if the first record matches (1,2,CH,EQ,C'30',AND,18,2,CH,EQ,C'99').
How to code the SORT control command?
Thanks!
| Code: |
30AAAAAAAAAAAAAAA99
461AAAAAAAAAAAAAAAA
452AAAAAAAAAAAAAAAA
463AAAAAAAAAAAAAAAA
454AAAAAAAAAAAAAAAA
465AAAAAAAAAAAAAAAA
456AAAAAAAAAAAAAAAA
467AAAAAAAAAAAAAAAA
458AAAAAAAAAAAAAAAA
469AAAAAAAAAAAAAAAA
4510AAAAAAAAAAAAAAA
|
|
|
| Back to top |
|
 |
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
I would use something like this
| Code: |
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
30AAAAAAAAAAAAAAA99
461AAAAAAAAAAAAAAAA
452AAAAAAAAAAAAAAAA
463AAAAAAAAAAAAAAAA
454AAAAAAAAAAAAAAAA
465AAAAAAAAAAAAAAAA
456AAAAAAAAAAAAAAAA
467AAAAAAAAAAAAAAAA
458AAAAAAAAAAAAAAAA
469AAAAAAAAAAAAAAAA
4510AAAAAAAAAAAAAAA
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY,STOPAFT=1,NULLOUT=RC4
INCLUDE COND=(1,2,CH,EQ,C'30',AND,18,2,CH,EQ,C'99')
/*
|
Now if the return code is 0, you can run step2 to copy the entire file.
I have not provided the JCL for step2, it's just a simple copy.
Gerry |
|
| Back to top |
|
 |
Lord.of.Wind
New User
Joined: 17 Nov 2005 Posts: 60
|
|
|
|
| thank you so much Gerry! |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
gcicchet,
There is a slight problem with your approach as the INCLUDE COND gets executed before the STOPAFT. So even if 30AAAAAAAAAAAAAAA99 is the 10 th record or any other record your job will issue a return code of 0 which is wrong. Try your job moving the first record anywhere and check it for yourself.
Check this link for illustratration of the processing order for record handling, exits, statements, and options in DFSORT
Lord.of.Wind,
Use the following DFSORT JCL which will copy the entire file in one pass ONLY if the very first record matches (1,2,CH,EQ,C'30',AND,18,2,CH,EQ,C'99') or else it would be empty
I assumed that your input is FB recfm and LRECL of 80
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
30AAAAAAAAAAAAAAA99
461AAAAAAAAAAAAAAAA
452AAAAAAAAAAAAAAAA
463AAAAAAAAAAAAAAAA
454AAAAAAAAAAAAAAAA
465AAAAAAAAAAAAAAAA
456AAAAAAAAAAAAAAAA
467AAAAAAAAAAAAAAAA
458AAAAAAAAAAAAAAAA
469AAAAAAAAAAAAAAAA
4510AAAAAAAAAAAAAAA
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),
IFTHEN=(WHEN=(81,8,ZD,EQ,1,AND,1,2,CH,EQ,C'30',AND,18,2,CH,EQ,C'99'),
OVERLAY=(89:C'Y'))
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(89,1,CH,EQ,C'Y'),PUSH=(89:89,1))
OUTFIL BUILD=(1,80),INCLUDE=(89,1,CH,EQ,C'Y')
//* |
|
|
| Back to top |
|
 |
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi Skolusu,
I apologise for providing an incorrect solution.
In your example which I cannot test GROUP due an old version of DFSORT,
are you still reading the entire file ?
Would it not be best to copy out 1st record only and test it, it's no point reading the entire file when only the first record needs to be tested. especially if it happens to be a large input file.
Gerry |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| gcicchet wrote: |
Would it not be best to copy out 1st record only and test it, it's no point reading the entire file when only the first record needs to be tested. especially if it happens to be a large input file.
Gerry |
gcicchet,
Yes I would read the entire file, but it is a good idea to just validate the first record and then copy it. In that case OP needs to use the following control cards
| Code: |
//SYSIN DD *
OPTION COPY,STOPAFT=1
OUTFIL NULLOFL=RC4,INCLUDE=(1,2,CH,EQ,C'30',AND,18,2,CH,EQ,C'99')
//* |
This will set a return code of 4 if the first record does not match the include cond. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|