0

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)                                           
/*
Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
  • Which SORT product do you have (nothing can be done with "JCL", JCL only sets things up for programs to do work). Why the COBOL tag? Why do you want to check it is in sequence? What is the key. Use the edit link under your question to provide the information. – Bill Woodger Apr 28 '15 at 10:38
  • Thanks. You missed an answer to why you want to do that. Also, you show use of DATASORT, which in your example is ignoring the first and last records. Does the entire file have to be in sequence, or in sequence except for the first and last record? Also, why the COBOL tag on your question? What does it have to do with COBOL? Which SORT product do you have, DFSORT, SyncSORT or, unlikely, CA-SORT? – Bill Woodger Apr 28 '15 at 10:48
  • DFSORT; check if company number in column 3 is in Sequence – thabrlo phungo Apr 28 '15 at 11:46
  • OK, thanks, but why do you want to check it is in sequence? What about the header and trailer? With SORT you're not going to get a controlled abend or a specific message. You can get a specific RC and work from that in another step. – Bill Woodger Apr 28 '15 at 12:34
  • You have another question now. How about finishing this one? – Bill Woodger May 14 '15 at 12:39

1 Answers1

0
  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.
Shivanshu
  • 1,230
  • 1
  • 11
  • 17
  • What is STEP1 supposed to do? STEP2 is just a COPY operation, so no key, so how is that going to fail? How are you going to get an abend which OP wants? OP's wandered off anyway, although a single-file MERGE with the key to be checked is the answer, and the JOINKEYS you describe would also fail (and would already use more resources). – Bill Woodger May 13 '15 at 22:47
  • Joinkeys I have not tested yet, but the 1st case (merge), I did sometines back. Step1 is just simplifying the op and Step2 WILL abend if data is out of sequence. I will provide the working JCL instead of pseudo code asap. – Shivanshu May 14 '15 at 08:10
  • A MERGE with a key, `MERGE FIELDS=(....)` will *fail*, not necessarily *abend*, if the data is in sequence on that key. A MERGE FIELDS=COPY *will not* fail and definitely won't abend, as for a COPY *there is no sequence to check*. Note that a MERGE copy is the same as a SORT COPY, and requires SORTIN not SORTIN01. – Bill Woodger May 14 '15 at 10:50
  • There is no need to "simplify the data" in any way. That would just waste resources. If you notice the actual question, there are header and trailer on the file. And no indication yet of why they wanted to do this. – Bill Woodger May 14 '15 at 10:53
  • Step1 was for just to make things clear, and yes it was MERGE FIELDS, please modify accordingly when free... – Shivanshu May 14 '15 at 22:41