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

For all entries vs Loop

hi experts I wonder why this two selection gives me a different result . I want to use the FOR ALL ENTRIES IN because it is much faster but it won't give me the exact result unlike LOOP or there something i don't know about FOR ALL ENTRIES.

  • FOR ALL ENRIES SELECTION

SELECT

BUKRS

GJAHR

HKONT

BELNR

DMBTR

SHKZG

ZUONR

INTO CORRESPONDING FIELDS OF TABLE it_data1 FROM

BSEG

FOR ALL ENTRIES IN it_select

WHERE bukrs IN S_BUKRS AND

GJAHR IN S_GJAHR AND

BELNR EQ it_select-BELNR AND

ZUMSK EQ SPACE.

*LOOP

LOOP AT it_select INTO wa_select.

SELECT

BSEG~BUKRS

BSEG~GJAHR

BSEG~HKONT

BSEG~BELNR

BSEG~DMBTR

BSEG~SHKZG

BSEG~ZUONR

APPENDING CORRESPONDING FIELDS OF TABLE it_data1 FROM

BSEG

WHERE BSEG~bukrs EQ wa_select-BUKRS AND

BSEG~GJAHR EQ wa_select-GJAHR AND

BSEG~BELNR EQ wa_select-BELNR

AND

BSEG~ZUMSK EQ SPACE.

ENDLOOP.

Please guys guide me.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 21, 2008 at 02:57 AM

    Hi,

    Before using FOR ALL ENTRIES statement,it is must to check the condition whether the internal table (in your case the internal table is 'it_select') is initial or not.If the internal table is initial,it will fetch all entries irrespective of the condition.Also while writing JOINS ,please include all key fields as selection fields.If keyfields are not included in the selection fields,duplicate entries will be truncated based on the fields given in the selection list.

    For example.

    IF it_select[] IS NOT INITIAL.

    SELECT

    BUKRS

    GJAHR

    HKONT

    BELNR

    DMBTR

    SHKZG

    ZUONR

    INTO CORRESPONDING FIELDS OF TABLE it_data1 FROM

    BSEG

    FOR ALL ENTRIES IN it_select

    WHERE bukrs IN S_BUKRS AND

    GJAHR IN S_GJAHR AND

    BELNR EQ it_select-BELNR AND

    ZUMSK EQ SPACE.

    ENDIF.

    Reward points if helpful.

    Regards,

    Aravind JM.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 21, 2008 at 02:45 AM

    Try:

    SELECT

    BUKRS

    GJAHR

    HKONT

    BELNR

    DMBTR

    SHKZG

    ZUONR

    INTO CORRESPONDING FIELDS OF TABLE it_data1 FROM

    BSEG

    FOR ALL ENTRIES IN it_select

    WHERE bukrs EQ it_select-BUKRS AND

    GJAHR EQ it_select-GJAHR AND

    BELNR EQ it_select-BELNR AND

    ZUMSK EQ SPACE.

    This is what your other loop select is doing. if this not the result you want, you have to change the other selects where condition

    Edited by: Aparna Shekhar on May 20, 2008 9:45 PM

    Edited by: Aparna Shekhar on May 20, 2008 9:47 PM

    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.