Skip to Content
avatar image
Former Member

10 Digit unique ID generation in SAP

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

Add comment
10|10000 characters needed characters exceeded

  • Former Member Sandra Rossi

    Hi Sandra ,

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

    Regards,

    Nilesh

  • Former Member Matthew Billingham

    Hi Matthew ,

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

    Regards,

    Nilesh

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

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Jan 18, 2017 at 11:44 AM

    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( ).
    
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Suhas Saha

      Integer is not enough. Max integer = 2147483647.

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

  • Jan 18, 2017 at 04:03 PM

    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

    Add comment
    10|10000 characters needed characters exceeded