Checking Header & Trailer

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Checking Header & Trailer

Post by raulravi » Thu Oct 11, 2012 5:02 pm

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

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Thu Oct 11, 2012 7:32 pm

Yes.

Is there any way to identify them other than physical position?

raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Post by raulravi » Fri Oct 12, 2012 5:06 pm

Sample File

Code: Select all

UHDR 20120811 AAAA xxx
000001 160000
000002 150000
000003 150005
000004 151000
000005 151999
UTRL 20120811 00005 xxx
Read the file, if there is no Trailer record, we have to abend the JOb.

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Fri Oct 12, 2012 7:04 pm

What if there is a trailer, but the contents of the trailer do not reflect the file?

What if there is no header? Where are you going to check the date on the header?

What if there are multiple headers and trailers?

Abending is not so easy. A non-zero return code may be possible, would that do?

raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Post by raulravi » Mon Oct 15, 2012 9:34 am

Yes William,

A non-zero return code should do i guess.

In my next JSTEP i will place a check If RC=0 proceed else stop.

Ravi

raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Post by raulravi » Mon Oct 15, 2012 1:13 pm

But how to verify that the file has got the Trailer record at the end?

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Mon Oct 15, 2012 1:35 pm

What level of DFSORT do you have? Look at the ICE201I message from a Sort step and post it, please.

raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Post by raulravi » Mon Oct 15, 2012 1:53 pm

My Objective is to copy the File only if it has got Both Header & Trailer Record.

If Trailer Record is not present, i will have to stop the copying..

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Mon Oct 15, 2012 2:37 pm

And this somehow prevents you from answering the questions so that it might be possible to help you without wasting time?

raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Post by raulravi » Mon Oct 15, 2012 5:48 pm

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

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue Oct 16, 2012 12:16 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.

raulravi
Member
Posts: 47
Joined: Mon Apr 18, 2011 9:51 am
Location: India

Post by raulravi » Tue Oct 16, 2012 9:00 am

Pardon me , i could'nt get that... Its very complex & Vague.

Can you make it simple & clear?

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Tue Oct 16, 2012 1:24 pm

Well, see what you make of this:

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
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.

Post Reply

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



Other References
Mainframe Tools and others