Agent Mahone
Agent Mahone

Reputation: 307

How to get the only records from input file, having written '7' on 5th position

Need a SORT JCL to write down records from input file, which have written '7' on 5th position.

    input file:
    AABL5ZZZZ
    AAQL7AAAA
    ZZWA76AAA
    AAXC01AAA

OUTPUT

    AAQL7AAAA
    ZZWA76AAA

Upvotes: 0

Views: 3844

Answers (1)

piet.t
piet.t

Reputation: 11921

If you don't want the records sorted you could use something like

//*******************************************
//SORT     EXEC PGM=SORT                     
//*******************************************
//SORTIN   DD  DSN=MY.INPUT.FILE,DISP=SHR
//SORTOUT  DD  SYSOUT=*                      
//SYSOUT   DD  SYSOUT=*                      
//SYSUDUMP DD  SYSOUT=*                      
//SYSIN    DD  *                             
  SORT FIELDS=COPY                           
  INCLUDE COND=(5,1,CH,EQ,C'7')              
  END                                        
/*

For sorting just change the SORT FIELDS= statement.

P.S.: The above JCL is for fixed record-length files. If you use variable record-length you have to take care of two points:

  • add the 4-byte length-field to the comparison-position
  • let SORT skip records that are shorter than 5 bytes

So the SYSIN would look like

  OPTION VLSHRT                
  SORT FIELDS=COPY             
  INCLUDE COND=(9,1,CH,EQ,C'7')
  END                                                                      

Upvotes: 4

Related Questions