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

Select records Randomly

Former Member
0 Likes
3,004

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
Read only

Former Member
0 Likes
1,599

Limit the Select query with UPTO 50 ROWS.

7 REPLIES 7
Read only

Former Member
0 Likes
1,599

Hi,

What is the purpose of selecting records randomly ?

Check this FM gives the random number QF05_RANDOM_INTEGER

Read only

Former Member
0 Likes
1,600

Limit the Select query with UPTO 50 ROWS.

Read only

awin_prabhu
Active Contributor
0 Likes
1,599

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

Read only

Former Member
0 Likes
1,599

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

Read only

Former Member
0 Likes
1,599

Hi,

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

Regards,

Chris Gu

Read only

Former Member
0 Likes
1,599
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.

Read only

Former Member
0 Likes
1,599

worked out