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

How to generate random sequence numbers

former_member295881
Contributor
0 Likes
1,335

Hello experts

Iu2019m writing a custom program and pulling data from VBAK & VBAP. As per requirement I also need to generate a sequence number randomly and finally store all data in text file and upload at server. The hiccup is I donu2019t know how to generate sequence numbers. Can somebody please show me how I can accomplish it?

Thanks a lot in advance

1 ACCEPTED SOLUTION
Read only

former_member206377
Active Contributor
0 Likes
863

Hi ,

Use FM QF05_RANDOM_INT to generate random numbers.


CALL FUNCTION 'QF05_RANDOM_INTEGER'
 EXPORTING
   RAN_INT_MAX         = '999'
   RAN_INT_MIN         = '000'
 IMPORTING
   RAN_INT             = d_result
 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.

Hello experts

Iu2019m writing a custom program and pulling data from VBAK & VBAP. As per requirement I also need to generate a sequence number randomly and finally store all data in text file and upload at server. The hiccup is I donu2019t know how to generate sequence numbers. Can somebody please show me how I can accomplish it?

Thanks a lot in advance

4 REPLIES 4
Read only

Former Member
0 Likes
863

hi

for genetae a number you can use the function module

NUMBER_GET_NEXT.

input-Create a object from SNRO tcode.

Read only

former_member206377
Active Contributor
0 Likes
864

Hi ,

Use FM QF05_RANDOM_INT to generate random numbers.


CALL FUNCTION 'QF05_RANDOM_INTEGER'
 EXPORTING
   RAN_INT_MAX         = '999'
   RAN_INT_MIN         = '000'
 IMPORTING
   RAN_INT             = d_result
 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.

Read only

Former Member
0 Likes
863

0 - your question is not exactly basic, but it does show a lack of willingness to find an answer on your own. Simply typing random and pressing F4 in SE37 returns a passle of hits.

Please search next time before asking.

Rob

Read only

0 Likes
863

Find the below code,

data: lv_range type datatype-char0128.

call function 'RANDOM_C'

exporting

len_min = 20

len_max = 20

char_min = 1

char_max = 20

importing

rnd_value = lv_range.

LV_RANGE param will have a random value..

If you need number you can use the FM "RANDOM_I4"

Thanks,

Prathap