Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

10 Digit unique ID generation in SAP

0 Kudos

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 REPLIES 10

Sandra_Rossi
Active Contributor
0 Kudos

What is your SAP release?

Do you want to achieve generation in parallel massively?

Does your production system have several application servers?

matt
Active Contributor

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

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( ).

0 Kudos

Hi Egor,

any particular reason for not using the CL_ABAP_RANDOM_INT class?

BR, Suhas

0 Kudos

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

0 Kudos

Integer is not enough. Max integer = 2147483647.

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

VijayCR
Active Contributor
0 Kudos

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.

SuhaSaha
Advisor
Advisor

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-nu...
  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

former_member337404
Discoverer
0 Kudos

Hi Sandra ,

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

Regards,

Nilesh

former_member337404
Discoverer
0 Kudos

Hi Matthew ,

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

Regards,

Nilesh