05-21-2008 3:41 AM
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.
05-21-2008 3: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.
05-21-2008 3: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
05-21-2008 3:53 AM
what do you mean? but that's the only condition i have to pass...
05-21-2008 3:59 AM
In the loop code how did you use the select to pull data into it_select.
Can you post that?
05-21-2008 4:07 AM
*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.
05-21-2008 3: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.
05-21-2008 4:11 AM
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.?
05-21-2008 4:23 AM
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.
05-21-2008 5:46 AM
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.
05-21-2008 6:31 AM
EXCELLENT
Thanks aravind you got it right...