Tips and Techniques: Processing Dates

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Date processing continues to be a pain in the neck for many RPG programmers. RPG III still does not support true date fields, while RPG IV and DDS do. Consequently, those who have not moved their entire set of applications to RPG IV have decided to not use date fields in their database files.

In V5R2, IBM added a date format code to the %CHAR built-in function that allows you to specify the resulting format of the date value that is generated.

In V5R3, IBM has added the capability to convert a numeric value into a date value and specify the format that the value is stored in. The %DATE built-in function now converts a numeric value into a date value. The second parameter of %DATE allows you to specify the format of the non-date value that you are converting. This allows you to compare or assign a non-date value to a true date variable.

Prior to V5R2, you had to use the MOVE operation code to convert the non-date value to a true date field and then use that field to compare.

While things are getting easier, it would still be beneficial if IBM would add true date data-type support to the RPG III language. But don't hold your breath.

The following are examples of the techniques explained above:

     D Today           S               D   Datfmt(*JUL)
     D DueDate2        S               D   Datfmt(*ISO)
     D dueDate         S              8S 0
      
      /IF DEFINED(*V5R3M0)
     C                   if        %Date(dueDate:*ISO) > Today
      /ELSEIF DEFINED(*V5R2M0)
     C                   if        %int(%Char(dueDate)) > 
     C                                %Int(%char(NewDate:*ISO0))
      /ELSE
     C     *ISO0         MOVE      dueDate       dueDate2
     C                   if        dueDate2 > Today
      /ENDIF

Bob Cozzi is a programmer/consultant, writer/author, and software developer of the RPG xTools, a popular add-on subprocedure library for RPG IV. His book The Modern RPG Language has been the most widely used RPG programming book for nearly two decades. Along with others, he speaks at and runs the highly popular RPG World, a conference for RPG programmers.

BLOG COMMENTS POWERED BY DISQUS