Skip to Content
0
Former Member
Oct 18, 2007 at 10:08 AM

Unique record to internal table

70 Views

  • I have enquiry regarding getting unique record into internal table:( I alway need to get unique record from a big table ( > 100, 000 record)

  • Refer to the example below, may I know which method(method #1 or

  • method #2) have better runtime?

  • or anyone have better solution for pop unique record into internal

  • table?

TYPES: BEGIN OF ty_vbak,

vbeln TYPE vbak-vbeln,

vkorg TYPE vbak-vkorg,

vbtyp TYPE vbak-vbtyp,

END OF ty_vbak,

BEGIN OF ty_tvkot,

vkorg TYPE tvkot-vkorg,

vtext TYPE tvkot-vtext,

END OF ty_tvkot.

DATA: tt_vbak TYPE STANDARD TABLE OF ty_vbak WITH HEADER LINE,

tt_temp1 TYPE STANDARD TABLE OF ty_vbak WITH HEADER LINE,

tt_temp2 TYPE STANDARD TABLE OF ty_tvkot WITH HEADER LINE,

ts_tvkot TYPE SORTED TABLE OF ty_tvkot

WITH UNIQUE KEY vkorg WITH HEADER LINE.

  • get record from table vbap

SELECT vbeln vkorg vbtyp FROM vbak

INTO TABLE tt_vbak.

  • get unique vkorg

  • method #1

tt_temp1[] = tt_vbak[].

SORT tt_temp1 BY vbeln vkorg.

DELETE ADJACENT DUPLICATES FROM tt_temp1 COMPARING vkorg.

  • end method #1

  • method #2

LOOP AT tt_vbak.

tt_temp2-vkorg = tt_vbak-vkorg.

COLLECT tt_temp2. CLEAR tt_temp2.

ENDLOOP.

  • end method #2

  • get sales org name from tvkot

SELECT vkorg vtext FROM tvkot

INTO TABLE ts_tvkot

FOR ALL ENTRIES IN tt_temp1/tt_temp2

WHERE spras = sy-langu

AND vkorg = tt_temp1/tt_temp2-vkorg.