‎2010 Oct 11 1:55 PM
Hello
I want to generate random number in SAP. we use this random number as Outbound Delivery number i.e. LIKP-VBELN. We are not generating sequential number as the requirement is such that a person should not be able to predict the next delivery number for security purpose.
I thought of using fm QF05_RANDOM_INTEGER. It generates random number. But I am not sure if this FM will repeat the number as this can be used globally by any user. Kindly advice If I should use fm QF05_RANDOM_INTEGER.
‎2010 Oct 11 5:04 PM
This will be really difficult to do. In addition to generating an random document number (easy), you also have to check that has not been used before. To do this you will have to read the database after generating the number and if it is already there, generate another. Keep doing this until you have a unique document number.
This won't take long at the start, but as the range fills up, it will become a performance problem.
Rob
‎2010 Oct 11 2:06 PM
>
> I want to generate random number in SAP. we use this random number as Outbound Delivery number i.e. LIKP-VBELN. We are not generating sequential number as the requirement is such that a person should not be able to predict the next delivery number for security purpose.
But if the number is going to be assigned to some document e.g., OB Delivery as you have mentioned, then i think we should respect the number range defined for the particular document.
BR,
Suhas
‎2010 Oct 11 2:34 PM
Hi Suhas,
Thanks a lot for ur quick reply. But here the business requirement is that delivery number should be a random number. And using number range we get sequential number. Thus I am thinking of using Random Number generation logic. We would update this table in LIKP-VBELN in enhancement spot.
Do you know any other method to get random number for OB delivery.
‎2010 Oct 11 2:48 PM
>
> We would update this table in LIKP-VBELN in enhancement spot.
I hope you are aware that the delivery number is also stored in several other database tables....
And regarding the requirement: i don't think i have ever come across such a weird one. Who cares what the delivery number is or will be? As long as unauthorized persons cannot enter your system i don;t see any reason why the next number should not be possible to guess.
‎2010 Oct 11 2:58 PM
There are several different classes or functions that can be used to generate random numbers, which you can find in the help files or by searching the browsers. You're never guaranteed uniqueness though, even when using GUIDs. But I agree with Suhas - it makes no sense at all to require that. I can't see any security scenario where the delivery number has to be unpredicatable. If you need a unique identifier for a delivery for some security purpose, I would use an additional field.
‎2010 Oct 11 4:55 PM
‎2010 Oct 11 5:04 PM
This will be really difficult to do. In addition to generating an random document number (easy), you also have to check that has not been used before. To do this you will have to read the database after generating the number and if it is already there, generate another. Keep doing this until you have a unique document number.
This won't take long at the start, but as the range fills up, it will become a performance problem.
Rob
‎2010 Oct 11 6:31 PM
Hello,
Please check the code snippet designed as per your requirement:
DATA: lcl_random TYPE REF TO cl_abap_random_int,
v_from TYPE nrfrom,
v_to TYPE nrto,
v_min TYPE i,
v_max TYPE i,
v_random TYPE i.
* Get the Number Range details for PERNR
SELECT fromnumber tonumber UP TO 1 ROWS
FROM nriv
INTO (v_from, v_to)
WHERE object = 'RP_PREL'
AND nrrangenr = '02'.
ENDSELECT.
CHECK sy-subrc = 0.
MOVE: v_from TO v_min,
v_to TO v_max.
* Get the Random Number generator class instance
TRY.
lcl_random = cl_abap_random_int=>create( min = v_min
max = v_max ).
CATCH cx_abap_random.
ENDTRY.
DO.
* Get the Random Number:
v_random = lcl_random->get_next( ).
* Check if the number is already used up
SELECT COUNT( * ) FROM pa0003
WHERE pernr = v_random.
IF sy-dbcnt = 0.
EXIT. "If no PERNR found, then use the number
ELSE.
CLEAR v_random.
ENDIF.
ENDDO.
WRITE: / 'Random Personnel Number Generated:',
40 v_random NO-GROUPING.If you see the DO ... ENDDO block will be the one causing the pain As the Number Range gets filled the number of iterations will also increase.
Anyway hope this helps you a lil'bit
Cheers,
Suhas