Handling timestamps in RPGLE
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
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).
- is a 19 character field in the DSPF, for containing the pretty printed timestamp.
- is the RPGLE defined timestamp (
Z) field. The
TIMEoperator 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* C* Get timestamp, and produce nice version thereof. C MOVEL CHANGED STAMP$ C '.':':' XLATE STAMP$ STAMP$ C '-':' ' XLATE STAMP$:11 STAMP$
- RPG imports that as anything but a timestamp declared in the