2014 Feb 12 11:50 AM
Hi all,
we are trying to obtain this result:
We are able to convert the standard table to a hashed table but we are not able to define the key at runtime.
We found this: Reading Lines of Tables (SAP Library - ABAP Programming (BC-ABA))
If you do not know the name of one of the key fields until runtime, you can specify it dynamically as the content of a field n1 ... nn using (n1)
= f1 (n2) = f2 If the data types of f1 ... fn are not compatible with the key fields, the system converts them. If the row type of the internal table is not structured, you can specify a comparison with the pseudo-component table_line.
But we cannot understand how does it work.
Could you help us?
Thank you
2014 Feb 12 2:29 PM
Hi all,
I found the solution. You need to put all the key columns name on a standard table and include it in brackets (...) as internal table.
Here an example:
TYPES: BEGIN OF ls_key_elem,
name(32) TYPE c,
END OF ls_key_elem.
DATA: lt_key_elem TYPE STANDARD TABLE OF ls_key_elem,
wa_key_elem TYPE ls_key_elem.
wa_key_elem-name = 'ID'.
APPEND wa_key_elem TO lt_key_elem.
wa_key_elem-name = 'ID2'.
APPEND wa_key_elem TO lt_key_elem.
CREATE DATA lt_table LIKE HASHED TABLE OF <ls_table> WITH UNIQUE KEY (lt_key_elem).
ASSIGN lt_table->* to <lt_table>.
READ TABLE <lt_table> ASSIGNING <ls_table> WITH TABLE KEY ('ID') = 'IDVALUE' ('ID2') = 'ID2VALUE'.
Thank you
2014 Feb 12 12:09 PM
Hi,
If you want to convert standard table into hashed table as part performance then you can try with secondary keys..
Like,
DATA : t_mara TYPE STANDARD TABLE OF mara
WITH UNIQUE HASHED KEY sec_key COMPONENTS matnr.
READ TABLE t_table INTO wa_mara WITH TABLE KEY sec_key COMPONENTS matnr = matnr.
Thanks & Regards,
Arun
2014 Feb 12 1:44 PM
Hi Arun,
thank you for your answer.
This could be useful but we still do not know how to define the key at runtime.
In your example matnr is just a component. How can we define these components at runtime?
2014 Feb 12 2:11 PM
Hi Alberto,
Are you creating the hash table dynamically ? source table of type also dynamic ?
Thanks & Regards,
Arun
2014 Feb 12 2:29 PM
Hi all,
I found the solution. You need to put all the key columns name on a standard table and include it in brackets (...) as internal table.
Here an example:
TYPES: BEGIN OF ls_key_elem,
name(32) TYPE c,
END OF ls_key_elem.
DATA: lt_key_elem TYPE STANDARD TABLE OF ls_key_elem,
wa_key_elem TYPE ls_key_elem.
wa_key_elem-name = 'ID'.
APPEND wa_key_elem TO lt_key_elem.
wa_key_elem-name = 'ID2'.
APPEND wa_key_elem TO lt_key_elem.
CREATE DATA lt_table LIKE HASHED TABLE OF <ls_table> WITH UNIQUE KEY (lt_key_elem).
ASSIGN lt_table->* to <lt_table>.
READ TABLE <lt_table> ASSIGNING <ls_table> WITH TABLE KEY ('ID') = 'IDVALUE' ('ID2') = 'ID2VALUE'.
Thank you