Page 1 of 1

convert date to YMMDD Formate

PostPosted: Sat Mar 12, 2011 12:13 am
by rjambu
Hi all,
I have a requirement that needs the date (YYYYMMDD) column 4 in the input file need to be converted to YMMDD.
The Input always have 8 bytes of Gregorian date for the Date field 3 and 4

Req output formate for the 2 date fields are below:

Col3 - MMDDYY
Col4 - YMMDD

I tried with the below JCL, but for Column 4 i not sure how to convert to 'YMMDD' Formate

Thanks JRS.
Input file:

AB80¦105¦20110125¦20110125¦
FG80¦105¦20110125¦20110125¦


//STEP010 EXEC PGM=SORT 
//SYSOUT   DD SYSOUT=*   
//SORTIN   DD  DSN=A.B.C,DISP=SHR     
//SORTOUT  DD  DSN=A.B.D,           
//             UNIT=DISK,SPACE=(TRK,(1,2),RLSE),   
//             DCB=(LRECL=35,BLKSIZE=0,RECFM=FB), 
//             DISP=(NEW,CATLG,DELETE)             
//SYSSORT  DD SYSOUT=*                             
//SYSUDUMP DD SYSOUT=*                             
//*                                                 
//SYSIN    DD  *                                   
SORT FIELDS=COPY                                   
INREC PARSE=(%00=(ENDBEFR=X'6A',FIXLEN=05),
             %01=(ENDBEFR=X'6A',FIXLEN=03),
             %02=(ENDBEFR=X'6A',FIXLEN=08),
             %03=(ENDBEFR=X'6A',FIXLEN=08)),
  BUILD=(%00,%01,%02,Y4T,TOGREG=Y2Y,%03,Y4T,TOGREG=Y2Y)                       

/*
//

Re: convert date to YMMDD Formate

PostPosted: Sat Mar 12, 2011 12:46 am
by Frank Yaeger
I'm not sure why you're using PARSE considering that your fields all seem to be in fixed positions, but ...

You don't need to "Convert" the date in this case - you just need to move the pieces of the date around. Here's a DFSORT job that will do what you asked for:

//S1 EXEC PGM=SORT                                   
//SYSOUT DD SYSOUT=*                                 
//SORTDIAG DD DUMMY                                 
//SORTIN DD *                                       
AB80¦105¦20110125¦20110125¦                         
FG80¦105¦20110125¦20110125¦                         
QQQQ¦105¦20120507¦20131231¦                         
//SORTOUT DD SYSOUT=*                               
//SYSIN DD *                                         
  OPTION COPY                                       
  INREC IFTHEN=(WHEN=INIT,                           
   PARSE=(%00=(ENDBEFR=X'6A',FIXLEN=05),             
             %01=(ENDBEFR=X'6A',FIXLEN=03),         
             %02=(ENDBEFR=X'6A',FIXLEN=08),         
             %03=(ENDBEFR=X'6A',FIXLEN=08)),         
  BUILD=(%00,%01,%02,%03)),                         
 IFTHEN=(WHEN=INIT,                                 
   BUILD=(1,8,X,13,4,11,2,X,20,5))                   
/*


SORTOUT would have:

AB80 105 012511 10125   
FG80 105 012511 10125   
QQQQ 105 050712 31231