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

Internal table help

Hi,

I have an internal table and i would like to read a bunch of records that matches the selection criteria in one step (without using a loop), just like we do using select statement from a DB table...

This is what I currently have...

INTTABLE1 IS A SORTED TABLE WITH KEY F1 F2 F3 F4.

LOOP AT INTTABLE1 INTO S_WORKAREA.

IF S_WORKAREA-F1 = INTTABLE2-F1 AND

S_WORKAREA-F2 = INTTABLE2-F2 AND

S_WORKAREA-F3 = INTTABLE2-F3 AND

S_WORKAREA-F4 = INTTABLE2-F4.

APPEND S_WORKAREA-F5 TO INTTABLE3.

ENDIF.

ENDLOOP.

So, I would like to get rid of this LOOP and still be able to append all the matching records to INTTABLE3. Is there any functionality like that, which lets me do it.

Thanks alot

John

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2005 at 03:15 PM

    Hi John,

    I'm afraid there's no such ABAP statement. But there is indeed a trick you can use:

    - First of all, define an itab with the same structure as INTTABLE1, say INTTABLE1_COPY.

    - Then, write INTTABLE1_COPY[] = INTTABLE1[].

    - Finally, write DELETE INTTABLE1_COPY WHERE NOT (your_condition)

    ...and that's it.

    Please tell me if it worked. BR,

    Alvaro

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 02, 2005 at 03:18 PM

    Hi John!

    a) There is no generic access with read tables.

    b) You can copy whole table and delete entries not matching your requirements - 2 statements, but in one step you will have twice the amount of data.

    c) Something like this:

    read inttable1 with key ....
    loop at inttable1 from sy-tabix into wa.
    if wa-key <> wa2-key.
    exit.
    endif.
    append wa to inttable2.
    endloop.

    Advantage: you will only loop over required entries.

    Disadvantage: more lines of coding (but fast and small memory usage).

    Regards,

    Christian

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2005 at 03:25 PM

    Hi John,

    the only possibility I can imagine is doing some reads instead of looping.

    Something like this:

    read table inttable1 into s_workarea with key ...

    if sy-subrc = 0.

    l_tabix = sy-tabix.

    while sy-subrc = 0.

    l_tabix = l_tabix + 1.

    read table inttable1 into s_workarea index l_tabix.

    • check the keyfields now and exit if not ok.

    endwhile.

    endif.

    This is not very nice too, but may be a bit faster as you are dealing with a sorted or may be better a hashed table.

    Another option (if you know the index of the first and the last relevant row) is doing a:

    append lines of inttable1 from index1 to indexl to inttable3.

    regards

    Siggi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 02, 2005 at 03:29 PM

    You are going to have to read thru the internal table somehow so try this:

    LOOP AT INTTABLE1 ASSIGNING <S_WORKAREA>
      WHERE F1 = INTTABLE2-F1 and
            F2 = ...
    
      APPEND <S_WORKAREA-F5> to INTTABLE3.
    
    ENDLOOP.

    This will allow you to take advantage of the fact that you have a sorted table.

    If your key is unique in your sorted table then try:

      READ TABLE INTTABLE1 ASSIGNING <S_WORKAREA>
        WITH TABLE KEY
          F1 = INTTABLE2-F1
          F2 = ...
    
      APPEND <S_WORKAREA-F5> to INTTABLE3.

    Field symbol <S_WORKAREA> is type line of INTTABLE1.

    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.