01-18-2017 12:50 AM
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
01-18-2017 7:39 AM
What is your SAP release?
Do you want to achieve generation in parallel massively?
Does your production system have several application servers?
01-18-2017 9:35 AM
Why must it be ten characters? And what kind of locking/performance issues are you getting with number ranges?
01-18-2017 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( ).
01-18-2017 1:01 PM
Hi Egor,
any particular reason for not using the CL_ABAP_RANDOM_INT class?
BR, Suhas
01-18-2017 1:15 PM
01-19-2017 4:25 AM
Integer is not enough. Max integer = 2147483647.
cl_abap_random=>seed generate unique integer, after that I use seed for generate a 'unique' p.
01-18-2017 3:28 PM
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.
01-18-2017 4: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 -
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
01-18-2017 5:43 PM
Hi Sandra ,
It's not massively but it can be parallel with little bit high in frequency .
Regards,
Nilesh
01-18-2017 5:45 PM
Hi Matthew ,
It must be 10 characters because this data goes to downstream third party system which has some restrictions.
Regards,
Nilesh