View previous topic :: View next topic
|
Author |
Message |
oerdgie
New User
Joined: 22 Nov 2007 Posts: 64 Location: Germany
|
|
|
|
Hi folks,
I have an input file containg two fields :
Year/month and a counter :
201202 003
201204 001
201205 004
The output file should contain records like this :
201201 000
201202 003
201203 000
201204 001
201205 004
201206 000
Is it posible to add records to the output file which are missing in the input file using SORT ?
Thanks in advance |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you have a limited number of years, with a (naturally) limited number of months, then it would be possibly by generating a file of YYYYMM and then using that file in a JOINKEYS, with JOIN UNPAIRED,F1,F2 (with the generated file as F2).
For unmatched F1, matched F1-F2, output the F1 unchanged. For unmatched F2, output the F2.
If that is not what you have, then your reading of enrico's link will get you to write a program in a general-purpose language, or code-up (manually or generated) a lot of statements and possible multiple passes to do it in DFSORT. |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
A simpler approach would be create a second input file containing your 'zero' values for each month.
Concatenate the two files together, and sort on your key with sum fields=none.
The zero value file will fill in the gaps.
See example and results:
Code: |
//SORT1 EXEC PGM=SORT
//*
//SYSUDUMP DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//*
//SORTIN DD *
201202 003
201204 001
201205 004
/*
// DD *
201201 000
201202 000
201203 000
201204 000
201205 000
201206 000
/*
//*
//SORTOUT DD SYSOUT=Z
//*
//SYSIN DD *
SORT FIELDS=(01,06,CH,A),EQUALS
SUM FIELDS=NONE
/*
//* |
Results:
Code: |
********************************* TOP OF DATA ********
201201 000
201202 003
201203 000
201204 001
201205 004
201206 000
******************************** BOTTOM OF DATA ****** |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, Dave, unproblematic with what has been shown.
I'm expecting to discover that it is subordinate to a key, where it is lots of SORT code, or needing to SORT the data, or generating a sizeable file, rather than a simple program. |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
Bill,
I try to formulate my approach to the facts I have in front of me (I know foolish on this forum).
I do no assuming facts not in evidence.
If the OP ever gets back on, we will see what happens. |
|
Back to top |
|
|
oerdgie
New User
Joined: 22 Nov 2007 Posts: 64 Location: Germany
|
|
|
|
Bill,
I always consider the actuall year, so the max. number of output records will be twelve. I will try your suggestion, creating a small REXX for generating YYYYMM and following DFSORT with JOINFILE.
Thank you very much for help ! |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You can do the generation with SORT as well.
Have a look at REPEAT on OUTFIL. You have 2014 on SYSIN, REPEAT=12, and OVERLAY a SEQNUM which is two digits zoned-decimal.
Do look at Dave's suggestion as well. |
|
Back to top |
|
|
|