I 'd like to calculate by trigger the 13th character of an EAN13 partnumber code.
I did the code in VBA, but now I'd like to translate it in order to
insert it in a db2 trigger (v5r4m0).
I have a table1 with field PN12, and field checkdigit,
how to fill checkdigit with right digit calculated using the code below,
how to transform this code in a trigger?
Function CheckDigitEAN13(PN12 As String) As Integer
Factor = 3
WeightedTotal = 0
For I = Len(PN12) To 1 Step -1
'Get the value of each number starting at the end
CurrentCharNum = Mid(PN12, I, 1)
'Multiply by the weighting factor which is 3,1,3,1...
'and add the sum together
WeightedTotal = WeightedTotal + CurrentCharNum * Factor
'Change factor for next calculation
Factor = 4 - Factor
'Find the CheckDigit by finding the number + WeightedTotal that = a multiple of 10
'Divide by 10, get the remainder and subtract from 10
I = (WeightedTotal Mod 10)
If I <> 0 Then
CheckDigit = (10 - I)
CheckDigit = 0
CheckDigitEAN13 = CheckDigit