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

Regarding sql query

Former Member
0 Likes
820

Hi guriji's.

There are two table t_itab1 and t_itab2. I want delete the whole row based on matnr which is in both table then pirnt the t_itab2 table output.

for this i have written one query which is properly not working.

LOOP AT T_ITAB2.

IF T_ITAB1-MATNR = T_ITAB2-MATNR .

SUM = SY-TABIX.

DELETE T_ITAB2 INDEX SUM.

ENDIF.

ENDLOOP.

plz tell me what is the problem.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
796

Hi,

Use read to select the matnr line from other table

LOOP AT T_ITAB2 into fs_itab2.

read table it_itab1 into fs_itab1 with key matnr eq fs_itab2-matnr.

if sy-subrc EQ 0.

DELETE T_ITAB2 from fs_itab2..

endif.

ENDLOOP.

6 REPLIES 6
Read only

Former Member
0 Likes
797

Hi,

Use read to select the matnr line from other table

LOOP AT T_ITAB2 into fs_itab2.

read table it_itab1 into fs_itab1 with key matnr eq fs_itab2-matnr.

if sy-subrc EQ 0.

DELETE T_ITAB2 from fs_itab2..

endif.

ENDLOOP.

Read only

Former Member
0 Likes
796

Hello

Try this:


LOOP AT T_ITAB2.
  READ TABLE T_ITAB1 WITH KEY MATNR = T_ITAB2-MATNR.
  IF SY-SUBRC = 0.
    DELETE T_ITAB2.
  ENDIF.
ENDLOOP.

Read only

former_member209217
Active Contributor
0 Likes
796

You are not rading the values from internal table T_ITAB1

Use READ statement after the loop statement

READ table t_tab1 with key matnr eq t_tab1-matnr

Regards,

lakshman.

Edited by: Lakshman N on Oct 29, 2009 7:40 AM

Read only

former_member222860
Active Contributor
0 Likes
796

Try this:

LOOP AT T_ITAB2.
  READ TABLE T_ITAB1 WITH KEY MATNR = T_TAB2-MATNR.
  IF SY-SUBRC = 0.
    DELETE T_ITAB2 .
  ENDIF.
ENDLOOP.

Read only

0 Likes
796

HI,

The problem is that you are not reading the table T_ITAB1 before deletion. Try the code below.

LOOP AT T_ITAB2.

READ TABLE T_ITAB1 WITH KEY MATNR = T_ITAB2-MATNR.

IF SY-SUBRC = 0.

DELETE T_ITAB2.

ENDIF.

ENDLOOP.

Read only

venkat_o
Active Contributor
0 Likes
796

Hi Sachin, Try this way.


LOOP AT t_itab1."Loop t_itab1 first
  LOOP AT t_itab2 WHERE matnr = t_itab1-matnr."Check matnr in t_itab2 based on t_itab1 matnr.
    "If you find matnr in t_itab2. You can delete using sy-tabix.
    "Sy-tabix gives the row number of the matnr found in t_itab2.
    DELETE t_itab2 INDEX sy-tabix.
  ENDLOOP.
ENDLOOP.
Thanks Venkat.O