Skip to Content

Internal tables - is it possible to link a secondary index with the primary index?


I'm trying to use standard internal tables, using a sorted access via a secondary key. This internal table is displayed in an ALV grid.

In certain cases, after finding a record, which is read using the secondary key, I want to highlight that row in the grid, using method SET_SELECTED_ROWS from class CL_GUI_ALV_GRID. After finding the records, the SY-TABIX contains the index from secondary index table. Method SET_SELECTED_ROWS allows only (if my understanding is correct) to set the the row id as per the primary index table.

If I do the READ TABLE using the primary key in order to be able to tell SET_SELECTED_ROW what is the proper row id, then I'm skipping the benefits of using a secondary sorted key (I would want to avoid SORT and READ with BINARY SEARCH).

I I do the READ TABLE using the secondary sorted key, I'm not able to tell SET_SELECTED_ROW what is the row id I want to highlight.....

Is there any way to get the table's primary index having the secondary one (without doing two READS of course)? ie is there any link between secondary and primary indexes from an internal table?

Thank you. I appreciate your help and time.



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Nov 19, 2015 at 12:19 AM

    Only option I see to avoid the second read is to add the index as an extra field in the table. You'd need to fill it every time the data is sorted.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 19, 2015 at 12:58 PM

    Thank you Srini for your time.

    Just let me mention that I was not trying to link two internal tables.

    I have one standard internal table, defined with a sorted secondary key. I read individual records, with READ TABLE and using the secondary key. If a record is found, SY-TABIX contains the index as per the secondary index table. This does not allow me to highlight this finding in an ALV, unless I can pick up the primary index (the physical row number).

    My question was: is it possible to know the primary index (row number), if I have the secondary index?

    Gerrit gave a good workaround. I'm just still curious if the system maintains that link or not.

    Thanks. Regards,


    Add a comment
    10|10000 characters needed characters exceeded

    • Suhas Saha Luis Gusmao Henriques

      I'm afraid I can't completely agree with you with regards to SAP documentation containing the answer for my question.

      What i meant to say was, per SAP documentation the answer to your question is NO. Therefore you cannot set the correct row via SET_SELECTED_ROWS( ) using the SY-TABIX set after READ TABLE using secondary key.

      This means you have to use somekind of workaround. The one suggested by Gerrit seems legit! 😉

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.