Handling of timestamps in RPGLE
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!
A CHANGED Z
A STAMP$ 19A O ...
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$