on 10-18-2007 11:08 AM
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.
The DELETE ADJACENT DUPLICATES option is the best one but you do not have to sort by VBELN and VKORG. You just need to sort by VKORG. Look at the code below.
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,
ts_tvkot TYPE HASHED 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.
IF sy-subrc EQ 0.
tt_temp1[] = tt_vbak[].
SORT tt_temp1 BY vkorg.
DELETE ADJACENT DUPLICATES FROM tt_temp1 COMPARING vkorg.
* get sales org name from tvkot
SELECT vkorg
vtext
FROM tvkot
INTO TABLE ts_tvkot
FOR ALL ENTRIES IN tt_temp1
WHERE spras EQ sy-langu
AND vkorg EQ tt_temp1-vkorg.
ENDIF.
LOOP AT tt_vbak.
READ TABLE ts_tvkot WITH KEY vkorg = tt_vbak-vkorg
TRANSPORTING
vtext.
IF sy-subrc EQ 0.
* Populate VTEXT
ENDIF.
ENDLOOP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check run time...
<b>goto theT.code: st03
ExportMode
there u will find the run time o f u Query</b>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> check run time...
>
> <b>goto theT.code: st03
>
> ExportMode
>
> there u will find the run time o f u Query</b>
May I know who to check the runtime using ST03? How to go to ExportMode?
The Tcode is for Workload in System IDS
I only can see a menu bar:
--Today's workload
-
Total
--Load Distribution
--Collector
hi,
its better if you make use of distinct keyword in select statement.
write:
SELECT distinct vbeln vkorg vbtyp FROM vbak
INTO TABLE tt_vbak.
here after distinct write those fields based on which you want unique entries.
like if you write:
select distinct * into itAB FROM VBAK, THEN IT WILL CHECK FOR ALL FIELDS AND IF THERE IS DIFFERENCE OF ONE FIELD VALUE BETWEEN TWO ROWS OF TABLE IT WILL SELECT THOSE ROWS.
IN YOUR CASE I THINK YOU WANT UNIQUE RECORDS BASED ON VKORG, SO WRITE:
SELECT DISTINCT VKORG INTO ITAB FROM VBAK.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.