SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.

CRM Companies List
Web Based CRM Software

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.


  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.

    ran_int_max = lv_MaxI
    ran_int_min = lv_MinI
    ran_int = lv_RndI
    invalid_input = 1
    OTHERS = 2.

WRITE :/ 'The Random Number Generated by QF05_RANDOM_INTEGER is : ', lv_RndI.

lv_i = lv_i - 1.


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.


SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table

Copyright © 2004 - 2018 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems