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

Need to convert date format


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

Active User


Joined: 20 Apr 2022
Posts: 141
Location: India

PostPosted: Thu Nov 16, 2023 5:40 pm
Reply with quote

Hi Team ,

I have a dataset a gdg version which looks like below, I have date in position 67 to 75 in format 10-MAR-24 and it changes every day accordingly.

file:
Code:
 Command ===>                                                  Scroll ===> CSR 
 =COLS> --3----+----4----+----5----+----6----+----7----+----8----+----9----+----
 ****** ***************************** Top of Data ******************************
 000001                              14-NOV-23 10-MAR-24 09-MAR-24 8-1-6    T 24
 ****** **************************** Bottom of Data ****************************


My requirement is i need to convert this date in postion 65 to 75 below format:
2024-03-10 where year should be first and month and day. I am not finding a way to do is it possible to it through sort....?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Nov 16, 2023 6:22 pm
Reply with quote

Resolve your issue step-by-step:

1) convert your date from '10-MAR-24' to '031024' format (by using PARSE and/or FINDREP)
2) convert the previous result from '031024' to '2024-03-10' (by using Y2W,DT=(4MD-) format)

RTFM
Back to top
View user's profile Send private message
Digvijay Singh

Active User


Joined: 20 Apr 2022
Posts: 141
Location: India

PostPosted: Thu Nov 16, 2023 7:05 pm
Reply with quote

Multiple steps is not concern.

How we can use FINDREP because the date is changing and not constant.

I can use FINDREP at least to change the Month MAR to 03 for different month I can use multiple FINDREP condition.

Like below

'10-MAR-24' can be changed to 10-03-24.

Bit stuck at to convert this to 2024-03-10.

any hint for this step..?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Nov 16, 2023 8:53 pm
Reply with quote

Digvijay Singh wrote:

How we can use FINDREP because the date is changing and not constant.

Code:
 FINDREP=(INOUT=(C'-JAN-',C'01',
                 C'-FEB-',C'02',
                 C'-MAR-',C'03',
                 C'-APR-',C'04',
                 C'-MAY-',C'05',
                 C'-JUN-',C'06',
                 C'-JUL-',C'07',
                 C'-AUG-',C'08',
                 C'-SEP-',C'09',
                 C'-OCT-',C'10',
                 C'-NOV-',C'11',
                 C'-DEC-',C'12'))


RTFM
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Nov 16, 2023 9:03 pm
Reply with quote

Digvijay Singh wrote:


'10-MAR-24' can be changed to 10-03-24.

Bit stuck at to convert this to 2024-03-10.

Code:
 IFTHEN=(WHEN=INIT,
         OVERLAY=(67:70,2,67,2,73,2)),         '10-03-24' --> '031024'
 IFTHEN=(WHEN=INIT,
         BUILD=(...new_pos:67,6,Y2W,DT=(4MD-)) '031024' --> '2024-03-10'


RTFM
Back to top
View user's profile Send private message
Digvijay Singh

Active User


Joined: 20 Apr 2022
Posts: 141
Location: India

PostPosted: Thu Nov 16, 2023 9:08 pm
Reply with quote

Thanks for above, I already had this solution to change the month to numbers.

I am stuck at second step.

Like below

'10-MAR-24' can be changed to 10-03-24.

Bit stuck at to convert this to 2024-03-10.

how 10-03-24 can be converted to 2024-03-10.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Nov 16, 2023 9:12 pm
Reply with quote

Digvijay Singh wrote:
Thanks for above, I already had this solution to change the month to numbers.

I am stuck at second step.

Like below

'10-MAR-24' can be changed to 10-03-24.

Bit stuck at to convert this to 2024-03-10.

how 10-03-24 can be converted to 2024-03-10.


RTFM
And above...
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Nov 17, 2023 4:44 pm
Reply with quote

Why force yourself for DFSORT only ? You could write a cobol date converter program for multipurpose use in your organization, right ? Think about that as well .

Also if you have a db2 then it’s so many date functions which can make life easier to convert to a specific format ..
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Fri Nov 17, 2023 7:20 pm
Reply with quote

Rohit Umarjikar wrote:
Why force yourself for DFSORT only ? You could write a cobol date converter program for multipurpose use in your organization, right ? Think about that as well .

Also if you have a db2 then it’s so many date functions which can make life easier to convert to a specific format ..

About 40%-50% of the existing extremely messy COBOL programs do nothing but converting datasets from one format to another one.
About 80%-90% of those 40%-50% can be easily replaced with SORT utility, at the same time improving their performance significantly.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Fri Nov 17, 2023 8:19 pm
Reply with quote

Agree .. However I always recommend to have a date converter module handy at any site ..
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Fri Nov 17, 2023 8:53 pm
Reply with quote

Rohit Umarjikar wrote:
Agree .. However I always recommend to have a date converter module handy at any site ..

In my career I've created a lot of date format converters, in PL/I, COBOL, C/C++, REXX, Assembler/Macro, - when it was really needed inside of a more complex algorithm.

But in case of dataset conversion only, the best way is using SORT utility.
Back to top
View user's profile Send private message
Digvijay Singh

Active User


Joined: 20 Apr 2022
Posts: 141
Location: India

PostPosted: Wed Nov 22, 2023 4:57 pm
Reply with quote

Hi

i have used the given sort card to convert the date but getting error

i have input file in whcih i have extracted only the date part and now it looks like below:

Code:
Command ===>                         
****** *****************************
000001 100324                       
****** **************************** B


expected ouput :

Code:
2024-03-10


sort card used given above changed the field position accordingly.


Code:
//SYSIN    DD *                             
  SORT FIELDS=COPY                         
  INREC IFTHEN=(WHEN=INIT,                 
           OVERLAY=(01:03,2,01,2,06,2)),   
  IFTHEN=(WHEN=INIT,                       
           BUILD=(1:01,6,Y2W,DT=(4MD-))     
/*                                         
**************************** Bottom of Data



Code:

error i am getting :

  SYNCSORT LICENSED FOR CPU SERIAL NUMBER 03CD7, MODEL 8561 605       
 SYSIN :                                                             
   SORT FIELDS=COPY                                                   
   OUTREC IFTHEN=(WHEN=INIT,                                         
            OVERLAY=(01:03,2,01,2,06,2)),                             
   IFTHEN=(WHEN=INIT,                                                 
            BUILD=(1:01,6,Y2W,DT=(4MD-))                             
                                        *                             
 WER813I  INSTALLATION OPTIONS IN MFX LOAD LIBRARY WILL BE USED       
 WER268A  OUTREC STATEMENT  : SYNTAX ERROR                           
 WER211B  SYNCSMF  CALLED BY SYNCSORT; RC=0000                       
 WER449I  SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE                       
 ******************************** END OF DATA ********
**************************************************


Please any hint is fine I am doing some small mistake heretried multiple time getting sam error again and again.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Wed Nov 22, 2023 5:50 pm
Reply with quote

The asterisk in the output is your hint from the sort - count your open and close parentheses! Very basic stuff, imho.

Also, you're using SYNCSORT which has a separate section to this DFSORT section.

Garry.
Back to top
View user's profile Send private message
Digvijay Singh

Active User


Joined: 20 Apr 2022
Posts: 141
Location: India

PostPosted: Wed Nov 22, 2023 7:17 pm
Reply with quote

sergeyken wrote:
Digvijay Singh wrote:


'10-MAR-24' can be changed to 10-03-24.

Bit stuck at to convert this to 2024-03-10.

Code:
 IFTHEN=(WHEN=INIT,
         OVERLAY=(67:70,2,67,2,73,2)),         '10-03-24' --> '031024'
 IFTHEN=(WHEN=INIT,
         BUILD=(...new_pos:67,6,Y2W,DT=(4MD-)) '031024' --> '2024-03-10'


RTFM



I am talking about this sort card.

i have rectified the syntax error now my job is running fine but in output file i am getting is not correct.

sort card:

Code:
//SYSIN    DD *                         
  SORT FIELDS=COPY                     
  INREC IFTHEN=(WHEN=INIT,             
           OVERLAY=(05:08,2,05,2,01,2)),
  IFTHEN=(WHEN=INIT,                   
           BUILD=(1:05,6,Y2W,DT=(4MD-)))
/*       



output file:

Code:
 Command ===>               
 ****** ********************
 000001 9999-99-99         
 ****** ********************     


please let know if sort card has any issue...? I have used the one suggested to me in above conversation.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 22, 2023 8:09 pm
Reply with quote

Digvijay Singh wrote:
sergeyken wrote:
Digvijay Singh wrote:

'10-MAR-24' can be changed to 10-03-24.
Bit stuck at to convert this to 2024-03-10.

Code:
 IFTHEN=(WHEN=INIT,
         OVERLAY=(67:70,2,67,2,73,2)),         '10-03-24' --> '031024'
 IFTHEN=(WHEN=INIT,
         BUILD=(...new_pos:67,6,Y2W,DT=(4MD-)) '031024' --> '2024-03-10'

RTFM

I am talking about this sort card.

My expectation was that you are able to count the balance of parenthesis by yourself, not only to copy-and-paste a ready-to-use code.

Digvijay Singh wrote:
i have rectified the syntax error now my job is running fine but in output file i am getting is not correct.

sort card:
Code:
//SYSIN    DD *                         
  SORT FIELDS=COPY                     
  INREC IFTHEN=(WHEN=INIT,             
           OVERLAY=(05:08,2,05,2,01,2)),
  IFTHEN=(WHEN=INIT,                   
           BUILD=(1:05,6,Y2W,DT=(4MD-)))
/*       

output file:
Code:
 Command ===>               
 ****** ********************
 000001 9999-99-99         
 ****** ********************     

please let know if sort card has any issue...? I have used the one suggested to me in above conversation.

'9999-99-99' means that your input field did not contain any CORRECT DATE VALUE in required format Y2W.
Change your BUILD in that way: to show BOTH: initial date value, AND converted date value.

Please, RTFM a little bit!!!
Back to top
View user's profile Send private message
Digvijay Singh

Active User


Joined: 20 Apr 2022
Posts: 141
Location: India

PostPosted: Wed Nov 22, 2023 8:44 pm
Reply with quote

Here is my input field :

Code:
Command ===>                             
 =COLS> ----+----1----+----2----+----3----+
 ****** ***************************** Top o
 000001     10-03-24                       
 ****** **************************** Bottom



date part is stating from 5th position here.

you mean to say the first Overlay part is not producing the correct date ..?

Code:
INREC IFTHEN=(WHEN=INIT,             
           OVERLAY=(05:08,2,05,2,01,2)),
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Nov 22, 2023 10:45 pm
Reply with quote

Digvijay Singh wrote:
Here is my input field :

Code:
Command ===>                             
 =COLS> ----+----1----+----2----+----3----+
 ****** ***************************** Top o
 000001     10-03-24                       
 ****** **************************** Bottom



date part is stating from 5th position here.

you mean to say the first Overlay part is not producing the correct date ..?

Code:
INREC IFTHEN=(WHEN=INIT,             
           OVERLAY=(05:08,2,05,2,01,2)),


Display in one single line, but in different positions of the same line:
1) the source field coming to your program
2) the result of the first conversion (from OVERLAY), which is also the input to the second conversion
3) the result of the second conversion (which is '9999-99-99' so far)

Then, compare all three fields to find out: what you've done wrong, and in which step?

Please, RTFM a little bit!!!
Back to top
View user's profile Send private message
Digvijay Singh

Active User


Joined: 20 Apr 2022
Posts: 141
Location: India

PostPosted: Thu Nov 23, 2023 9:55 am
Reply with quote

I was able to do that in two step, i was not much confident with overlay i used below two step:

step1 sort:
Code:

 //**************************************
 //*  5TH                               
 //*  10-03-24        031024   **********
 //*  67TH                      *********
 //*  10-03-24        031024   **********
 //**************************************
 //SYSPRINT  DD SYSOUT=*                 
 //SYSIN    DD *                         
   SORT FIELDS=COPY                     
   OUTREC FIELDS=(1:8,2,03:05,2,5:11,2)



Step2 sort:

Code:
//***********************************************
 //SYSPRINT  DD SYSOUT=*                         
 //SYSIN    DD *                                 
   SORT FIELDS=COPY                               
   INREC IFTHEN=(WHEN=INIT,                       
                  BUILD=(01:01,06,Y2W,DT=(4MD-)))

**************************** Bottom of Data *****


output i got :

Code:
 ***********
 2024-03-10

***********
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1255
Location: Bamberg, Germany

PostPosted: Thu Nov 23, 2023 1:24 pm
Reply with quote

No need to specify the obvious starting positions here. It will start at position one.
Code:
OUTREC BUILD=(8,2,5,2,11,2)

Same applies to the other BUILD statement.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Nov 23, 2023 9:41 pm
Reply with quote

No need to make simple things too complex for no reason:

Code:
//**************************************
//*  5TH                               
//*  10-03-24        031024   **********
//**************************************
//SYSPRINT DD  SYSOUT=*                 
//SYSIN    DD  *                         
  INREC FIELDS=(8,2,   MM
                5,2,   DD
               11,2)   YY
  SORT FIELDS=COPY                                                                           
  OUTREC BUILD=(01,06,Y2W,     MMDDYY
                DT=(4MD-)))    YYYY-MM-DD
 END
//*


P.S.
OVERLAY also can be used, after some thinking about it.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Nov 23, 2023 11:16 pm
Reply with quote

Extra parenthesis to be fixed:

Code:
//**************************************
//*  5TH                               
//*  10-03-24        031024   **********
//**************************************
//SYSPRINT DD  SYSOUT=*                 
//SYSIN    DD  *                         
  INREC FIELDS=(8,2,   MM
                5,2,   DD
               11,2)   YY
  SORT FIELDS=COPY                                                                           
  OUTREC BUILD=(01,06,Y2W,     MMDDYY
                DT=(4MD-))     YYYY-MM-DD
 END
//*
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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Populate last day of the Month in MMD... SYNCSORT 2
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
Search our Forums:

Back to Top