|
View previous topic :: View next topic
|
| Author |
Message |
Atul Banke
New User
Joined: 08 Aug 2011 Posts: 7 Location: India
|
|
|
|
Hi,
I need the get the record count of specific type of records and write that count to a summary record. There is one summary record for each group of detail records. E.g my input file format is as below
| Code: |
D|COUNT|111111111111|123.23|XYZ COMMERCE|NEW YORK CITY
R|11111110444A|15022016|0.34|XYZ AFFILIATE|BOSTON
R|11111110444A|15032016|2.44|XYZ AFFILIATE|BOSTON
R|11111110444B|15022016|12.76|XYZ BROTHERS|LA CITY
R|11111110444B|15032016|112.76|XYZ BROTHERS|LA CITY
D|COUNT|222222211111|73.23|ABC CONSTRUCTION|NEW YORK CITY
R|22222220111A|15022016|0.34|ABC CONSTRUCTION|BOSTON
R|22222220111B|15032016|71.63|ABC CONS.|BOSTON |
Output Should have:
| Code: |
D|4|111111111111|123.23|XYZ COMMERCE|NEW YORK CITY
R|11111110444A|15022016|0.34|XYZ AFFILIATE|BOSTON
R|11111110444A|15032016|2.44|XYZ AFFILIATE|BOSTON
R|11111110444B|15022016|12.76|XYZ BROTHERS|LA CITY
R|11111110444B|15032016|112.76|XYZ BROTHERS|LA CITY
D|2|222222211111|73.23|ABC CONSTRUCTION|NEW YORK CITY
R|22222220111A|15022016|0.34|ABC CONSTRUCTION|BOSTON
R|22222220111B|15032016|71.63|ABC CONS.|BOSTON
|
That I just need the count of "R" records under each "D" type records on second field in pipe delimited record.
Could you please suggest a simplest way using DFSORT?
Thanks,
Atul
CODE'd |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| What have you tried? Have you looked up any of the DFSort reference material - programmers guide, getting started, tricks? |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Atul Banke,
The below DFSORT should give you something to start with. I have assumed the input to be FB with an LRECL=80. You might want to modify it as per your requirements.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN ===> Input Data set (FB/LRECL=80)
//T1 DD DSN=&T1,DISP=(,PASS),UNIT=SYSDA
//T2 DD DSN=&T2,DISP=(,PASS),UNIT=SYSDA
//*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(81:ID=4))
OUTFIL FNAMES=T1,BUILD=(1,84)
OUTFIL FNAMES=T2,REMOVECC,NODETAIL,BUILD=(9X),
SECTIONS=(81,4,
TRAILER3=(81,4,COUNT-1=(M10,LENGTH=5)))
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTJNF1 DD DSN=&T1,DISP=SHR
//SORTJNF2 DD DSN=&T2,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(81,4,A),SORTED,NOSEQCK
JOINKEYS FILE=F2,FIELDS=(01,4,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,80,F2:5,5)
SORT FIELDS=COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(3,5,CH,EQ,C'COUNT'),
OVERLAY=(3:81,5),HIT=NEXT),
IFTHEN=(WHEN=ANY,
FINDREP=(IN=C' ',OUT=C'',STARTPOS=3,ENDPOS=6)) |
SORTOUT had
| Code: |
D|4|111111111111|123.23|XYZ COMMERCE|NEW YORK CITY
R|11111110444A|15022016|0.34|XYZ AFFILIATE|BOSTON
R|11111110444A|15032016|2.44|XYZ AFFILIATE|BOSTON
R|11111110444B|15022016|12.76|XYZ BROTHERS|LA CITY
R|11111110444B|15032016|112.76|XYZ BROTHERS|LA CITY
D|2|222222211111|73.23|ABC CONSTRUCTION|NEW YORK CITY
R|22222220111A|15022016|0.34|ABC CONSTRUCTION|BOSTON
R|22222220111B|15032016|71.63|ABC CONS.|BOSTON |
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2290 Location: USA
|
|
|
|
Note #1
Under no circumstances you can get the count of following records before you've read all those records.
You cannot guess in advance what is following next in your file?
It's the same as getting your salary in advance - before starting your job.
At least two steps are required to manipulate with record re-ordering.
But correct way would be creating the totals under your detail records. |
|
| Back to top |
|
 |
Atul Banke
New User
Joined: 08 Aug 2011 Posts: 7 Location: India
|
|
|
|
Hi Arun,
Thanks a lot, it works perfectly fine as you suggested. I was also thinking that using WHEN=GROUP and then join should work but since I didn't know the SECTIONS parameter therefore could not get that working.
Thanks again! |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| At a brief view, you don't need two steps, all the processing of the first step can be specified in the JNF1CNTL and JNF2CNTL files for your single input file (used twice). |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Atul Banke wrote: |
Hi Arun,
Thanks a lot, it works perfectly fine as you suggested. Thanks again! |
You're welcome!. Thanks for letting us know. |
|
| Back to top |
|
 |
magesh23586
Active User

Joined: 06 Jul 2009 Posts: 213 Location: Chennai
|
|
|
|
Arun,
As per Bill advice, We can do this in one step like below.
| Code: |
//STEP01 EXEC PGM=SORT
//SORTJNF1 DD DSN=INPUT.FILE1,DISP=SHR
//SORTJNF2 DD DSN=INPUT.FILE2,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS FILE=F1,FIELDS=(81,6,A)
JOINKEYS FILE=F2,FIELDS=(81,6,A),SORTED,NOSEQCK
JOIN UNPAIRED,F2
REFORMAT FIELDS=(F2:1,80,F1:88,5)
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(3,5,CH,EQ,C'COUNT'),
OVERLAY=(3:81,5,ZD,SUB,+1,EDIT=(IIIIT),81:5X),HIT=NEXT),
IFTHEN=(WHEN=ANY,
FINDREP=(IN=C' ',OUT=C'',STARTPOS=3,ENDPOS=6))
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(88:C'00001')),
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(81:ID=6))
SUM FIELDS=(88,5,ZD)
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(81:ID=6))
|
|
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
magesh23586,
AFAIK it would require the same passes of data.
Besides you have used the SUM operator that requires 'sorting' of data. What I posted earlier was a SORT COPY, which does not require any sorting. Always the direction should be to avoid sorting of data whenever there is no need to. Saving resources should be the priority, we may not always gain by doing something in 'one step'. |
|
| Back to top |
|
 |
magesh23586
Active User

Joined: 06 Jul 2009 Posts: 213 Location: Chennai
|
|
|
|
Arun,
Here is the one step solution without sort . As I mentioned earlier we need not requires two steps
| Code: |
//SYSIN DD *
OPTION COPY
JOINKEYS FILE=F1,FIELDS=(81,6,A,103,1,A),SORTED,NOSEQCK
JOINKEYS FILE=F2,FIELDS=(81,6,A,103,1,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(F1:1,103,?,F2:1,103)
INCLUDE COND=(207,1,CH,NE,C'C')
INREC IFOUTLEN=103,
IFTHEN=(WHEN=(104,1,CH,EQ,C'2'),
OVERLAY=(1:105,103))
OUTREC IFTHEN=(WHEN=INIT,
BUILD=(97,7,1,80)),
IFTHEN=(WHEN=INIT,
FINDREP=(IN=C' ',OUT=C'',STARTPOS=10,ENDPOS=13))
OUTFIL SECTIONS=(1,7,
TRAILER3=(8,80)),NODETAIL,REMOVECC
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(97:C'000001',C'A')),
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(1:1,80,ID=6,SEQ=5)),
IFTHEN=(WHEN=(3,5,CH,EQ,C'COUNT'),
OVERLAY=(3:87,5,ZD,SUB,+1,EDIT=(IIIIT)))
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(81:ID=6,
97:SEQ=6)),
IFTHEN=(WHEN=(1,1,CH,EQ,C'D'),
OVERLAY=(103:C'C')),
IFTHEN=(WHEN=NONE,
OVERLAY=(103:C'B'))
|
|
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
magesh23586,
There is no justification to build a 207 byte record in the REFORMAT to save a step. Keeping the Intermediate file lengths to the possible minimum is as important as getting rid of an unnecessary sort.
Learn to keep things simple and short. Like I mentioned earlier - everything in "one step" might not help always, and that should not be the prime objective of any application. |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
having a single step will make JOB management easier
in case of a failure RESTART from the failing step
for the example posted
a failure in step200 will imply a restart from step100
I would go for easier handling rather than for peephole optimisation |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Below is a "one step" ICETOOL version of the DFSORT solution posted earlier.
| Code: |
//STEP0100 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DISP=SHR,DSN ===> Input Data set (FB/LRECL=80)
//CTL2JNF1 DD DSN=&T1,DISP=(,PASS),UNIT=SYSDA
//CTL2JNF2 DD DSN=&T2,DISP=(,PASS),UNIT=SYSDA
//OUT DD SYSOUT=*
//*
//TOOLIN DD *
COPY FROM(IN) TO(CTL2JNF1) USING(CTL1)
SORT FROM(CTL2JNF1) TO(OUT) USING(CTL2)
//*
//CTL1CNTL DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(81:ID=4))
OUTFIL FNAMES=CTL2JNF1,BUILD=(1,84)
OUTFIL FNAMES=CTL2JNF2,REMOVECC,NODETAIL,BUILD=(9X),
SECTIONS=(81,4,
TRAILER3=(81,4,COUNT-1=(M10,LENGTH=5)))
//CTL2CNTL DD *
JOINKEYS FILE=F1,FIELDS=(81,4,A),SORTED,NOSEQCK
JOINKEYS FILE=F2,FIELDS=(01,4,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,80,F2:5,5)
SORT FIELDS=COPY
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(3,5,CH,EQ,C'COUNT'),
OVERLAY=(3:81,5),HIT=NEXT),
IFTHEN=(WHEN=ANY,
FINDREP=(IN=C' ',OUT=C'',STARTPOS=3,ENDPOS=6)) |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
magesh23586 contacted me yesterday after they noticed outside the 10-minute edit period that they'd included data which was not needed.
I'll try to get some edits done, maybe in the morning, as it is already late here. |
|
| Back to top |
|
 |
magesh23586
Active User

Joined: 06 Jul 2009 Posts: 213 Location: Chennai
|
|
|
|
Arun Raj,
| Arun Raj wrote: |
Below is a "one step" ICETOOL version of the DFSORT solution posted earlier.
|
Though you do it in ICETOOL, your solution is 4 Pass solution (1 for sort copy + 3 for Joinkeys) , which is not at all recommended when there is 1 step( Joinkey 3 Pass) solution is possible.
what will happen when second JOINKEYS Fails for some reason, we need to start sort copy + joinkey again, which means we are wasting resource unnecessarily.
Bill, Please correct me, if i am wrong.
The following code would be optimal + simple, where I am just sorting 12 bytes of records which will be much better than a reading a complete file with Sections. Below is the post I requested Bill to update.
| Code: |
//SYSIN DD *
OPTION COPY
JOINKEYS FILE=F1,FIELDS=(1,6,A)
JOINKEYS FILE=F2,FIELDS=(81,6,A),SORTED,NOSEQCK
JOIN UNPAIRED,F2
REFORMAT FIELDS=(F2:1,80,F1:7,5)
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(3,5,CH,EQ,C'COUNT'),
OVERLAY=(3:81,5,ZD,SUB,+1,EDIT=(IIIIT),81:5X),HIT=NEXT),
IFTHEN=(WHEN=ANY,
FINDREP=(IN=C' ',OUT=C'',STARTPOS=3,ENDPOS=6))
//JNF1CNTL DD *
INREC IFOUTLEN=12,
IFTHEN=(WHEN=INIT,
OVERLAY=(7:C'00001')),
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(1:ID=6))
SUM FIELDS=(7,5,ZD)
//JNF2CNTL DD *
INREC IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(81:ID=6))
|
Avoid Sorting, following code is still better than two step solution. where the combined record read is 116 bytes now.
| Code: |
//SYSIN DD *
OPTION COPY
JOINKEYS FILE=F1,FIELDS=(6,7,A),SORTED,NOSEQCK
JOINKEYS FILE=F2,FIELDS=(1,7,A),SORTED,NOSEQCK
JOIN UNPAIRED,F2
REFORMAT FIELDS=(F2:1,98,?,F1:1,17)
INREC IFTHEN=(WHEN=(99,1,CH,EQ,C'B'),
OVERLAY=(21:100,5)),
IFOUTLEN=98
OUTREC IFTHEN=(WHEN=INIT,
FINDREP=(IN=C' ',OUT=C'',STARTPOS=21,ENDPOS=24))
OUTFIL SECTIONS=(13,6,
TRAILER3=(19,80)),NODETAIL,REMOVECC,BUILD=(1,80)
//JNF1CNTL DD *
INREC IFOUTLEN=18,
IFTHEN=(WHEN=INIT,
OVERLAY=(12:C'A000001')),
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(1:SEQ=5,ID=6)),
IFTHEN=(WHEN=INIT,
OVERLAY=(1:1,5,ZD,SUB,+1,EDIT=(IIIIT)))
//JNF2CNTL DD *
OPTION COPY
INREC IFTHEN=(WHEN=INIT,
BUILD=(6X,C'B',11X,1,80)),
IFTHEN=(WHEN=GROUP,
BEGIN=(19,1,CH,EQ,C'D'),
PUSH=(1:ID=6,13:SEQ=6)),
IFTHEN=(WHEN=(19,1,CH,EQ,C'D'),
OVERLAY=(7:C'A'))
|
|
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
| Bill Woodger wrote: |
| So any solution involving SORT is absurd: wasteful of resources. Unless absolutely necessary :-) |
magesh23586,
I would assume that the above note by Bill in one of the old topics still holds true for your "optimum + simple" solution-1, which involves SORT and SUM.
Moreover, I would think we don't have to restart/abend on a daily basis. So if the copy solution runs fine for 99% of the time, I don't see any problem with that, unless the job fails every day.
Edit: Your second "solution" still has unused bytes if you have not realized it yet. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Problem is, the context of the original from which the quote is taken is the ability to use the OUTFIL reporting features. "Don't use SORT just to use SUM". In JNFnCNTL, there is no possibility to use the OUTFIL reporting features. But in itself, perhaps not enough to use SUM.
It's not the SUM itself that is the problem, it is doing a SORT just to be able to do a SUM, because SORTing is an extensive operation.
I think from Arun's original solution, drop the first OUTFIL and do the appending in the JNF1CNTL. Avoids the "write", and the BUILD (which I can't see why it was needed).
For sure I've seen and used the SUM in JNFnCNTL for this type of task. A separate step I think on balance is going to be a more efficient way to do it than by using the SUM.
From both the suggested solutions, I have another idea. Have to check it first... |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Regarding the solution-2 by magesh23586, we don't really need to complicate things by adding another identifier 'A'.
I would do something like this, if this has to be a "one step" DFSORT thing.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTJNF1 DD DSN= >> Input data set (FB/80)
//SORTJNF2 DD DSN= >> Same Input data set (FB/80)
//SORTOUT DD DSN= >> Output data set (FB/80)
//*
//SYSIN DD *
JOINKEYS FILE=F1,FIELDS=(81,4,A,01,01,A),SORTED,NOSEQCK
JOINKEYS FILE=F2,FIELDS=(01,4,A,10,01,A),SORTED,NOSEQCK
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:85,5,1,80,F2:5,5)
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(8,5,CH,EQ,C'COUNT'),
OVERLAY=(8:86,5),HIT=NEXT),
IFTHEN=(WHEN=ANY,
FINDREP=(IN=C' ',OUT=C'',STARTPOS=08,ENDPOS=11))
OUTFIL REMOVECC,NODETAIL,SECTIONS=(1,5,TRAILER3=(6,80)),BUILD=(80X)
/*
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(81:ID=4,SEQ=5))
/*
//JNF2CNTL DD *
INREC IFOUTLEN=10,
IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'D'),
PUSH=(01:ID=4,SEQ=5)),
IFTHEN=(WHEN=INIT,OVERLAY=(5:5,5,ZD,SUB,+1,M10,LENGTH=5,C'D'))
/* |
My personal preference is not to generate duplicate records and then having to roll up later. I would have to run a performance comparison between the 2 step DFSORT and the above one. I will post it here when I have it. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3112 Location: NYC,USA
|
|
|
|
Just a thought, between these big performance talks and may get avoided with simple approach.
1.Assuming the Header (D) is unique always.
Here is my approach.
a. I am not sure if sequence number is required but in case to sort back or its original order I have added, also '1' for reach record
b.Whenever we get a hit for Header , push the entire header for reach record (append).
c.group them (pushed headers) and count-This gives the details record count to overlay
d.Overlay the count in step c ,when its ONLY header(D) and include only records which has a space at 51:1
I stopped right here and got to go, may be someone can modify to finsh.
| Code: |
//SORTIN DD *
D123
R343
R343
D454
R343
//SYSIN DD *
INREC IFOUTLEN=80,
IFTHEN=(WHEN=INIT,OVERLAY=(30:C'1',40:SEQNUM,8,ZD)),
IFTHEN=(WHEN=GROUP,
BEGIN=(1,1,CH,EQ,C'D'),PUSH=(20:1,5))
OUTFIL REMOVECC,FNAMES=T1,
SECTIONS=(20,5,
TRAILER3=(50:COUNT-1=(M10,LENGTH=1))) |
|
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Hi Rohit,
Just in case if you missed to notice, the approach described above to arrive at the detail record count is already used in one of the tested working solutions posted so far in this topic.
| Rohit Umarjikar wrote: |
c.group them (pushed headers) and count-This gives the details record count to overlay
d.Overlay the count in step c ,when its ONLY header(D) and include only records which has a space at 51:1 |
I could not comprehend how this piece can possibly get to the OPs expected result. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Rohit, the D record has been written out before all its subordinate records have been counted.
Sure, with multiple passes of the data you can do anything, but with more than three passes (at most) it is extremely likely that it would be more resource-effective to just write a program and that would only fail if there were so many records within a group as to not fit within the available storage for the program. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3112 Location: NYC,USA
|
|
|
|
| Quote: |
| I could not comprehend how this piece can possibly get to the OPs expected result. |
let me see when I can have comple SORTCARD. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|