IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Check if any Detail records and extract count from Trailer


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Mon May 08, 2017 8:54 pm
Reply with quote

Hi All,

The requirement is below.

Input:(LRECL=80,RECFM=FB)

Code:

01 HEADER
02 DETAIL
02 DETAIL
02 DETAIL
99 0000003


Expected Output:(LRECL=80,RECFM=FB)

Code:

RECORDS RECEIVED
MM/DD/YY COUNT RECEIVED 0000003


In words, the requirement is check if there are any 'D' records in the input. If any, then produce the output like shown above and put the count from the trailer record.

If there are no 'D' records, set return code to 4

Can this be done using syncsort?

I built this card, but it doesn't return 4 when there are no '02'. Also, I know why it doesn't, it is because of the INCLUDE. Here H1,H2 are the symbols I used to put the text

Code:

OPTION COPY,NULLOUT=RC4                           
INCLUDE COND=(1,2,ZD,EQ,02,OR,1,2,ZD,EQ,99)       
OUTFIL IFTHEN=(WHEN=(1,2,ZD,EQ,99),               
        BUILD=(H1,80:X,/,&DATE,X,H2,X,4,7,80:X)),
        OMIT=(1,2,ZD,EQ,02)                       


Please let me know if there are any ideas.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Mon May 08, 2017 9:13 pm
Reply with quote

Why are you even looking for a '02' record? If there is No '02' record then the trailer count must be 0000000 (Or there may not be a trailer at all). If trailer count is greater than 0 (Or if there is a trailer) then that means there must be a detail record. So, you can only look at trailer count to tell whether you have a detail record (and their count). Isn't it?

.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Mon May 08, 2017 9:20 pm
Reply with quote

Thanks for the reply Rahul.

That is the ideal case, but we don't want to trust the input since it was manually prepared. So, we want to check what was 'actually' sent in the input.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Mon May 08, 2017 11:50 pm
Reply with quote

This should give you the desired result but you'll get the output with count 0 if no '02' found. There may be better solutions available icon_confused.gif
Code:
//STEPSORT EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN   DD *
01 HEADER
03 DETAIL
03 DETAIL
03 DETAIL
99 0000003
//OUT1    DD SYSOUT=*
//OUT2    DD SYSOUT=*
//SYSIN DD *
 OPTION COPY
 INCLUDE COND=(1,2,ZD,EQ,02)
 OUTFIL FNAMES=OUT1,
 TRAILER1=(C'TEXT1',/,C'TEXT2',COUNT),NODETAIL
 OUTFIL FNAMES=OUT2,
 TRAILER1=(C'TEXT1',/,C'TEXT2',COUNT),NULLOFL=RC4
/*
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Tue May 09, 2017 12:02 am
Reply with quote

Quote:
That is the ideal case, but we don't want to trust the input since it was manually prepared. So, we want to check what was 'actually' sent in the input.
RahulG31 is right.
You can not pretend the mistakes and code for the whole world.
This link will help you to do what you want in a prior step.
ibmmainframes.com/about57751.html
or think how to twist more if you would like to merge in one step.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 12:24 am
Reply with quote

Quote:
You can not pretend the mistakes and code for the whole world.


Agreed, but the fundamentals needed for the functionality to work in the first place need to be verified before such functionality is triggered. So, for any file with header, details and trailer, we tend to verify if the detail records exist or count is as same as the trailer. These validations run day in and day out in all the shops I worked.

So, that is why I was posting this requirement.

Anyways thank you all for your help.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Tue May 09, 2017 12:29 am
Reply with quote

Quote:
These validations run day in and day out in all the shops I worked.

And still you don't know how to do it?

Btw, a slight modification in above sort card, making Out2 as Dummy and No need for Trailer1 for Out2 (tested with DFSORT as I don't have SyncSort):
Code:
//OUT2    DD DUMMY
//SYSIN DD *
 OPTION COPY
 INCLUDE COND=(1,2,ZD,EQ,02)
 OUTFIL FNAMES=OUT1,
 TRAILER1=(C'TEXT1',/,C'TEXT2',COUNT),NODETAIL
 OUTFIL FNAMES=OUT2,INCLUDE=(1,2,ZD,EQ,02),NULLOFL=RC4
/*


.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 12:33 am
Reply with quote

Quote:
And still you don't know how to do it?
Wow, this is inspiring.

I do know how to do it, but this one is different, I only asked for a suggestion. If you look at my piece of code, I did achieve what I could for the first part. I was not asking how to count the records from the input file(like your piece of code does), I said to pull the count from the trailer.

Thanks for your effort spent on my ask. I will look for other options.

Thanks again.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Tue May 09, 2017 12:47 am
Reply with quote

Quote:
I said to pull the count from the trailer.

This is even simpler if you make a slight modification in my sort card. I don't know what other options are you looking for.

.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 12:57 am
Reply with quote

Code:
 INCLUDE COND=(1,2,ZD,EQ,02)


1. This one includes only detail records, how would you bring the count if you don't even include the trailer?

Code:
OUTFIL FNAMES=OUT2,INCLUDE=(1,2,ZD,EQ,02),NULLOFL=RC4


2. This one copies all the details into other output file. I don't want to create a copy of my input file again.

3. why am I creating 2 output files when there is a need for only one output file?
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Tue May 09, 2017 1:06 am
Reply with quote

So, ultimately you want me to do the job for you which I nearly did in the previous post but you are Not even able to think on how to make a simple change.
Code:
//OUT2    DD DUMMY
//SYSIN DD *
 OPTION COPY
 INCLUDE COND=(1,2,ZD,EQ,02,OR,1,2,ZD,EQ,99)
 OUTFIL FNAMES=OUT1,INCLUDE=(1,2,ZD,EQ,99),
   BUILD=(C'TEXT1',/,C'TEXT2',X,4,7)
 OUTFIL FNAMES=OUT2,INCLUDE=(1,2,ZD,EQ,02),NULLOFL=RC4
/*

Since you don't even know how to read a JCL/Sort card, I would like to tell that you are Not creating 2 files, and that is what I said in my previous post to have OUT2 as Dummy. Out2 is only used to give you RC4 when needed.

Mods, Please Lock the topic. Enough of the crap already.

.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 1:15 am
Reply with quote

I didn't say you do the whole job for me, I was missing something in my original card.

If you just see my control card, I have the same INCLUDE condition like yours now and we both have the same build statements too, except I used symbols since they are long in size.

so, like I said I did the majority part. I even coded NULLOUT I was only missing to join both in one step.

The only piece missing was the last one OUT2. I noticed you put DUMMY, but the thing is it will try to copy ALL the records even though it is Dummy. Dummy essentially means a temp file for JES, there would I/O involved. Dummy doesn't mean that it doesn't create any file. you can just run the card and see the sysout, so I was trying to reduce the I/O.

So, I am really thankful for your efforts. I am not sure why you are getting upset at the lines, those are only questions.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Tue May 09, 2017 1:21 am
Reply with quote

Did you even look at the link shared to you? What is missing there that you don't understand?
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 1:22 am
Reply with quote

I would look again Rohit, let me read thru. Thank you
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 2:00 am
Reply with quote

I've leveraged the missing piece Rahul provided with OUT2 and hooked it into my card and added ACCEPT parm to just copy one record. So, I think the piece works now. It looks like this now.


Code:
 
OPTION COPY                                                   
INCLUDE COND=(1,2,ZD,EQ,02,OR,1,2,ZD,EQ,99)                   
OUTFIL  BUILD=(H1,80:X,/,&DATE,X,H2,X,48,7,80:X),FNAMES=OUT1, 
        OMIT=(1,2,ZD,EQ,02)                                   
OUTFIL FNAMES=OUT2,NULLOFL=RC4,SAVE,ACCEPT=1                   
 


Thank you Rohit and Rahul.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Tue May 09, 2017 2:01 am
Reply with quote

V S Amarendra Reddy,

Quote:
but the thing is it will try to copy ALL the records

If you don't want to copy all the records then just use STARTREC and ENDREC (=1) in OUTFIL and that will give you only a single record in OUT2. That way you are Not copying all the records. BUT you say that you'll look for other options.

I am trying to be more polite.

Code:
 OUTFIL FNAMES=OUT2,INCLUDE=(1,2,ZD,EQ,02),STARTREC=1,ENDREC=1,
 NULLOFL=RC4 

.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 2:07 am
Reply with quote

Rahul,

Yeah, I think we did pretty much same thing with your idea with just change in ACCEPT or START REC/END REC. I just posted one min before that's all icon_smile.gif.

Thanks man. Have a nice evening.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Tue May 09, 2017 2:10 am
Reply with quote

Amar,

If you are just trying to validate the trailer count AND to check if you have '02' records in it, you could do something like this and then forget worrying about the two outputs.

I don't have Syncsort, but this should get you going.
You might want to modify the BUILD below as in your original card to format the SORTOUT, the way you wanted to. Good luck.
Code:
//STEP01  EXEC PGM=SORT                                             
//SYSOUT    DD SYSOUT=*                                             
//SORTIN    DD *                                                   
01 HEADER                                                           
02 DETAIL                                                           
02 DETAIL                                                           
02 DETAIL                                                           
99 0000003                                                         
//SORTOUT   DD SYSOUT=*                                               
//SYSIN     DD *                                                     
  INCLUDE COND=(1,2,SS,EQ,C'02,99')                                 
  SORT FIELDS=COPY                                                   
  OUTREC OVERLAY=(81:SEQNUM,7,ZD,START=0)                             
  OUTFIL INCLUDE=(1,2,CH,EQ,C'99',AND,4,7,ZD,EQ,81,7,ZD),NULLOFL=RC4,
         BUILD=(1,80)                                               

SORTOUT had:
Code:
99 0000003
You get an RC=4 AND an empty SORTOUT if there are no '02' records OR if the trailer count is incorrect.
Back to top
View user's profile Send private message
V S Amarendra Reddy

Active User


Joined: 13 Sep 2006
Posts: 220
Location: USA

PostPosted: Tue May 09, 2017 2:39 am
Reply with quote

Beautiful, Arun icon_smile.gif. Yeah that is another way look at the requirement. Always, the count must be the same as the Trailer and that condition check can be leveraged for returning the code 4. I think I just need to hook my Build card and use it.

Thanks a ton icon_smile.gif
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Tue May 09, 2017 2:45 am
Reply with quote

You're welcome. Glad it helped. icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts combine multiple unique records into ... DFSORT/ICETOOL 2
No new posts SORT on detail record, then repeat he... DFSORT/ICETOOL 3
No new posts CA7 count with DATE variable CA Products 0
No new posts To Omit records based n SORT condition DFSORT/ICETOOL 6
No new posts Using Multiple IFTHEN and WHEN condit... SYNCSORT 12
Search our Forums:

Back to Top