‎2007 Oct 19 1:01 PM
How can I read data records from an internal table in a random order?
My aim is to select records randomly from an internal table without speciafying a key.
‎2007 Oct 19 1:02 PM
‎2007 Oct 19 1:08 PM
use RANDOM_AMOUNT to generate random number for index...
and read theline from itab corresponding to this index...
‎2007 Oct 30 11:09 AM
Get the random number using the RANDOM_AMOUNT function into lv_number
then use the syntax
read table itab index lv_number.
also, make sure than your lv_number value is not greater than the number of rows in your internal table
‎2007 Oct 30 11:12 AM
I think the function RANDOM_AMOUNT gives decimal numbers
Use this code to get only integers
*&---------------------------------------------------------------------*
*& Report ZKRIS_RANDOM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report zkris_random.
selection-screen begin of block b1 with frame title title1.
selection-screen begin of block b2 with frame title title2.
parameters: low type i.
parameters: high type i.
selection-screen end of block b2.
parameters: num_vals type i.
selection-screen end of block b1.
initialization.
title1 = 'Parameters'.
title2 = 'Limits'.
start-of-selection.
types: begin of random_numbers_type,
random_nr type i,
end of random_numbers_type.
data: random_numbers type random_numbers_type occurs 0 with header line.
constants: a type i value 21,
c type i value 101,
m type i value 32768,
start type i value 500.
data: new_num type i,
interval type i.
data: last_num type i.
if high < low or num_vals < 1.
write: 'parameter error'.
exit.
endif.
if last_num is initial.
last_num = start.
endif.
clear random_numbers[].
interval = high - low + 1.
do num_vals times.
new_num = ( a * last_num + c ) mod m.
last_num = new_num.
random_numbers-random_nr = ( new_num mod interval ) + low.
append random_numbers.
enddo.
loop at random_numbers.
write:/ random_numbers-random_nr.
endloop.