Hi,
this question is for the real experts (like Horst Keller) so please don't answer if not really know...
I delare an internal table with various fields as SORTED TABLE WITH UNIQUE KEY table_line - I won't have any duplicates as I fill from a database (customizing) table.
In a LOOP AT this table WHERE <field> = <value>, will the loop use the key if it's the first key?
What are the rules of index use in LOOP?
I mean NOT secondary index as they can be defined now.
Thanks a lot and best regards,
Clemens
Hi Clemens,
I really can't believe that a respected topaz level member like yourself would discriminate other users by asking them not to reply to your question. Surely you are being VERY disrespectful to other members.
If you have a direct question to Dr Horst Keller (or someone "like" him), I'm sure you can figure out his email address. (tip: it's first_name dot last_name at company dot com)
Regards,
Custodio
Clemens... that's is the doc, look at Optimization of the WHERE Condition (so here answer is YES)
Regards,
Raymond
Hi,
No, I believe (why should the table_line, whatever the resulting key, cause something to differ from the normal rules..?), based on this:
There is no implicit selection of a suitable key or index. The used table key or table index is always specified uniquely. The syntax check issues a warning if there is a suitable secondary table key but this table key is not used. This warning should be removed through using the key. However, in exceptional cases, it can be bypassed using a pragma.
The values for using primary key would need to be provided in full, if I remember correctly.
No,
LOOP AT this_sorted_table USING KEY primary_key
WHERE
...
compiles with partial key, as long as the "beginning of key" is somewhere in WHERE condition (and rest of WHERE optimization conditions are fulfilled). My understanding of the red statement above still is - without the addition USING KEY, no key will be used by LOOP...
cheers
Jānis
Message was edited by: Jānis B
The code:
REPORT zjbtst20.
TYPES: BEGIN OF ty_item,
mandt TYPE symandt,
group(3) TYPE c,
counter(8) TYPE n,
a TYPE sysuuid_c32,
b TYPE sysuuid_c32,
c TYPE sysuuid_c32,
d TYPE sysuuid_c32,
e TYPE sysuuid_c32,
END OF ty_item,
tyt_sorted_items TYPE SORTED TABLE OF ty_item
WITH UNIQUE KEY table_line .
DATA: gt_sorted_table TYPE tyt_sorted_items .
DATA: gs_sorted_table_item TYPE ty_item .
DATA: gx_ex TYPE REF TO cx_uuid_error .
DATA: go_timer TYPE REF TO if_abap_runtime .
DATA: g_runtime TYPE int4 .
DATA: g_groupk(3) TYPE c .
DATA: g_counterk(8) TYPE n .
LOAD-OF-PROGRAM .
gs_sorted_table_item-mandt = sy-mandt .
DO 3 TIMES .
WRITE sy-index TO gs_sorted_table_item-group RIGHT-JUSTIFIED .
DO 10000 TIMES .
TRY .
gs_sorted_table_item-counter = sy-index .
gs_sorted_table_item-a = cl_system_uuid=>create_uuid_c32_static( ).
gs_sorted_table_item-b = cl_system_uuid=>create_uuid_c32_static( ).
gs_sorted_table_item-c = cl_system_uuid=>create_uuid_c32_static( ).
gs_sorted_table_item-d = cl_system_uuid=>create_uuid_c32_static( ).
gs_sorted_table_item-e = cl_system_uuid=>create_uuid_c32_static( ).
CATCH cx_uuid_error INTO gx_ex.
MESSAGE gx_ex TYPE 'E' .
ENDTRY .
INSERT gs_sorted_table_item INTO TABLE gt_sorted_table .
ENDDO .
ENDDO .
START-OF-SELECTION .
g_groupk = 2 .
go_timer = cl_abap_runtime=>create_hr_timer( ) .
go_timer->get_runtime( ). "init
DO 10000 TIMES .
g_counterk = sy-index.
LOOP AT gt_sorted_table INTO gs_sorted_table_item
WHERE
mandt = sy-mandt AND
group = g_groupk AND
counter = g_counterk .
EXIT .
ENDLOOP .
ENDDO .
g_runtime = go_timer->get_runtime( ) .
WRITE: / g_runtime.
go_timer = cl_abap_runtime=>create_hr_timer( ) .
go_timer->get_runtime( ). "init
DO 10000 TIMES .
g_counterk = sy-index.
LOOP AT gt_sorted_table INTO gs_sorted_table_item
USING KEY primary_key
WHERE
mandt = sy-mandt AND
group = g_groupk AND
counter = g_counterk .
EXIT .
ENDLOOP .
ENDDO .
g_runtime = go_timer->get_runtime( ) .
WRITE: / g_runtime.
Add a comment