Using timestamps in RPG

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

Using timestamps in RPG is not as straightforward as using character, or decimal fields.

RPG has an internal way to handle timestamps, which is incompatible with the external representation in externally described fields, such as database- and display files.

Note: Adding the internal date/time handling routines is a compile time option. Use CVTOPT(*DATETIME) in a H line.

Example

CHANGED
is a timestamp field in the database (physical file).[1]
STAMP$
is a 19 character field in the DSPF, for containing the pretty printed timestamp.
STAMP
is the RPGLE defined timestamp (Z) field. The TIME operator writes to this variable.
  • PF:
A            CHANGED         Z
  • DSPF:
A            STAMP$        19A  O ...
  • RPGLE:
D* For saving/handling timetamp data.
DSTAMP            S               Z
D*

For every time we write, or update a record:

C* Current time → Database
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$

See also

Weblinks

Footnotes

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