Skip to Content
0

10 Digit unique ID generation in SAP

Jan 18, 2017 at 12:50 AM

413

avatar image

Hi All ,

I have a requirement to generate 10 Digit unique ID similar to GUID whenever a call comes to my custom SAP application .

Can someone suggest how to generate 10 Digit unique ID in SAP ?

Please note CREATE_GUID function module will gives more then 10 digit hence i can't use it for my requirement Also i don't want to use number range for this process due to locking & performance issue .

Regards,

Nilesh

10 |10000 characters needed characters left characters exceeded

What is your SAP release?

Do you want to achieve generation in parallel massively?

Does your production system have several application servers?

0

Hi Sandra ,

It's not massively but it can be parallel with little bit high in frequency .

Regards,

Nilesh

0

Why must it be ten characters? And what kind of locking/performance issues are you getting with number ranges?

1

Hi Matthew ,

It must be 10 characters because this data goes to downstream third party system which has some restrictions.

Regards,

Nilesh

0

Try to create Number ranges if it depends on year so that every year you have a unique combination of number use the FM NUMBER_GET_NEXT and try to generate a unique number and concatenate with the year and any other keyfield. This is the best solution i can see for your question.

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Egor Muratov Jan 18, 2017 at 11:44 AM
2

Hi! Try this:

  DATA lc_guid TYPE REF TO cl_abap_random_packed.
  DATA lv_seed TYPE i.
  DATA lv_guid TYPE p.

CALL METHOD cl_abap_random=>seed
  RECEIVING
    seed   = lv_seed.

  CALL METHOD cl_abap_random_packed=>create
   EXPORTING
      seed   = lv_seed
      min    = 1000000000
      max    = 9999999999
    RECEIVING
      prng   = lc_guid.

  lv_guid = lc_guid->get_next( ).
Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Egor,

any particular reason for not using the CL_ABAP_RANDOM_INT class?

BR, Suhas

0

Integer is not enough. Max integer = 2147483647.

cl_abap_random=>seed generate unique integer, after that I use seed for generate a 'unique' p.

0

Are you sure, cl_abap_random_packed generates a 'unique' number?

0
Suhas Saha
Jan 18, 2017 at 04:03 PM
2

This class implements the basic version of a pseudo random number generator. It is based on the Mersenne Twister algorithm. This algorithm guarantees a high period length for the generated values, and ensures that values are evenly distributed when multi-dimensional data is generated.

I found 2 interesting reads -

  1. http://softwareengineering.stackexchange.com/questions/273105/why-is-the-period-of-a-pseudorandom-number-generator-important
  2. https://en.wikipedia.org/wiki/Mersenne_Twister

If i understand correctly, because the period length is so high the chances of getting the same "random" number is minimal. Now if the OP uses this "random" number together with (say) Fiscal Year, it'll kind of ensure that the combination is unique.

BR,

Suhas

Share
10 |10000 characters needed characters left characters exceeded