thabrlo phungo
thabrlo phungo

Reputation: 11

Check if input file record is sorted and if not it should abend

I'm trying to write a JCL that check if the input file record is sorted and if not it should abend with a specific message.

This is the job that I have; but I don't want it to sort anymore. I want it to abend if company number in column 3 not in Sequence;

//TOOL1    EXEC PGM=ICETOOL                                        
//TOOLMSG  DD SYSOUT=T                                             
//DFSMSG   DD SYSOUT=T                                             
//TOOLIN   DD *                                                    
  DATASORT FROM(INPUT1) TO(OUTPUT) HEADER TRAILER USING(CTL1)      
/*                                                                 
//INPUT1   DD  DSN=FCGL.BPYP667.CNTL(GLGLJ010),                    
//             DISP=SHR                                            
//OUTPUT   DD  DSN=FCGL.BPYP667.CNTL(GLGLJ010),                    
//             DISP=SHR,                                           
//         DCB=*.INPUT1                                            
//CTL1CNTL DD *                                                    
  SORT FIELDS=(3,4,CH,A)                                           
/*

Upvotes: 0

Views: 986

Answers (1)

Shivanshu
Shivanshu

Reputation: 1269

  1. You can use a fake merge

(This is just a pseudo code of a fake merge, so please ignore any syntax errors if any),

//STEP1 EXEC PGM=SORT

//SORTIN DD DSN=YOUR-INP-DSN,DISP=SHR

//SORTOUT DD DSN=&&TEMP1,DISP=SHR

//SYSIN DD *

OUTREC=(1:3,1)

/*

//STEP2 EXEC PGM=SORT

//SORTIN01 DD DSN=&&TEMP1,DISP=SHR

//SORTOUT DD DUMMY or NULLFILE

//SYSIN DD *

MERGE FIELDS=COPY

/*

here STEP2 will fail if your input file not in sequence.

  1. And as a 2nd option, In the JOINKEYS statement when the file is already sorted, we would give the SORTED Keyword if the file is already sorted. And if the records are not in the sorted order, it would terminate.

Upvotes: 0

Related Questions