Handling of timestamps in RPGLE

From Try-AS/400
Revision as of 16:26, 20 August 2021 by PoC (talk | contribs) (New)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Because date and time values have been bolted-on to RPG later, their handling of timestamps in RPGLE is somewhat tedious.

To make it work properly, we need three (!) variables:

  • CHANGED is the database field, type timestamp. Incompatible with the timestamp type within RPG, so we need another variable…
  • STAMP is the variable for dealing with timestamps within RPG.
  • STAMP$ is a string variable derived from the DSPF for showing a nicely formatted timestamp. This isn't meant to be edited, so fields must be flagged O!

PF
     A            CHANGED         Z
DSPF
     A            STAMP$        19A  O ...
RPGLE
     D*
     D* For saving/handling timetamp data.
     DSTAMP            S               Z
     D*

For every time we write, or update a record:

     C* Get current timestamp.
     C                   TIME                    STAMP
     C                   MOVEL     STAMP         CHANGED

For every instance before displaying the STAMP$ field:

      C* Get timestamp, and produce nice version thereof.
      C                   MOVEL     CHANGED       STAMP$
      C     '.':':'       XLATE     STAMP$        STAMP$
      C     '-':' '       XLATE     STAMP$:11     STAMP$

See also