Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

For all entries vs Loop

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

9 REPLIES 9

Former Member
0 Kudos

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

0 Kudos

what do you mean? but that's the only condition i have to pass...

0 Kudos

In the loop code how did you use the select to pull data into it_select.

Can you post that?

0 Kudos

*Code for bkpf selection:

SELECT

BUKRS

BELNR

BUDAT

MONAT

GJAHR

BLART

XBLNR

INTO CORRESPONDING FIELDS OF TABLE it_select FROM

BKPF WHERE BUKRS IN s_bukrs AND

BUDAT in s_budat AND

GJAHR IN s_gjahr.

Former Member
0 Kudos

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.

0 Kudos

yah i'm doing that in my code but the issue is that why they don't give the same results. whats on FOR ALL ENTRIES.?

0 Kudos

Hi,

In query with FOR ALL ENTRIES,for fields ,BUKRS and GJAHR you have given SELECT OPTIONS(!) but for the select query within loop ,you have directly assigned a variable form work area,will it make a difference.

Regards,

Aravind JM.

0 Kudos

Hi ,

Please include the field BUZEI in selection list.

Use the following code.

IF it_select[] IS NOT INITIAL.

SELECT

BUKRS

GJAHR

BELNR

BUZEI

HKONT

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.

Regards,

Aravind JM.

0 Kudos

EXCELLENT

Thanks aravind you got it right...