IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to check only the first record?


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Lord.of.Wind

New User


Joined: 17 Nov 2005
Posts: 60

PostPosted: Wed Jun 30, 2010 9:18 am
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Wed Jun 30, 2010 10:21 am
Reply with quote

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
View user's profile Send private message
Lord.of.Wind

New User


Joined: 17 Nov 2005
Posts: 60

PostPosted: Wed Jun 30, 2010 11:48 am
Reply with quote

thank you so much Gerry!
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Jun 30, 2010 9:39 pm
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Thu Jul 01, 2010 5:57 am
Reply with quote

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
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Jul 01, 2010 9:30 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts SCOPE PENDING option -check data DB2 2
Search our Forums:

Back to Top