‎2005 Dec 27 3:40 AM
Hi All,
I have created the following ITAB;
Data itab_sales_orders Like BAPIORDERS OCCURS 0 WITH HEADER LINE and this table has 1 record.
In a Loop I delete a record that means it does not contain any records;
LOOP AT itab_sales_orders.
DELETE itab_sales_orders INDEX sy-tabix.
ENDLOOP.
Then in a SQL query I use itab_sales_orders;
SELECT BSTDK
INTO VBKD-BSTDK
FROM VBKD
FOR ALL ENTRIES IN itab_sales_orders
WHERE BSTKD = v_pono and
VBELN = itab_sales_orders-SD_DOC.
VBKD-BSTDK gets a value because the itab still contains a record. Idealy VBKD-BSTDK should be blank and no record should exist in itab. Why this happen?
Thanks,
Kishan
‎2005 Dec 27 3:45 AM
Dear Kishan,
Using FOR ALL ENTRIES has a caution. If there is no record in the ITAB then in where clause it will be treated as '*'. Hence in the case of empty itab, your query can be re-written as:-
SELECT BSTDK
INTO VBKD-BSTDK
FROM VBKD
WHERE BSTKD = v_pono AND
VBELN = '*'.
Regards,
Deva.
‎2005 Dec 27 3:44 AM
HI,
You already deleted all records in itab.How you will get record for SQL query. first fill some data relevent to query inside itab and execute query.
Regards,
Nandha
‎2005 Dec 27 3:45 AM
Dear Kishan,
Using FOR ALL ENTRIES has a caution. If there is no record in the ITAB then in where clause it will be treated as '*'. Hence in the case of empty itab, your query can be re-written as:-
SELECT BSTDK
INTO VBKD-BSTDK
FROM VBKD
WHERE BSTKD = v_pono AND
VBELN = '*'.
Regards,
Deva.
‎2005 Dec 27 3:55 AM
Thank All my problem is solved. Your points awarded.
‎2005 Dec 27 3:48 AM
Hi,
I think the value in the header line is not deleted, so you are getting this result.
Try using free or clear and try.
‎2005 Dec 27 3:49 AM
Hi Kishan,
Your problem is not with having some records in the itab, it is actually not having any records in the itab before you use it in the SELECT statement with the option FOR ALL ENTRIES. If there are no entries in your itab, then FOR ALL ENTRIES will select all records. Just before your SELECT statement, add this statement as follows.
IF NOT itab_sales_orders[] IS INITIAL.
SELECT BSTDK
INTO VBKD-BSTDK
FROM VBKD
FOR ALL ENTRIES IN itab_sales_orders
WHERE BSTKD = v_pono and
VBELN = itab_sales_orders-SD_DOC.
ENDIF.
‎2005 Dec 27 3:51 AM
Hi Check the initial condition before selecting.
if not itab_sales_orders[] is initial.
SELECT BSTDK
INTO VBKD-BSTDK
FROM VBKD
FOR ALL ENTRIES IN itab_sales_orders
WHERE BSTKD = v_pono and
VBELN = itab_sales_orders-SD_DOC.
endif.Try this..
regards
vijay
‎2005 Dec 27 3:51 AM
Hi,
Before using FOR ALL ENTRIES, always check whether the table mentioned in FOR ALL ENTRIES is blank or not.
eg.
if not itab_sales_orders[] is initial.
SELECT BSTDK
INTO VBKD-BSTDK
FROM VBKD
FOR ALL ENTRIES IN itab_sales_orders
WHERE BSTKD = v_pono and
VBELN = itab_sales_orders-SD_DOC.
endif.
This is the more appropriate way while using FOR ALL ENTRIES.
Here, the error is of header line data being not cleared.
Clear the header line & do check the internal table is blank or not.
Best regards,
Prashant