|
View previous topic :: View next topic
|
| Author |
Message |
vnktrrd
New User
Joined: 12 Jan 2010 Posts: 34 Location: New York
|
|
|
|
HI,
Due to huge data in the input file I want to extract only those records with current year in the first date field. It is in the format '2016/01/01'.
I want to do this by comparing the first 4 positions of the file to current year, current month and current date individually.
Please advise how to achieve this using sort card.
Input
2014mmdd
2015mmdd
2016mmdd
Output should be the records of the current year like below.
2016mmdd
I want the same for month and date as well.
Thanks,
Ramana. |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
If you want a sort solution why post in JCL & VSAM? Why didn't you post in the relevant sort sub-section of the forum. Also provide the full information re the dataset - RECFM, LRECL and representative data showing if duplicates could be present and whether they are in sort sequence or not.
Moving to DFSort but if you use Syncsort then say so and it will be moved there. |
|
| Back to top |
|
 |
vnktrrd
New User
Joined: 12 Jan 2010 Posts: 34 Location: New York
|
|
|
|
dataset is of format FB and LRECL is 95 with first field having date in 'YYYYMMDD' format.
There are duplicates in this field and file is sorted in descending order on this field.
Thanks. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Anything wrong with this, and similar?
| Code: |
OPTION COPY
INCLUDE COND=(1,4,CH,EQ,C'2016') |
|
|
| Back to top |
|
 |
vnktrrd
New User
Joined: 12 Jan 2010 Posts: 34 Location: New York
|
|
|
|
| I want the year to be dynamic and match with the current year always. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I doubt that that is true, if you think about it.
First working day of January, you want nothing? Even if it is a December job running late?
You going to force testing data at various levels always to be for the current year? And prevent any testing of what happens around the year end?
Means you can never do a re-run without changing the code.
For what?
Sure you can do it. Not really sure that you really want to.
| Code: |
OPTION COPY
INCLUDE COND=(1,4,CH,EQ,DATE1) |
You can read-up on the documentation of INCLUDE to see why it works. |
|
| Back to top |
|
 |
vnktrrd
New User
Joined: 12 Jan 2010 Posts: 34 Location: New York
|
|
|
|
DATE1 gives us the complete date. But I only want to compare with year.
I wont run this in prod so I don't have to bother about the issue you are mentioning.
Please advise.
Thanks |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I know what DATE1 means, and how long it is.
You can also chose from DATE2, DATE3, DATE4 and DATE5 for this. You can also put & in front of them.
I assumed you'd test it, and wonder how it worked, which is why I pointed you at how to understand how it works.
I wasn't expecting you to tell me it doesn't work without you trying. If you feel it doesn't work, then, well, you'll have to try something else. |
|
| Back to top |
|
 |
kranthikumarb
Active User
Joined: 02 Jan 2009 Posts: 115 Location: Hyderabad
|
|
|
|
vnktrrd,
if you dont find something that gives you CCYY only, you may use this
| Code: |
//STEP001 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD *
2015MMDD
2016MMDD
2014MMDD
2016DDMM
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC OVERLAY=(96:DATE1)
SORT FIELDS=COPY
OUTFIL FNAMES=SORTOUT,BUILD=(1,95),INCLUDE=(96,4,CH,EQ,1,4,CH)
/*
|
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
kranthikumarb,
You didn't like my suggestion either? |
|
| Back to top |
|
 |
kranthikumarb
Active User
Joined: 02 Jan 2009 Posts: 115 Location: Hyderabad
|
|
|
|
Bill,
I tried DATE1,2,3,4,5 etc. But couldn't get CCYY format. Just as a back up plan I gave this idea.
No doubt, your suggestion is easy way to do, if there is a way to get CCYY alone. |
|
| Back to top |
|
 |
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
| Quote: |
Just as a back up plan I gave this idea.
|
Would have been nice if this was known at the beginning.
Those who posted could have given it 'back up' effort as well. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It is clear that no-one is actually trying what I suggested, so here it is in action:
| Code: |
//DATECCYY EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,4,CH,EQ,DATE1)
//SORTIN DD *
20160316 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,6,CH,EQ,DATE1)
//SORTIN DD *
20160316 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,8,CH,EQ,DATE1)
//SORTIN DD *
20160316 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DATECCYY EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,4,CH,EQ,DATE1(/))
//SORTIN DD *
2016/03/16 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,6,CH,EQ,DATE1(/))
//SORTIN DD *
2016/03/16 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER
//DACCYYMM EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTOF01 DD SYSOUT=*
//SORTOF02 DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,8,CH,EQ,DATE1(/))
//SORTIN DD *
2016/03/16 THIS ONE
20151234 NOT THIS ONE
20141234 NOT THIS ONE EITHER |
Run that lot, and look at the SORTOUTs in the spool.
You will see
as output from the first three steps, and
| Code: |
| 2016/03/16 THIS ONE |
as output from the last three steps.
For those who not only don't run the suggested code, but don't read the suggested manual either:
| Quote: |
Tip: When a field is shorter than the character string it's compared to, DFSORT truncates the string on the right. You can take advantage of this to compare a field to only part of the DATE4 timestamp when appropriate. For example:
INCLUDE COND=(1,13,CH,GT,DATE4)
would compare the field in positions 1-13 to the truncated DATE4 constant C'yyyy-mm-dd-hh'. |
What works with DATE4 in the example is not specific to DATE4, it works with all the date constants, edited or not. |
|
| Back to top |
|
 |
John Del
New User

Joined: 27 Apr 2012 Posts: 42 Location: NY
|
|
|
|
If it is the current year and month, sort symbolics utilizing system symbolics.
| Code: |
CCYY,S'&LYR4'
CCYYMM,S'&LYR4.&LMON'
------------------ SYMBOL TABLE -----------------
CCYY,C'2016'
CCYYMM,C'201603'
|
If you want to use a previous date range, generate your own symbolics to be used in the sort step. You could configure to use them as a passed exec parm so that you can override the values as you need to.
| Code: |
// SET OBCDATE='CCYYMM'
//********************************************************
//* GENERATE DATE PARMS FOR DATA EXTRACTION
//********************************************************
//STEP0001 EXEC PGM=SORT,PARM=('JP0"&OBCDATE"')
//SYSOUT DD SYSOUT=*
//SORTIN DD *
CCYYMM MMCCYY MMDDCCYY CCYYDDD
//DATEPARM DD DSN=&&S,DISP=(,PASS,DELETE),UNIT=SYSDA,SPACE=(TRK,(1,1))
//DATEPARX DD SYSOUT=*
//SYSIN DD *
OPTION COPY,STOPAFT=1
* EDIT TO SEE IF THERE IS A PARM DATE OVERRIDE, OTHERWISE USE DEFAULT
* FOR PREVIOUS MONTH, EXPECTS CCYYMM FORMAT AND CONVERTS TO JULIAN
*
INREC IFOUTLEN=80,
IFTHEN=(WHEN=(1,6,CH,NE,JP0),
OVERLAY=(81:JP0,C'01',81:81,8,Y4T,TOJUL=Y4T,
1:81,7,10:81,7,Y4T,LASTDAYM,TOJUL=Y4T),HIT=NEXT),
IFTHEN=(WHEN=(1,6,CH,EQ,JP0),
OVERLAY=(81:DATE2-1,C'01',81:81,8,Y4T,TOJUL=Y4T,
1:81,7,10:81,7,Y4T,LASTDAYM,TOJUL=Y4T))
* BUILD THE SYMBOLICS USED BY SORT
*
OUTFIL FNAMES=(DATEPARM,DATEPARX),
BUILD=(C'BEG-DATE,',1,7,80:X,/,
C'END-DATE,',10,7,80:X)
/*
//STEP0002 EXEC PGM=SORT
//SYMNAMES DD DISP=SHR,DSN=&SYMBLIB(SYMCONST)
// DD DISP=SHR,DSN=&&S
//SYMNOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=&YOURFILE(0)
//SORTOUT DD DSN=&OUTFILE(+1),
// DISP=(NEW,CATLG,DELETE),UNIT=POOL,SPACE=(TRK,(1,1),RLSE)
//SYSIN DD *
OPTION COPY
INCLUDE COND=(SOME-DATE,GE,BEG-DATE,&,
SOME-DATE,LE,END-DATE)
|
J |
|
| Back to top |
|
 |
John Del
New User

Joined: 27 Apr 2012 Posts: 42 Location: NY
|
|
|
|
Bill -
Sorry, only afterwards did I get what you were saying. Please feel free to delete my previous post to avoid confusion.
This would be my solution that would allow users to dynamically override the date parm when based on year (year, month, day, what have you) :
| Code: |
// SET SYMBLIB='CR.#050.PROD.PARMLIB'
// SET OBCDATE='&LYR4'
//*SET OBCDATE='2015'
//*SET OBCDATE='&LYR4.&LMON'
//*SET OBCDATE='201603'
//********************************************************
//* GENERATE DATE PARMS FOR DATA EXTRACTION
//********************************************************
//STEP0001 EXEC PGM=SORT,PARM=('JP0"&OBCDATE"')
//SYMNAMES DD DISP=SHR,DSN=&SYMBLIB(SYMCONST)
// DD *
MY-INPUT-RECORD,1,80,CH
MY-INPUT-YEAR-ZD,=,4,ZD
MY-INPUT-YEAR-CH,=,4,CH
MY-INPUT-DAYS,*,3,ZD
MY-INPUT-DONTCARE,*,73,CH
//SYMNOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD *
//SORTIN DD *
20150316 PAST
2016014I.DONT.CARE.ABOUT.THE.REST
2017014 FUTURE
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INCLUDE COND=(MY-INPUT-YEAR-CH,EQ,JP0)
/*
|
J |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
No problem John. Since I don't like the requirement, I prefer your solutions anyway :-)
I'd do this:
| Code: |
| MY-INPUT-YEAR-CH,=,=,CH |
Just to keep the definition more bound to the original field. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|