Since the reaction to that calculation is kind of like a "train wreck" for processing, let's look at the alternative.
Take a look at my data structure, and I'll get you converting dates in no time.
Here's the way it works; you put the entire number into the appropriate original format. Let's convert from CYMD to MDY you'd Z-Add DATE into CYMD. Then Z-Add YY into cvYY. Two lines of code later, and you have MDY. Want to do the reverse – easy! Z-Add the DATE into MDY. Then take cvYY and Z-add that into YY. Use a window technique to extrapolate the century if you can (Window technique = If year (YY) < 60 then century (CC) = 20, ELSE century (CC) = 19).
Now you're shaking your head – two lines of code, no! The original date calculation may have been only one line of code, but since it causes so many exception errors while processing, it's slower then 100's of lines of code. The two innocuous lines of code we used to convert using my data structure are extremely fast.
Now, let's do this in our CL programs. CVTDAT has been a wonderful part of our diet since the early days of the operating system.Let's convert some dates in CL.
I grab my Job Date (define – the Job Date is different from the System Date (Note: even if they are the same) then use this CL command, but look – I can convert from *MDY (see my MDY DS entry from above isn't so original ) to *YMD or any other permutation. Please make note, that *CYMD isn't the result you may want. IBM used a century byte until they learned that we were going to be using a real date. So *CYMD for say 2/28/2007 would convert to 1070228 – not exactly friendly. *YYMD is going to be your friend here -- this format would return 20070228. Keep in mind that's if you set "To date separator" to *NONE.
Like what you see? We'll calculate these next month. If you're excited about data calculations using CL, I highly recommend TAATOOLS, which is now available as a professional set of tools -- instead of being supplied with the operating system. There are a ton of handy commands - and last time I checked – licensed from Jim Sloan is about 30 cents a tool.
About the author: Andrew Borts is webmaster at United Auto Insurance Group in North Miami, Fla. He is often a frequent speaker at COMMON and is past president of The Southern National Users Group, an iSeries-AS/400 user group based in Deerfield Beach, Fla.
This was first published in March 2007