Application Development 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: 

Select records Randomly

Former Member
0 Kudos
1,614

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos
209

Limit the Select query with UPTO 50 ROWS.

7 REPLIES 7

Former Member
0 Kudos
209

Hi,

What is the purpose of selecting records randomly ?

Check this FM gives the random number QF05_RANDOM_INTEGER

Former Member
0 Kudos
210

Limit the Select query with UPTO 50 ROWS.

awin_prabhu
Active Contributor
0 Kudos
209

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

Former Member
0 Kudos
209

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

Former Member
0 Kudos
209

Hi,

You can use FM: 'QF05_RANDOM_INTEGER' to get the random records.

Regards,

Chris Gu

Former Member
0 Kudos
209
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.

Former Member
0 Kudos
209

worked out