Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Random Number Generation

Former Member
0 Likes
2,326

hi all,

how to generate random numbers. is there any function module to generate it. pls tell me.

9 REPLIES 9
Read only

Former Member
0 Likes
1,319

try this FM - QF05_RANDOM_INTEGER

Kothand

Read only

Former Member
0 Likes
1,319

hi,

Use FM QF05_RANDOM_INTEGER

Regards

Srilatha

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,319

I always wonder, what is the business scenario in SAP, where you need random numbers? Or you develope game in ABAP?

Read only

0 Likes
1,319

Yes Eric,

I really used(!) this FM - QF05_RANDOM_INTEGER only for answering questions in SDN forum and never in my programs.

Sandeep, what are you doing with this FM. Please let us know its usage.

//Kothand

Read only

Former Member
0 Likes
1,319

Hi,

you can use FM 'QF05_RANDOM_INTEGER'

DATA:

number TYPE i.

CALL FUNCTION 'QF05_RANDOM_INTEGER'

EXPORTING

ran_int_max = 1000

ran_int_min = 1

IMPORTING

ran_int = number

EXCEPTIONS

invalid_input = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

WRITE 😕 'Next available number is: ', number.

Hope this is useful to you.

Reward points if it is useful.

Thanks,

phani Diwakar.

Read only

Former Member
0 Likes
1,319

Hi

Try with this one :

REPORT ZRANDOM.

DATA RANINT LIKE QF00-RAN_INT.

PARAMETERS: P_MAX LIKE QF00-RAN_INT DEFAULT 100,

P_MIN LIKE QF00-RAN_INT DEFAULT 1,

P_TIMES TYPE I DEFAULT 10.

WRITE:/ 'RANDOM NUMBER'.

ULINE.

DO P_TIMES TIMES.

CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
  RAN_INT_MAX   = P_MAX
  RAN_INT_MIN   = P_MIN
IMPORTING
  RAN_INT       = RANINT
EXCEPTIONS
  INVALID_INPUT = 1
  OTHERS        = 2.

  IF SY-SUBRC EQ 0.
    WRITE:/ RANINT.
  ELSE.
    WRITE:/ 'UNABLE TO GENERATE RANDOM NUMBER'.
  ENDIF.
ENDDO.

With Regards

Nikunj shah

Read only

farihakazi
Active Contributor
0 Likes
1,319

if you want to generate numbers in sequence define an number range object in transaction SNRO. create intervals there.

Read only

Former Member
0 Likes
1,319

Hi Sandeep,

I think u can use the function module: GUID_CREATE.

check this it may be of som euse.

Regards

Abhilash.

Read only

matt
Active Contributor
0 Likes
1,319

Look at this and you'll find an important clue recently posted, that should help you complete your homework assignment.

Are you and MySAP Public, aka zhoulanb related?