‎2009 Apr 14 6:05 AM
Hi Experts,
I have a internal table with 1000 records, I would like to select 50 records randomly from the 1000 records.
Is there any better way, for this logic. Please let me know .
Thank you,
Prasead
‎2009 Apr 14 6:12 AM
‎2009 Apr 14 6:08 AM
Hi,
What is the purpose of selecting records randomly ?
Check this FM gives the random number QF05_RANDOM_INTEGER
‎2009 Apr 14 6:12 AM
‎2009 Apr 14 6:12 AM
Try FM 'RANDOM_TABLE_ENTRY'.
Ex:
REPORT ZTEST.
TABLES: marc.
DATA: str TYPE matnr.
DO 10 TIMES.
CALL FUNCTION 'RANDOM_TABLE_ENTRY'
EXPORTING
table = 'MARC'
item1 = 'MATNR' <---- Field1
ITEM2 = <---- Field2
ITEM3 = <---- Field3
ITEM4 = <---- Field4
IMPORTING
value1 = str <---- Field1 Value
VALUE2 =
VALUE3 =
VALUE4 =
TABLESIZE =
TABLEPOS =
EXCEPTIONS
GENERATION_FAILED = 1
OTHERS = 2.
WRITE: / str.
ENDDO.
Thanks.
Edited by: Sap Fan on Apr 14, 2009 7:18 AM
‎2009 Apr 14 6:19 AM
hi
check this out
Use Structure RESERVELNS
Number of reserved rows for event print_end_of_page. If no number is specified, the text specified there is overwritten by the list.
thanks
‎2009 Apr 14 6:26 AM
Hi,
You can use FM: 'QF05_RANDOM_INTEGER' to get the random records.
Regards,
Chris Gu
‎2009 Apr 14 6:46 AM
DATA: MAX TYPE I,
RND TYPE I.
PARAMETERS: SAMPLE TYPE I. " to decide on number of entries can hard code on requirement
DESCRIBE TABLE ITAB LINES MAX. " to get the max number of entries in table
DO SAMPLE TIMES.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
RAN_INT_MAX = MAX
RAN_INT_MIN = 1
IMPORTING
RAN_INT = RND " Here you get a random integer
EXCEPTIONS
INVALID_INPUT = 1
OTHERS = 2.
READ TABLE ITAB INDEX RND. " Use RND as index and read that entry.
WRITE:/ ITAB-FIELD. " This is the random entry you can place it in a new internal table
ENDDO.
Regards,
Lalit Mohan Gupta.
‎2009 Apr 28 2:32 AM