mgo
OS/400 Edition
Volume 2, Number 53 -- July 17, 2002

Using Timestamps as Unique Keys


Hey, Ted:

We need to generate unique keys for each record written to a file and thought that the timestamp would make a good unique key for a file. Then we ran into a problem. The RPG TIME op code fills in only the first three digits of the microseconds portion of a timestamp field. The last three digits are always zeros.


Is there another way in RPG to fill the timestamp with a unique time, such as an op code that fills the last three digits as well?

-- Michael


Since your concern is that you have a unique value, not that you have an accurate timestamp, let me suggest an alternate approach. Compare the timestamp to the timestamp that was retrieved for the previous record. If they are the same, add one microsecond to get a unique key value.

D key             s               z                     
D timestamp       s               z                     
D timestampsave   s               z                     

C                time                    timestamp   
C                if        timestamp <> timestampsave
C                eval      key = timestamp           
C                eval      timestampsave = timestamp 
C                else                                
C                adddur    1:*mseconds   key         
C                endif                               

-- Ted


Sponsored By
TRAMENCO

The Training and Mentoring Company (Tramenco) is dedicated to just one thing: Advancing your career by giving you the skills you need to solve real-world business problems.

Choose from a menu of training options to fit your needs: onsite seminars, public seminars, mentoring, consulting, books, CBTs, and Web-based training.

For more information about Tramenco's career enhancing opportunities, call (800)421-8031 or go to www.tramenco.com.


THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
Tramenco


BACK ISSUES

TABLE OF CONTENTS

SQL and System/36 File Names

Using Timestamps as Unique Keys

Reader Feedback and Insights: Dealing with Record Locks


Editors
Howard Arner
Joe Hertvik
Ted Holt
David Morris

Managing Editor
Mari Barrett

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com



Last Updated: 7/17/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.