Skip to Content
author's profile photo Former Member
Former Member

Read hashed internal table with runtime key

Hi all,

we are trying to obtain this result:

  • We have a source standard table itab
  • We want transform this table to a hashed table
  • The unique key of the hashed table must be calculated at runtime (e.g. the columns of the table used as key are known only at runtime)
  • Then we want to read data from the table using the key defined above.

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 12, 2014 at 02: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 12, 2014 at 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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.