_Ralph_
19th December 2006, 16:02
Hello Everyone!;)

I have a table eucom102 wich contains 3 fields.

- Code - eucom102.code
- Name - eucom102.name
- Description - eucom102.desc

With its respective session already created. The field eucom102.code need to be in a sequencial order starting from 0. So I created the following:


|**************field section*************
field.eucom102.code:
before.input:
eucom102.code = auto.number()
|**************function section**********
functions:

function domain tcorno auto.number()
{
long num.x
select max(eucom102.code):num.x
from eucom102
selectdo
num.x = num.x +1
endselect
return(str$(num.x))
}


In ERP LN the domain tcorno was turned into String.:mad:

In Baan the codes would be organized this way:
0, 1, 2, 3, 4, 5, 6, 7, 8,9 ,10, 11, 12,...

In LN the order is:
0, 1, 10, 11, 12, 2, 3, 4, 5, 6, 7, 8, 9, ...

So when used

select max(eucom102.code):num.x
The number stored will be ever "9". And the return: 10.

I heard about use a function of a Library that fix this problem. And gives me the choice to use a code with letters and number. like ABC001, ABC002 and so on(As Sales/Purchase Orders) But I don't know how to work with libraries.

Could you clear my mind please??

Thanks a lot!

george7a
19th December 2006, 16:30
Hi,

I don't know about the Library that fix the problem but you can try to convert to long then find the max in the selectdo. Here is an example:

select eucom102.code
from eucom102
selectdo
num.x = lval(eucom102.code) | converting string to long
if num.x > max.num.x then | finding maximum
max.num.x = num.x
endif
endselect
return(str$(max.num.x))

I hope it helps,

- George

_Ralph_
19th December 2006, 18:47
Thanks for the reply George,

but did not work...

Guess that just this "magical library" could save me lol:(

mark_h
19th December 2006, 19:02
Well I think George had the correct idea to start with.

max.num.x = 0
select eucom102.code
from eucom102
selectdo
num.x = lval(eucom102.code) | converting string to long
if num.x > max.num.x then | finding maximum
max.num.x = num.x
endif
endselect
max.num.x = max.num.x + 1
return(str$(max.num.x))

Based off your post this should return 13. The only problem would be if there are additional qualifiers for this sequence type number and you want to start it at 0. Then you would need to add a selectempty and a couple of other lines maybe. Actually if this does not return 13 (based off your list) you can let us know what it does return.

_Ralph_
19th December 2006, 19:26
Guess I was wrong too:eek:

Thanks Mark! That was right!
this details you added are the key :P

the return for this sequence was 13 as u said.

I'm researching about the library I spoke before.
When get the answers. I'll post here!

see ya!

george7a
19th December 2006, 19:48
Well I think George had the correct idea to start with.
Sorry, I forgot to add one to the maximum...

Dikkie Dik
20th December 2006, 12:01
The posted solutions maybe work, but I hope your table will not become too large else you will definitly have a performance issue. The sugestions all have to go through the whole table.
Hereby some suggestions that make it more performing:
- as your table eucom102 is created by yourself, I advise to add an additional column (type float or long) that contains the number (lval) of the code
- then you can do a simple select on that column to find the maximum value.
- If the performance on this is still not optimal, I recommend to add an index on this new field.

Hope this helps,
Dick

ARijke
20th December 2006, 14:12
The functions you are looking for are available in tcmcs.dll0050.

good luck

Dikkie Dik
20th December 2006, 15:50
The functions you are looking for are available in tcmcs.dll0050.
tcmcsdll0050 only has functions for First Free Numbers that are located in tcmcs050 to my opinion.

Kind regards,
Dick