ABAP Tutorial  How to Generate Random Number for a Given Range of Numbers using QF05_RANDOM_INTEGER
ABAP developers can use the function module QF05_RANDOM_INTEGER to generate random number for a given range of numbers.
There are several other methods for ABAP random number generation.
Frequently, ABAP developers require to create random integer numbers.
There are a few function modules that can help you generate random numbers in your SAP system.
I want to show the ABAP code for generating random numbers using function module QF05_RANDOM_INTEGER in this ABAP tutorial.
Below you can find the ABAP example and the source codes for ABAP random numbers.
The local variables with integer data type lv_MinI and lv_MaxI are the input parameters.
They define the range of numbers by identifying the start and the end of the numbers range.
lv_RndI is used to get the output generated random number from the QF05_RANDOM_INTEGER function module.
REPORT ZGENERATERANDOMNUMBER.
DATA :
lv_MinI TYPE I,
lv_MaxI TYPE I,
lv_RndI TYPE I,
lv_i TYPE I.
lv_MinI = 1.
lv_MaxI = 100.
lv_i = 10.
WHILE lv_i > 0.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
ran_int_max = lv_MaxI
ran_int_min = lv_MinI
IMPORTING
ran_int = lv_RndI
EXCEPTIONS
invalid_input = 1
OTHERS = 2.
WRITE :/ 'The Random Number Generated by QF05_RANDOM_INTEGER is : ', lv_RndI.
lv_i = lv_i  1.
ENDWHILE.
And the output of this example ABAP program that generate random numbers is shown in the below screenshot.
This small ABAP code can be used for random number generation in ABAP.
