IBM Support

RPG Cafe: Microseconds for %TIMESTAMP

News


Abstract

RPG enhancement for %TIMESTAMP, to provide timestamps with microsecond precision and unique timestamps.

Content

You are in: RPG Cafe > Spring 2020: Microseconds for %TIMESTAMP

Short URL: https://ibm.biz/rpgcafe_timestamp_microseconds

RPG Cafe: Microseconds for %TIMESTAMP

Enhancements for %TIMESTAMP

  • %TIMESTAMP() now returns microseconds

    Note: You can add an environment variable at compile time to cause %TIMESTAMP to continue to return a value with only milliseconds. The environment variable is not needed at runtime.

    ==> ADDENVVAR QIBM_RPG_DISABLE_TIMESTAMP_MICROSEC VALUE('Y')
    
  • %TIMESTAMP(*UNIQUE) returns a unique timestamp

Warning

After you compile your program to use this enhancement, a runtime PTF is needed on any system where you run your program.

PTFs for 7.3 and 7.4, available in May 2020

7.3:

  • ILE RPG compiler: SI73190
  • ILE RPG runtime: SI73189

7.4:

  • ILE RPG compiler: SI73192
  • ILE RPG runtime: SI73191>
  • ILE RPG compiler, TGTRLS(V7R3M0): SI73193

The PTFs are also available with the Db2 for i Fix Packs of 15 May 2020. See Db2 for IBM i 2020 PTF Group Schedule.

Details

Microseconds for %TIMESTAMP

Formerly, %TIMESTAMP only returned a value with millisecond precision. The last three digits of the timestamp were '000'. Now, it returns a value with microsecond precision.

If you only want millisecond precision, code %TIMESTAMP(*SYS : 3). Or you can add this environment variable at compile-time (not needed at runtime):

===> ADDENVVAR QIBM_RPG_DISABLE_TIMESTAMP_MICROSEC VALUE('Y')

          DCL-S ts TIMESTAMP;

          ts = %TIMESTAMP();          // Returns microseconds
          ts = %TIMESTAMP(*SYS : 3);  // Returns milliseconds

%TIMESTAMP(*UNIQUE) returns a unique timestamp

%TIMESTAMP(*UNIQUE) returns a timestamp with 12 fractional seconds. Use keyword TIMESTAMP(12) to define a variable to hold a unique timestamp.

          DCL-S ts_unique TIMESTAMP(12);

          ts_unique = %TIMESTAMP(*UNIQUE);

The first 6 fractional seconds represent the microseconds for the timestamp.

The final 6 fractional seconds do not represent increased accuracy. They are only used to make the timestamp unique.

Tip: Avoid using the result of %TIMESTAMP(*UNIQUE) for calculations that determine the amount of time between two timestamps.

RDi support

The next release of RDi will support this enhancement.

Documentation in the IBM Knowledge Center

The ILE RPG Reference and ILE RPG Programmer's Guide in the 7.3 and 7.4 IBM Knowledge Center are updated with full information about this enhancement. Start at the What's New Since 7.3 or What's New Since 7.4 section in the Reference.

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SS69QP","label":"Rational Development Studio for i"},"Component":"ILE RPG Compiler","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.3;7.4","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
06 October 2020

UID

ibm16127845