Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 3 Jahren, 3 Monaten
Letzter Beitrag:
vor 3 Jahren, 3 Monaten
Beteiligte Autoren:
Peter Holemans, ICI, Al, Yogi Yang

How to auto increment such a sequence?

Startbeitrag von Yogi Yang am 14.11.2014 06: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

Antworten:

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

von Al - am 14.11.2014 07:22
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.

von ICI - am 14.11.2014 19:53
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.

von Peter Holemans - am 15.11.2014 10:35
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.