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

to get weekday for a date from input file


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Sathish Gurumoorthy

New User


Joined: 12 Feb 2009
Posts: 33
Location: Chennai, India

PostPosted: Mon Jul 13, 2009 6:23 pm
Reply with quote

Hi,

i have an input file like below. the input file can contain any no of such records with different dates

Code:
07-13-2009


the date is in format MM-DD-YYYY

i want the output as below

Code:
07-13-2009 2


Here 2 indicates the 2nd day (i.e monday) of the week.
the output can look like below too

Code:
07-13-2009 MON
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Mon Jul 13, 2009 7:11 pm
Reply with quote

Hi Sathish,

You can try the below code


SORT FIELDS=COPY
OUTREC FIELDS=(1:1,10,X,
11:11,1,CHANGE=(3,C'2',C'MON',
C'3',C'TUE'),
C'4',C'WED'),
C'5',C'THU'),
C'6',C'FRI'),
C'7',C'SAT'),
C'1',C'SUN'),
NOMATCH=(C'N/A'))

I haven't tried this on mainframe but hope it will work.

Please let me know if it doesn't work.

Thanks And Regards
Rahul Gupta
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Mon Jul 13, 2009 10:13 pm
Reply with quote

Sathish Gurumoorthy,

Sort products do not have the ability to produce the day of week from a given date. However with a bunch of IFTHEN statements we can get the day of the week. In order to help you with that I need to know the LRECL and RECFM of the input dataset along with the position and format of the date field.

Rgupta71,

Please read the question once again and try to answer the question. If you can't test your solution please do NOT post the solution. Satish does NOT have the numerical value of the day of the week in the input. He just have a date field and he needs it to be converted to a numerical number which represents the day of the week or literal name of the day of week.
Back to top
View user's profile Send private message
Sathish Gurumoorthy

New User


Joined: 12 Feb 2009
Posts: 33
Location: Chennai, India

PostPosted: Tue Jul 14, 2009 10:05 am
Reply with quote

Skolusu,

LRECL of the input file is 254 and RECFM is FB. The date field YYYYMMDD starts at 19th position in the input file and it's format is BINARY 9
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Jul 14, 2009 9:13 pm
Reply with quote

Sathish Gurumoorthy,

The following JCL will give you the desired results. I did not do any do any kind of date validation as I assumed that your input has valid dates in CCYYMMDD format in 4 byte binary field at pos 19 in your input.

Code:

//STEP0100 EXEC PGM=SORT                   
//SYSOUT   DD SYSOUT=*                     
//SORTIN   DD DSN=Your input FB 254 byte file,DISP=SHR           
//SORTOUT  DD SYSOUT=*                     
//SYSIN    DD *                           
  OPTION COPY,NOSZERO                                                 
  INREC IFTHEN=(WHEN=INIT,BUILD=(19,4,BI,ZD,LENGTH=8)),               
  IFTHEN=(WHEN=(5,2,ZD,LT,3),OVERLAY=(9:1,4,ZD,SUB,+1,EDIT=(TTTT),     
  13:5,2,ZD,ADD,+10,EDIT=(TT),15:9,4,ZD,DIV,+100,EDIT=(TTTT),         
  19:9,4,ZD,MOD,+100,EDIT=(TT))),                                     
  IFTHEN=(WHEN=(5,2,ZD,GE,3),OVERLAY=(9:1,4,                           
  13:5,2,ZD,SUB,+2,EDIT=(TT),15:9,4,ZD,DIV,+100,EDIT=(TTTT),           
  19:9,4,ZD,MOD,+100,EDIT=(TT)))                                       
  OUTREC IFTHEN=(WHEN=INIT,                                           
  OVERLAY=(21:((+26,MUL,13,2,ZD),SUB,+2),DIV,+10,M11,LENGTH=8)),       
  IFTHEN=(WHEN=INIT,                                                   
  OVERLAY=(29:21,8,ZD,ADD,7,2,ZD,ADD,19,2,ZD,M11,LENGTH=8)),           
  IFTHEN=(WHEN=INIT,                                                   
  OVERLAY=(37:29,8,ZD,ADD,(19,2,ZD,DIV,+4),ADD,(15,4,ZD,DIV,+4),       
           M11,LENGTH=8)),                                             
  IFTHEN=(WHEN=INIT,                                                   
  OVERLAY=(45:(37,8,ZD,SUB,(+2,MUL,15,4,ZD)),MOD,+7,LENGTH=8)),       
  IFTHEN=(WHEN=(45,8,SFF,LT,0),OVERLAY=(53:+7,ADD,45,8,SFF,EDIT=(T))),
  IFTHEN=(WHEN=(45,8,SFF,GT,0),OVERLAY=(53:45,8,SFF,EDIT=(T)))         
  OUTFIL IFOUTLEN=20,                                                 
  IFTHEN=(WHEN=INIT,BUILD=(1,4,C'-',5,2,C'-',7,2,53,1)),               
  IFTHEN=(WHEN=(11,1,ZD,EQ,0),OVERLAY=(11:C' SUNDAY   ')),             
  IFTHEN=(WHEN=(11,1,ZD,EQ,1),OVERLAY=(11:C' MONDAY   ')),             
  IFTHEN=(WHEN=(11,1,ZD,EQ,2),OVERLAY=(11:C' TUESDAY  ')),             
  IFTHEN=(WHEN=(11,1,ZD,EQ,3),OVERLAY=(11:C' WEDNESDAY')),             
  IFTHEN=(WHEN=(11,1,ZD,EQ,4),OVERLAY=(11:C' THURSDAY ')),             
  IFTHEN=(WHEN=(11,1,ZD,EQ,5),OVERLAY=(11:C' FRIDAY   ')),             
  IFTHEN=(WHEN=(11,1,ZD,EQ,6),OVERLAY=(11:C' SATURDAY '))             
/*


The output will be of this format

Code:

2008-03-01 SATURDAY   
2008-02-28 THURSDAY   
2009-02-28 SATURDAY   
2009-07-13 MONDAY     
2009-07-14 TUESDAY   
2009-07-15 WEDNESDAY 
Back to top
View user's profile Send private message
Sathish Gurumoorthy

New User


Joined: 12 Feb 2009
Posts: 33
Location: Chennai, India

PostPosted: Wed Jul 15, 2009 5:07 pm
Reply with quote

Thanks Skolusu icon_smile.gif
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Nov 17, 2009 4:43 am
Reply with quote

Sathish Gurumoorthy

With z/OS DFSORT V1R5 PTF UK51706 or z/OS DFSORT V1R10 PTF UK51707, you can use the new date conversion function WEEKDAY like shown below to get the desired results . This job also validates the dates. If an invalid date is found then the output will have asterisks
Code:

//STEP0100 EXEC PGM=SORT                   
//SYSOUT   DD SYSOUT=*                     
//SORTIN   DD DSN=Your input FB 254 byte file,DISP=SHR           
//SORTOUT  DD SYSOUT=*                     
//SYSIN    DD *         
  OPTION COPY                                           
  INREC IFTHEN=(WHEN=INIT,BUILD=(19,4,BI,ZD,LENGTH=8)), 
  IFTHEN=(WHEN=INIT,BUILD=(1,8,Y4T,TOGREG=Y4T(-),X,     
                           1,8,Y4T,WEEKDAY=CHAR9))       
//*


For complete details on date conversion functions and the other new functions available with the Nov, 2009 DFSORT PTF, see:

www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000174
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top