Application Development and Automation 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: 
Read only

ITAB Delete Problem

Former Member
0 Likes
849

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
822

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.

7 REPLIES 7
Read only

Former Member
0 Likes
822

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

Read only

Former Member
0 Likes
823

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.

Read only

0 Likes
822

Thank All my problem is solved. Your points awarded.

Read only

Former Member
0 Likes
822

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.

Read only

Former Member
0 Likes
822

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.

Read only

Former Member
0 Likes
822

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

Read only

Former Member
0 Likes
822

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