• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • JD Edwards Dates, Revisited

    September 20, 2002 Timothy Prickett Morgan

    Dear Readers:

    After I published the piece on how to convert JD Edwards date to DB2 date data types, I received more mail than I have ever received before.

    Obviously, you guys are salivating for date routines. Well, so as not to let you down, I will publish in this issue a user-defined function that you can use in place of the date conversion formula. However, for those of you that do not have V5 or the C Compiler and SQL Development Kit, I will provide instructions on how you can download a working version of the function and put it on your machine. Even if you cannot create the function yourself, you can at least put it on your machine and use it.

    The Function

    If you remember my article from the September 6 issue of Midrange Guru, OS/400 Edition, here’s one formula for converting JD dates to real dates:

    DATE(digits(DECIMAL(JDEDATE+1900000,7,0)))
    

    This formula uses simple addition and a few SQL scalar functions to make the JD date into a real date. Once the data is a date, you are home free, as you can use all of the built-in DB2 date functions to do date math and manipulation.

    The following SQL source code is a user-defined function that will convert JD dates:

    CREATE FUNCTION MCEIS.JDDCONV
       (JDEDATE DECIMAL(6,0))
       RETURNS DATE 
       LANGUAGE SQL
       SET OPTION DATFMT=*ISO
    BEGIN 
    DECLARE F_OUTPUT DATE ; 
    DECLARE F_TEST INTEGER ; 
    DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET F_TEST = 1 ; 
    SET F_TEST = 0; 
    SET F_OUTPUT = DATE(DIGITS(DECIMAL(JDEDATE+1900000,7,0)));
    IF F_TEST = 0 THEN RETURN F_OUTPUT ; 
    ELSE RETURN NULL; 
    END IF; 
    END
    

    You can create this function on your AS/400 by pasting this code into a run SQL Scripts session under Operations Navigator (OpsNav) and running it, executing it in my SQLThing tool or using STRSQL. Once the code (displayed above) is executed, you will have a UDF called JDDCONV in the MCEIS library on your AS/400.

    Note that the function takes a DECIMAL(6,0) value and returns it as a DB2 date data type. Also, the function uses the SET option to ensure that, when the function is executing, it deals with all date data in *ISO format. This ensures that even if your job is running in a different format, within the function scope the value will be treated as an *ISO date value.

    When the function executes, it first declares two variables:  F_OUTPUT as a DATE and F_TEST as an integer.  F_OUTPUT will be used to hold the results of the date calculation, and F_TEST will be used to test whether the conversion was successful. The function next declares a continue handler for any SQLEXCEPTION. A handler is a basic form of error handling available within user-defined functions and stored procedures. A continue handler is like a trap that instructs the program to continue processing if an SQLEXCEPTION happens, but to make sure that the code right after the continue handler is executed before processing continues. In my function, I am instructing the AS/400 that if an error occurs, I want the variable F_TEST to be set to the value 1. On the next line of the function, I am setting F_TEST to 0. F_TEST will only contain the value of 1 if the continue handler is fired.

    The next line attempts to convert the passed-in argument to a DB2 date and place the results into the F_OUTPUT variable. I then test the variable F_TEST to see if an error occurred during the conversion. If the conversion was successful, I return the converted data; otherwise I return a null value. And that is the end of the function.

    Once the function is placed on your system, you use it in the following manner:

    SELECT  JDDCONV(MyField) FROM MyFile
    

    MyField is the JD Edwards date column you want to convert. If, for some reason, the function does not work, you probably do not have the library that contains the function in your library list. To rectify this, execute the following statement:

    SET CURRENT FUNCTION PATH = MyFuncLib
    

    MyFuncLib is the name of the library that you created the function within.

    “But I’m not on V5,” you say. Or, “I don’t have a C compiler.”

    Ok, don’t whine; you can still have the function thanks to the AS/400’s wonderful backwards compatibility. My friend, Domenic, has an AS/400, but he is on V4R5 and also does not have the C compiler. So, I made one simple change to the above function (I added a set option for compatibility back to V4R4), and I then compiled it on my system. I made a save file into which I saved the service program. I then sent it to my friend, and he restored the service program to his machine.

    Bang, Domenic can now use the function on his AS/400. When you restore a user defined function from a save file, the AS/400 automatically makes all of the updates to the system catalog and registers the function to DB2. This technique very useful, as you can develop objects like stored procedures and functions on a development machine and then restore them to a production machine that perhaps doesn’t have the C compiler or the SQL development kit. Or in this case, I can put the function on my Web site and you can download it and put it on your machine.

    I have placed on my Web site a save file containing this user-defined function, complete with detailed instructions on how to restore it to your AS/400. In a nutshell, simply download the save file to your PC. Then, transfer the save file to your AS/400 and use Restore object to restore the function to your AS/400. Bang, now you can use the JDDCONV function, too.

    — Howard

    Howard F. Arner, Jr. is a writer and consultant for Client Server Development, Inc. in Jacksonville, Florida. He is also the author of “iSeries and AS/400 SQL at Work,” which you can purchase from his Web site at www.sqlthing.com/books . Or, visit Howard’s Web site to learn more about user-defined functions on the AS/400.

    Sponsored By
    RJS SOFTWARE SYSTEMS

    Implement Document Imaging on your iSeries-AS/400 in 30 minutes or less

    Image Server/400 is a Web browser-based document image management system for the iSeries.

    Documents can be quickly scanned and stored in IFS folders, and then located and retrieved for viewing via any Web browser. Integrate with other iSeries-AS/400 applications.

    Visit us at COMMON, Booth 418, call us at 888-RJS-SOFT, or download a FREE fully functional demo from our Web site at

    www.rjssoftware.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: mgo_rc, Volume 2, Number 72 -- September 20, 2002

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Is It a Different ‘Hello World’ in OS/400 V5R1? Reader Feedback and Insights: Displaying Menu Options

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 72

This Issue Sponsored By

    Table of Contents

    • Reader Feedback and Insights: Thanks for the Tips
    • Comparing Lists of Numbers to a Value
    • JD Edwards Dates, Revisited

    Content archive

    • The Four Hundred
    • Four Hundred Stuff
    • Four Hundred Guru

    Recent Posts

    • Meet The Next Gen Of IBMers Helping To Build IBM i
    • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
    • Will Independent IBM i Clouds Survive PowerVS?
    • Now, IBM Is Jacking Up Hardware Maintenance Prices
    • IBM i PTF Guide, Volume 27, Number 24
    • Big Blue Raises IBM i License Transfer Fees, Other Prices
    • Keep The IBM i Youth Movement Going With More Training, Better Tools
    • Remain Begins Migrating DevOps Tools To VS Code
    • IBM Readies LTO-10 Tape Drives And Libraries
    • IBM i PTF Guide, Volume 27, Number 23

    Subscribe

    To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

    Pages

    • About Us
    • Contact
    • Contributors
    • Four Hundred Monitor
    • IBM i PTF Guide
    • Media Kit
    • Subscribe

    Search

    Copyright © 2025 IT Jungle