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

Read Table

can i use two conditions in :

Read Table itab With Key .....?

i want to check two conditions like:

Read Table itab With Key field1 = '1000' and field2 = '5000'.

pls give me the syntax..........

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 05:13 AM

    hi,

    Omit the and:

    Read Table itab With Key field1 = '1000'

    field2 = '5000'.

    Regards,

    Subramanian

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 05:14 AM

    correct syntax is :

    Read Table itab With Key field1 = '1000' field2 = '5000'.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 19, 2008 at 05:14 AM

    Hi Babu,

    Yes offcourse you can use two key fields in the Read statement

    READ TABLE itab WITH TABLE KEY k1 = v1 ... kn =

    vn [additions].

    Effect

    The system uses the specified table key values to locate the correct line. If there is more than one entry with the same key, the system returns the first. The way in which the system looks for table entries depends on the table type:

    STANDARD TABLE:

    The system searches from the start of the table. The response time is in linear relation to the number of table entries.

    SORTED TABLE:

    The response time is in logarithmic relation to the number of table entries.

    HASHED TABLE:

    The response time is constant.

    Notes

    When you specify the table key using k1 = v1 ... kn = vn you must specify values for all of the key fields. If the type of a value is not compatible with the type of the corresponding key field,the system uses MOVE logic to convert it to the type of the key field before reading from the table.

    If you do not know the name of a component until runtime, you can use the expression WITH TABLE KEY ... (ni) = vi ... to specify it dynamically as the contents of the field ni. If ni is empty at runtime, the key specification is ignored.

    If a table has a non-structured line type, you can use the pseudocomponent TABLE_LINE to address the entire line as the table key (see also Pseudocomponent TABLE_LINE in Internal Tables).

    If you specify the key implicitly using FROM wa, the values for the table key are taken from the corresponding components of the (structured) field wa. wa must be compatible with the line type of itab. In this way, you can access a table using READ without having to know the table key statically. If the table key is empty, the system reads the first line.

    &************** Reward Point if helpful**********&

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 05:19 AM

    For better performance use BINARY SEARCH while reading the internal table.

    SORT itab BY field1 field2.
    READ TABLE itab WITH KEY field1 = '1000'
                                                field2 = '500'
                                         BINARY SEARCH.
    if sy-subrc eq 0.
    endif.

    Regards

    Kannaiah

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 05:28 AM

    Hi,

    Yes u can use

    read table key field1 = '1000'

    field2 = '5000'

    binary search.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 19, 2008 at 05:13 AM
    Read Table itab With Key field1 = '1000' 
                                           field2 = '5000'.

    Best regards,

    Prashant

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 05:31 AM

    Hi,

    Yes we can use number of keys in READ statement.

    One thing we need to keep in mind while reading a internal table use always BINARY SEARCH and have the SORTED table.

    Example:

    SORT itab BY field1 field2. 
    READ TABLE itab WITH KEY field1 = '1000'    field2 = '500' BINARY SEARCH.

    This will surely help you.

    Plz reward if useful.

    Thanks.

    Dhanashri.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 05:39 AM

    What's the difference b/w my post and Dhanshri post.

    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.