
QF05_RANDOM_INTEGER
.SAP_RANDOM_GET
when QF05_RANDOM_INTEGER
is unavailable.QF05_RANDOM_INTEGER
is a built-in function in newer SAP versions that generates a random integer. The function requires two input parameters - the minimum and maximum number in the desired range.
DATA: lv_random TYPE i.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
ran_int_min = 1
ran_int_max = 100
IMPORTING
ran_int = lv_random.
WRITE: / 'Random Number:', lv_random.
QF05_RANDOM_INTEGER
is not available, you can use the SAP_RANDOM_GET
function module. This module generates a random floating point number between 0 (inclusive) and 1 (exclusive). To convert this to an integer in a desired range, you'll need to do a little bit of additional work. Here's how:DATA: lv_random TYPE f,
lv_random_int TYPE i,
lv_min TYPE i VALUE 1,
lv_max TYPE i VALUE 100.
CALL FUNCTION 'SAP_RANDOM_GET'
IMPORTING
ran_float = lv_random.
lv_random_int = lv_min + lv_random * ( lv_max - lv_min + 1 ).
lv_random_int = TRUNC( lv_random_int ).
WRITE: / 'Random Number:', lv_random_int.
QF05_RANDOM_INTEGER
or SAP_RANDOM_GET
function modules, you can efficiently generate random numbers for your SAP applications. Remember, these numbers are pseudo-random, which means they should not be used in security-critical situations where true randomness is required.You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |