Page 1 of 1

I want to remove header and trailer using sort

PostPosted: Wed Jan 24, 2018 12:13 pm
by pgkkreddy1
Hi,
Good morning!

I have file with header like this '***HEADER***' and trailer is ***TRAILER***. I want to process the file when we have both header and trailer.
1.if only header record present we should not process the file
2.If only trailer record present we should not process the file

if I use below code, it is handling if file has both header and trailer. if file has only header or trailer it Is not working.

Please help me out.

I used the below code :

//STEP1    EXEC PGM=SORT,PARM='NULLOUT=RC4'      
//SYSOUT   DD SYSOUT=*                            
//SYSPRINT DD SYSOUT=*                            
//SYSUDUMP DD SYSOUT=*                            
//SORTIN   DD DSN=INPUT.FILE.NAME,DISP=SHR        
//SORTOUT  DD SYSOUT=*                            
//SYSIN    DD *                                  
   SORT FIELDS=COPY                              
   INCLUDE COND=(01,12,CH,EQ,C'***HEADER***',OR,  
                 01,13,CH,EQ,C'***TRAILER***')    
   END                


Scenarios like below:

1.it has to process : This working with above code) - return code -RC0

000001 ***HEADER***      
 000002 0000000000007FT9X  
 000003 000000000000Y4ZPM  
 000004 0000000000007GSXB  
 000005 000000000000YPLCL  
 000006 000000000000VM5DT  
 000007 0000000000000000000
 000008 000000000000X34T3  
 000009 ***TRAILER***  


2.Below should not process: (This working with above code) - RC4
0000000000007FT9X  
000000000000Y4ZPM  
0000000000007GSXB  
000000000000YPLCL  
000000000000VM5DT  
0000000000000000000
000000000000X34T3  


3.Below should not process: (This is not working with above code)
***HEADER***        
0000000000007FT9X  
000000000000Y4ZPM  
0000000000007GSXB  
000000000000YPLCL  
000000000000VM5DT  
0000000000000000000
000000000000X34T3  


4.Below should not process: (This is not working with above code)

0000000000007FT9X    
000000000000Y4ZPM    
0000000000007GSXB    
000000000000YPLCL    
000000000000VM5DT    
0000000000000000000  
000000000000X34T3    
***TRAILER***  


Regards,
kk

Re: I want to remove header and trailer with diffent scenar

PostPosted: Thu Jan 25, 2018 12:05 am
by pgkkreddy1
Can some one please help on this

Re: I want to remove header and trailer using sort

PostPosted: Thu Jan 25, 2018 12:19 am
by Robert Sample
Can some one please help on this
Prompting for replies like this is the one way that is pretty much guaranteed to NOT get you answers. People who respond on this forum are volunteers -- as in, they answer if they have knowledge of the topic, the time to write a response, and the interest to write a response. If you have a time-sensitive question, a forum is NOT the way to go; convince your management to hire a consultant to provide you help. Answers may take hours ... or days ... or weeks ... or months ... or years to appear; this is normal and expected. If you had waited a week or two without any responses, that would be a pretty good clue that nobody on this forum can help you (for whatever reason). But prompting after just 12 hours indicates the people who would normally respond will not respond since they're not going to want the hassle of dealing with your time demands.

Furthermore, it appears that you do not understand the difference between OR and AND in the INCLUDE statement. I recommend you go back and read the manual until you do understand (no matter how many times you have to read it, nor how long it takes) the difference.

Re: I want to remove header and trailer using sort

PostPosted: Thu Jan 25, 2018 12:46 am
by pgkkreddy1
Sorry Robert. I can wait..

Re: I want to remove header and trailer using sort

PostPosted: Thu Jan 25, 2018 1:19 am
by Robert Sample
While you wait, read up on the difference between AND / OR on the INCLUDE statement.

Re: I want to remove header and trailer using sort

PostPosted: Thu Jan 25, 2018 1:38 am
by enrico-sorichetti
IIRC the or/and condition applies ONLY to comparisons for the record being processed.
the requirement needs two steps.. extract and check the count for 2 records

Re: I want to remove header and trailer using sort

PostPosted: Sat Feb 10, 2018 12:41 am
by Aki88
Hello,

Unsure if this requirement is still open; if it is not, then this might help.

As Mr. Sorichetti and Mr. Sample have already pointed out, INCLUDE is needed but is to be used a little differently.
The primary challenge here is that, you'll not come to know about the properties of the tail record unless you've read it, which can be done by either:
a. Reading the complete dataset
b. Reading the dataset in reverse, but then you miss the header (unless you read the complete DS)

Here is a solution using *SORT; the code is untested as I no longer have access to a mainframe, but errors if any, should be minor and can be easily resolved:


//STEP001  EXEC PGM=SORT              
//SORTMSG  DD SYSOUT=*                
//SYSOUT   DD SYSOUT=*                
//SORTIN   DD *                        
HEAD                                  
ASDFLASJHDF                            
ASF                                    
ASDF                                  
ASDFGGDFSAGLLJH                        
TAIL                                  
/*                                    
//HEAD     DD DSN=&&HEAD,              
//            DISP=(NEW,PASS,DELETE),  
//            DCB=(RECFM=FB,LRECL=80),
//            SPACE=(TRK,(1,1),RLSE)  
//DATA     DD DSN=&&DATA,              
//            DISP=(NEW,PASS,DELETE),  
//            DCB=(RECFM=FB,LRECL=80),
//            SPACE=(TRK,(1,1),RLSE)  
//TAIL     DD DSN=&&TAIL,              
//            DISP=(NEW,PASS,DELETE),  
//            DCB=(RECFM=FB,LRECL=80),            
//            SPACE=(TRK,(1,1),RLSE)              
//SYSIN    DD *                                  
 SORT FIELDS=COPY                                
 OUTFIL FNAMES=HEAD,NULLOFL=RC4,                  
        INCLUDE=(1,4,CH,EQ,C'HEAD')              
 OUTFIL FNAMES=DATA,                              
        OMIT=((1,4,CH,EQ,C'HEAD'),OR,            
              (1,4,CH,EQ,C'TAIL'))                
 OUTFIL FNAMES=TAIL,NULLOFL=RC4,                  
        INCLUDE=(1,4,CH,EQ,C'TAIL')              
/*                                                
//STEP002  EXEC PGM=SORT,COND=(0,NE)              
//SORTMSG  DD SYSOUT=*                            
//SYSOUT   DD SYSOUT=*                            
//SORTIN   DD DSN=&&HEAD,DISP=(OLD,DELETE,DELETE)
//         DD DSN=&&DATA,DISP=(OLD,DELETE,DELETE)
//         DD DSN=&&TAIL,DISP=(OLD,DELETE,DELETE)
//SORTOUT  DD SYSOUT=*                            
//SYSIN    DD *                                  
 SORT FIELDS=COPY                                
/*