Skip to Content

Usage of Sorted Keys in standard tables

Hi,

If I have a sorted secondary key (unique or non-unique) in my internal table, and use the secondary key with my DELETE statement (DELETE ... WITH TABLE KEY <secondary_key_name> COMPONENTS ... = ...), I still get a prio 2 checkman error saying possible sequential read. My question:

1. What's the difference between usages of sorted key and a sorted table with regards to a READ statement?

2. Would I still have to do a SORT on the standard table by the secondary key components and then do a BINARY search to avoid the possible sequential read? (in that case why should i mention the key to be "sorted"?

Thanks in advance,

Best Regards

Anantharaman L

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Feb 22, 2011 at 06:04 AM

    Hi,

    I don't think it is possible to have a secondary key for an internal table!

    Please show us the definition of your internal table and why you believe to have a secondary key!

    Regards,

    Klaus

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 08, 2012 at 09:50 AM

    Hi Anantharaman ,

    When we define sorted secondary keys, we do not have to sort it explicitly and use a binary search. we just have to define the sorted secondary keys and read based on that keys. The read statement should be as follows:

    read TABLE <internal table>INTO <work area/field symbol>WITH KEY <secondary key name> COMPONENTS <comp1 = value>.

    eg : read TABLE lt_tab INTO lw_tab WITH KEY key_1 COMPONENTS carrid1 = 'CC'

    Complete Code :

    REPORT YTEST.

    DATA: lt_tab TYPE YSTRU1_TT,

    lw_tab LIKE LINE OF lt_tab.

    lw_tab-carrid1 = 'BB'.

    lw_tab-connid = '50'.

    APPEND lw_tab to lt_tab.

    lw_tab-carrid1 = 'ZZ'.

    lw_tab-connid = '50'.

    APPEND lw_tab to lt_tab.

    lw_tab-carrid1 = 'WW'.

    lw_tab-connid = '50'.

    APPEND lw_tab to lt_tab.

    lw_tab-carrid1 = 'AA'.

    lw_tab-connid = '50'.

    APPEND lw_tab to lt_tab.

    lw_tab-carrid1 = 'XX'.

    lw_tab-connid = '50'.

    APPEND lw_tab to lt_tab.

    lw_tab-carrid1 = 'CC'.

    lw_tab-connid = '50'.

    APPEND lw_tab to lt_tab.

    CLEAR lw_tab.

    read TABLE lt_tab INTO lw_tab WITH KEY key_1 COMPONENTS carrid1 = 'CC'.

    Note : Table type ystru1_tt is defined with a unique-sorted secondary key carrid1.

    Hope this will be helpful.

    Warm Regards,

    Jenny

    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.