Midrange News for the IBM i Community

Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Moving the Job Date into an RPG IV Variable
has no ratings.
Published: 27 Dec 2011
Revised: 23 Jan 2013 - 4138 days ago
Last viewed on: 22 May 2024 (10303 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Moving the Job Date into an RPG IV Variable Published by: Bob Cozzi on 27 Dec 2011 view comments

The cool %DATE() and %TIMESTAMP() built-in functions are wonderful tools in RPG IV. They allow use to do all kinds of things, such as:

  • Retrieve the System Date or Date/Timestamp
  • Convert non-Date variables into real date data-types
  • Extract the date component from a "Z" (timestamp) variable

But how do you use %DATE to return the job's date "job date"?

In RPG III you would use the UDATE or the *DATE "figurative" constants.

Well, RPGIV bests that, slightly: You have two methods.

       D jobDate         S               D   Inz(*JOB)                    
       D myJobDate       S               D                                
              myJobDate = %date(UDATE);                                   

On line 1, the date variable JOBDATE is initialized using one of the 3 available initialization constants, *JOB. This constant tells the compiler to initialize this date variable to the job date.

On line 4, the %DATE built-in function is being used. Now normally this built-in function returns the system date. However, it also converts non-date values to true date data-types. Therefore, by passing in the UDATE figurative constant, we can convert UDATE (which is the Job Date) into a true date variable. We could also use *DATE which works exactly the same.


Return to midrangenews.com home page.
Sort Ascend | Descend