Wednesday, October 7, 2009

What Is the Calculation Logic Behind the Conversion Function RowIdToRowIdNum?

In Siebel versions 6.x and 7.x, there are several number fields such as SR Number, Agreement Number, Asset Number, and Invoice Number which have the Pre Default Value = Expr: 'RowIdToRowIdNum ([Id])'. RowIdToRowIdNum is a function used in calculated expressions. This function converts an alphanumeric ROW_ID to a unique, pure numeric ROW_ID.

The conversion is performed for digits and letters after or before the hyphen '-'. The formula used by RowIdToRowIdNum is the following:

[Last digit or letter * 36^0] + [Second to last digit or letter * 36^1] + [Third to last digit or letter * 36^2] + ...+ [Second digit or letter * 36^n-1)] + [First digit or letter * 36^n]

By design, values of letter A is 10, B is 11, C is 12 ... Y is 34, and Z is 35.

Example 1:

Take the example of ROW_ID = 1-5GYG0.

  1. Start converting from the last digit or letter from right to left, which is 0 in this case:

0 * 36^0 = 0

  1. Conversion of second to last digit or letter, which is 'G':

G * 36^1 = 16 * 36 = 576

  1. Conversion of third to last digit or letter, which is 'Y':

Y * 36^2 = 34 * 36 * 36 = 44064

  1. Conversion of second letter or digit, which is 'G':

G * 36^3 = 16 * 36 * 36 * 36 = 746496

  1. Conversion of first digit or letter before the hyphen '-', which is '5':

5*36^4 = 5 * 36 * 36 * 36 * 36 = 8398080

  1. Adding all the converted values right of the '-' gives 9189216:

0 + 576 + 44064 + 746496 + 8398080 = 9189216

  1. The next character is a hyphen '-'. The letter or digit to the left of the hyphen,'1', is converted by itself:

1 * 36^0 = 1 * 1 = 1

The final converted ROW_ID is 1-9189216.

Example 2:

ROW_ID G-5GYG0

This ROW_ID is the same as the ROW_ID in example 1 with the exception of the letter to the left of the hyphen, 'G'. Using the same conversion, G-5GYG0 would be 16-9189216 where G, the letter to the left of the hyphen, gets converted to 16.

  1. 0 * 36^0 = 0 * 1 = 0
  2. G * 36^1 = 16 * 36 = 576
  3. Y * 36^2 = 34 * 36 * 36 = 44064
  4. G * 36^3 = 16 * 36 * 36 * 36 = 746496
  5. 5 * 36^4 = 5 * 36 * 36 * 36 * 36 = 8398080
  6. Adding all the converted values right of the hyphen = 9189216

The final converted ROW-ID is 16-9189216.

Example 3:

ROW_ID = 1-IB79I

Using the same conversion, 1-IB79I would be 1-30755718 where '1', the digit to the left of the hyphen, gets converted to 1.

  1. I * 36^0 = 18 * 1 = 18
  2. 9 * 36^1 = 9 * 36 = 324
  3. 7 * 36^2 = 7 * 36 * 36 = 9072
  4. B * 36^3 = 11 * 36 * 36 * 36 = 513216
  5. I * 36^4 = 18 * 36 * 36 * 36 * 36 = 30233088
  6. Adding all the converted values right of the hyphen = 30755718

The final converted ROW_ID is 1-30755718.


Have a nice day!

2 comments:

  1. Nicely explained . . . really helpfull.

    ReplyDelete
  2. Hi Riyan i have a requirement where i have to generate Numbers based on row id but the number should be of 12 digit and unique. .

    ReplyDelete

Share/Bookmark