Checking Header & Trailer
Moderators: Frank Yaeger, Moderator Group
Checking Header & Trailer
I have a CSV file, and i want to check if there a Header & Trailer is there in that file. Else i will have to abend the job.
Can we do it in DFSORT?
Raul
Can we do it in DFSORT?
Raul
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
Sample File
Read the file, if there is no Trailer record, we have to abend the JOb.
Code: Select all
UHDR 20120811 AAAA xxx
000001 160000
000002 150000
000003 150005
000004 151000
000005 151999
UTRL 20120811 00005 xxx
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
Code: Select all
ICE201I H RECORD TYPE IS F - DATA STARTS IN POSITION 1
ICE751I 0 C5-K62149 C6-K90026 C7-K58148 C8-K67572 E4-K58148 C9-BASE E5-K72040
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
Have a look at this one:
http://www.mainframegurukul.com/ibmmain ... 6851#16851
You'll notice it is able to identify the last record. You should be able to apply that to your file and therefore know that it should be a trailer.
If I was doing it, I'd count the headers and trailers as well. Might be fun in Sort
To get a return code, you need an OUTFIL for a file. The file can be DUMMY. If you don't write anything, a return-code can be set. Then you act on that in a subsequent step.
http://www.mainframegurukul.com/ibmmain ... 6851#16851
You'll notice it is able to identify the last record. You should be able to apply that to your file and therefore know that it should be a trailer.
If I was doing it, I'd count the headers and trailers as well. Might be fun in Sort
To get a return code, you need an OUTFIL for a file. The file can be DUMMY. If you don't write anything, a return-code can be set. Then you act on that in a subsequent step.
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
Well, see what you make of this:
The thing is to use the same file for both INA and INB. Play around with the test and you should find RC 4 for: multiple headers; multiple trailers; header not first; trailer not last. Otherwise RC 0.
You could include checking of the data on the header and trailer as well.
Code: Select all
//STEP0100 EXEC PGM=SORT
//CHKOUT DD SYSOUT=*
//SYMNAMES DD *
INPUT-RECORD,*,1,CH
INPUT-TYPE,=,1,CH
REC-COUNT,10,7,ZD
HEADER-COUNT,20,3,ZD
HEADER-FLAG,*,1,CH
TRAILER-COUNT,30,3,ZD
TRAILER-FLAG,*,1,CH
DATA-COUNT,40,7,ZD
* REFORMAT RECORD
REFREC-RECORD,1,60,CH
REFREC-TYPE,=,1,CH
REFREC-SEQ,*,7,CH
REFREC-MATCH-MARKER,10,1,CH
REFREC-V-TYPE,11,1,CH
REFREC-REC-KEY,*,7,CH
REFREC-REC-COUNT,20,7,CH
REFREC-HEADER-COUNT,30,3,CH
REFREC-TRAILER-COUNT,40,3,CH
REFREC-DATA-COUNT,50,7,CH
REFREC-BAD,*,1,CH
REFREC-TRAILER-REC-NO,*,7,CH
COUNT-OF-ONE,+1
A-HEADER,C'H'
A-TRAILER,C'T'
SOME-DATA,C'D'
FIRST-REORD-ON-FILE,C'0000001'
WRONG-PLACE-HEADER,C'Y'
BAD-COUNTS-OR-TRAILER,C'Y'
BAD-TO-REPORT,C'Y'
ON-F2-ONLY-SO-V-RECORD,C'2'
CORRECT-COUNT-OF-ONE,C'001'
INIT-HT-COUNT,C'000'
INIT-DATA-COUNT,C'0000000'
TO-SORT-AFTER-TRAILER,X'FFFFFFFFFFFFFF'
//SYMNOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=INA,FIELDS=(2,7,A),SORTED,NOSEQCK
JOINKEYS F2=INB,FIELDS=(2,7,A)
JOIN UNPAIRED
REFORMAT FIELDS=(F1:1,9,?,F2:1,60)
INREC IFTHEN=(WHEN=GROUP,BEGIN=(REFREC-TYPE,EQ,A-TRAILER),
PUSH=(REFREC-TRAILER-REC-NO:REFREC-SEQ)),
IFTHEN=(WHEN=(REFREC-TYPE,EQ,A-HEADER,
AND,
REFREC-SEQ,NE,FIRST-REORD-ON-FILE),
OVERLAY=(REFREC-BAD:WRONG-PLACE-HEADER)),
IFTHEN=(WHEN=((REFREC-MATCH-MARKER,EQ,ON-F2-ONLY-SO-V-RECORD),
AND,
((REFREC-HEADER-COUNT,NE,CORRECT-COUNT-OF-ONE),
OR,
(REFREC-TRAILER-COUNT,NE,CORRECT-COUNT-OF-ONE),
OR,
(REFREC-TRAILER-REC-NO,NE,REFREC-REC-COUNT))),
OVERLAY=(REFREC-BAD:BAD-COUNTS-OR-TRAILER))
OUTFIL FNAMES=SORTOUT,
INCLUDE=(REFREC-BAD,EQ,BAD-TO-REPORT)
OUTFIL FNAMES=CHKOUT,NULLOFL=RC4,
INCLUDE=((REFREC-MATCH-MARKER,EQ,ON-F2-ONLY-SO-V-RECORD),
AND,
(REFREC-BAD,NE,BAD-TO-REPORT))
//JNF1CNTL DD *
OPTION COPY
INREC OVERLAY=(2:SEQNUM,7,ZD)
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(2:TO-SORT-AFTER-TRAILER)),
IFTHEN=(WHEN=INIT,OVERLAY=(HEADER-COUNT:INIT-HT-COUNT,
TRAILER-COUNT:INIT-HT-COUNT,
DATA-COUNT:INIT-DATA-COUNT)),
IFTHEN=(WHEN=INIT,OVERLAY=(REC-COUNT:C'0000001')),
IFTHEN=(WHEN=(INPUT-TYPE,EQ,A-HEADER),
OVERLAY=(HEADER-COUNT:COUNT-OF-ONE,
ZD,LENGTH=3)),
IFTHEN=(WHEN=(INPUT-TYPE,EQ,A-TRAILER),
OVERLAY=(TRAILER-COUNT:COUNT-OF-ONE,
ZD,LENGTH=3)),
IFTHEN=(WHEN=(INPUT-TYPE,EQ,SOME-DATA),
OVERLAY=(DATA-COUNT:COUNT-OF-ONE,
ZD,LENGTH=7))
SUM FIELDS=(REC-COUNT,HEADER-COUNT,TRAILER-COUNT,DATA-COUNT)
//INA DD *
H
D
D
D
D
D
D
D
D
D
T
D
//INB DD *
H
D
D
D
D
D
D
D
D
D
T
D
You could include checking of the data on the header and trailer as well.
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page