>I have made auto-incrementing keyfields before, using the system in TASTRADE. What would be a good system for auto-incrementing while having each "digit" cycle through a-z, or maybe 0-9 and a-z, or maybe A-Z and then a-z? Doing this would increase the number of available values. It would be useful to me because I have a legacy app, written using data from other people's legacy apps, which has a meaningful keyfield which is only five characters long, and always starts with a digit. Now they want to allow blank values in this field, and we don't feel like rewriting the whole thing. I propose to generate values always starting with a letter, which would appear as blank in reports.
I use this for some types of codes, where the number should be AAA-nnn, where AAA is a three-letter code based on date, and nnn is the daily counter. Gives some kind of a meaningful unique key:
*+ date to three char
* returns date packed into three characters (A-Z)
* v1.0 21.3.98 WMW Bar, for the bill serial number
* v1.1 14.6.98 additional parameter _len - 4 covers 26**4 dates;
giving 1251 years, 3 covers 48 (1990-2038)
*-
para _d, _du
if empty(_d)
_d=date()
endif
if empty(_du)
_du=3
endif
numdat=_d-{01.01.1990}
sl=""
for i=1 to _du
ns=numdat%26
sl=chr(ns+65)+sl
numdat=int(numdat/26)
endf
retu sl
You could simply start passing the number instead of date, adding more characters than I use here etc, but the principle would be the same.