|
View previous topic :: View next topic
|
| Author |
Message |
Angad
New User
Joined: 22 Apr 2017 Posts: 2 Location: US
|
|
|
|
Hi All,
I need to populate the 1st date of previous month in the header section of my output file.
The job is scheduled to run on first friday of every month.
Example, today's date is 23rd April 2017.
The date in header needs to be 1st March 2017 (20170301 - CCYYMMDD)
I have taken two different approaches to overcome this, however not able to achieve desired results:
1. Subtracting 30 days from &DATENS in HEADER1, below sort card:
SORT FIELDS=COPY
OUTFIL HEADER1=('H',1' ',&DATENS=(4MD)-30)
- This gives me the required Year and Month i.e. previous.
- However the date needs to be the 1st.
- As date of job execution varies, cannot subtract a precise count from date.
- In case I try to overlap the date in header with '01' is gives an error.
2. Using SYMNAMES with SORT:
//SYMNAMES DD *
MDT,S'&YR4.&LMON'
SORT FIELDS=COPY
OUTFIL HEADER1=('H',1' ',MDT,'01')
- This gives me the required Year and date.
- However the current month is populated.
- No subtraction can be performed here in SORT card.
Kindly share in case desired results can be achieved using any of the above method.
Any new approach is also welcome. |
|
| Back to top |
|
 |
John Del
New User

Joined: 27 Apr 2012 Posts: 42 Location: NY
|
|
|
|
I would build a symbolic for the date in a previous sort step, similar to the following:
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
//XORTOUT DD DSN=&&S,DISP=(,PASS),SPACE=(TRK,(1,0),RLSE)
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY,STOPAFT=1
OUTFIL BUILD=(C'FIRST-OF-LAST-MONTH,',DATE2-1,C'01',80:X)
//
|
Output:
| Code: |
FIRST-OF-LAST-MONTH,20170301
|
/* |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Alternatively, you could also append the calculated date value in an OUTREC, and just use it in your HEADER.
| Code: |
//STEP01 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN DD *
RECORD
//SYSIN DD *
SORT FIELDS=COPY
OUTREC OVERLAY=(81:DATE2-1,C'01')
OUTFIL NODETAIL,REMOVECC,HEADER1=('H ',81,8) |
SORTOUT
| Code: |
----+----1--
H 20170301 |
|
|
| Back to top |
|
 |
Angad
New User
Joined: 22 Apr 2017 Posts: 2 Location: US
|
|
|
|
| Arun Raj wrote: |
Alternatively, you could also append the calculated date value in an OUTREC, and just use it in your HEADER.
| Code: |
//STEP01 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SORTIN DD *
RECORD
//SYSIN DD *
SORT FIELDS=COPY
OUTREC OVERLAY=(81:DATE2-1,C'01')
OUTFIL NODETAIL,REMOVECC,HEADER1=('H ',81,8) |
SORTOUT
| Code: |
----+----1--
H 20170301 |
|
Thank you Arun for sharing your approach.
Using the above sort card the required date is populated in the Header section of output file.
However the OVERLAY function populates the required date on the 81st position of all the detail records read from INPUT file.
Any method to populate required date in header section without altering the detail records from input. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It is only required in that position prior to you using it. Once you have used it, it is no longer required, so you get rid of it. BUILD=(1,80) or IFOUTLEN=80 (if you have at least one IFTHEN already).
I'd go with John Del's suggestion. Both solutions work. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|