Handling timestamps in RPGLE

From Try-AS/400
Jump to navigation Jump to search

Data types of date, time, and timestamps are external to RPGLE and thus are somewhat special to handle. Support for date/time handling has to be explicitly enabled by CVTOPT(*DATETIME) in the H specs.

In turn, (DDS) defined database fields are not correctly imported as the appropriate data type by just referencing the file. My approach to handle timestamps therefore consists of multiple variables:

is a timestamp field in the database (physical file).[1]
is a 19 character field in the DSPF, for containing the pretty printed timestamp.
is the RPGLE defined timestamp (Z) field. The TIME operator writes to this variable.


  • Variable definition (in addition to autogenerated ones from referenced files).
    D* For saving/handling timetamp data.
    DSTAMP            S               Z
  • Current time → Database
    C* Get current timestamp.
    C                   TIME                    STAMP
    C                   MOVEL     STAMP         CHANGED
  • Database → Pretty print DSPF field
    C* Get timestamp, and produce nice version thereof.
    C                   MOVEL     CHANGED       STAMP$
    C     '.':':'       XLATE     STAMP$        STAMP$
    C     '-':' '       XLATE     STAMP$:11     STAMP$


  1. RPG imports that as anything but a timestamp declared in the D statements.