PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → How to auto increment such a sequence?
How to auto increment such a sequence?
Iniciado por guest, 14,nov. 2014 07:22 - 3 respuestas
Publicado el 14,noviembre 2014 - 07:22
I have a need to generate a sequence which should be unique and should have following format:

JobNum/Month/Year (Eg. 00001/11/2014)

Here each JobID will always get reset to 1 on every month.

Please help me.

TIA

Yogi Yang
Publicado el 14,noviembre 2014 - 08:22
Hello Yogi

I would put the JobNum segment into a file. I have a sysnumber file with four fields.
Each number sequence I need to generate is in a separate row with a transaction type so a call to a procedure will have a parameter to identify the transaction type so it knows which number to increment. The increment process is determined by the second field which is "S"tring or "N"umeric and this determines the increment procedure called. The third field hold stirng value and the foruth holds numeric values

UpdateSysnum("JOBNO","S",1,true) tells the procedure to find the row with a transaction type of "JOBNO", use the string increment procedure, increment by one and increment as a plus ( false will decrement the value)
I would then lock the record, increment the number and unlock the record.
Sounds convoluted but I can use this proc for anything and create a new number sequence by simply adding a transaction type.

The year and month could come from datesys() or the month and year that your application thinks is current for the purpose of assigning a number.
.e.g an accounting product may be running in a "month period" that is different to the actual date month.

Regards
Al
Publicado el 14,noviembre 2014 - 20:53
Hi Yogi.

You need to have 20014110001 for correct increment so you can.
HreadSeekFirst(MyFile,YearMonthNumber,[2014,11], hgeneric+hlimitparsing)

HFound() return False if there is no 201411
HFound() return True if there is any of data starting with 201411

Hope this will help you.
Publicado el 15,noviembre 2014 - 11:35
Hi Yogi,

A simple soltuion might be to revert the sequence of the elenments into YYYY/MM/NNNNN -> 2014/11/00001.
In the database you index this field. (This will allow always for a logical sequence based on date and number)

Then you read the file on the last element of this index. This will give you the last number.
Now you can just add 1 to the last element of this key to create a new record.

Note that if this concerns a multi-user system you will to foresee the necessary locking mechanisms while getting/calculating the next number...

Greetz,

Peter H.