Home > AS/400 Tips > iSeries programmer tips > System i date conversions in RPG
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

System i date conversions in RPG


Andrew Borts
03.07.2007
Rating: -3.76- (out of 5)


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



Andrew Borts
Date conversion in RPG is something that we do without too much hassle. Years ago, we'd use wacky calculations, which are now deemed harmful to proper processing (programming general warning!) The old multiply by 100.0001 is a bad way to go. Here's the reasoning why you need to eliminate all of these from your repertoire of conversion tools.


  • This produces a hiccup while processing --because the end result of that calculation creates an exception error.

  • The field gets violently (best word for it) truncated

  • The system stops whatever it's doing, thinks really hard over the answer, decides on keeping the remaining numbers from the calculation

  • The result is given to you after the server has been calmed down by years of OS monitor messages.

    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).

    More Information

    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.

    Rate this Tip
    To rate tips, you must be a member of Search400.com.
    Register now to start rating these tips. Log in if you are already a member.


    Submit a Tip




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


    RELATED CONTENT
    iSeries programmer tips
    Coloring source lines with COBOL and using a shortcut from within PDM
    Date calculation commands for AS/400
    There is very little RPG on System i can't do: From RPG nay to RPG yay!
    Using SQL on System i to color source code and inline comments
    Controlling spool files with APIs
    System i document management tips
    Selective SPOOLFILE copy to CSV files and e-mail
    System i Resume Building 101
    Web skills crucial to iSeries programmer professional development
    System i no longer the stepchild of IBM's world

    RPG iSeries programming
    RPG application gets a Web revamp at Pinnacle Foods
    There is very little RPG on System i can't do: From RPG nay to RPG yay!
    Chain operation error after converting RPG3 to ILE RPG (RPGIV)
    RPG application modernization for i5
    RPG dynamic value calculation versus hard-coded values
    COMMON product round-up: Modernizing the IBM System i
    Top 10 System i white papers
    Embracing RPG IV
    Java for RPG Programmers, Third Edition -- Chapter 10
    Free form RPG: Are you /FREE?

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    Report Program Generator  (Search400.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

  • HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




    All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts