10-26-2007 10:38 AM
Hi,
I have 2 internal tables. for ex:
1st (header) table has A, B, C, D fields ( A and B are primary fields )
2nd (item) table has A, B, E, F, G fields
how to remove the entries from header table if the item records are not available in the item table?
ex: if header has
11, 12, 13, 14
21, 22, 23, 24
31, 32, 33, 34
and if item has
11 12 15 16 17
31 32 35 36 37
i have to remove the second rec from the header table ie. 21, 22, 23, 24
How to do this in easiest way? Kindly help out.
Regards,
Kalai
10-26-2007 10:42 AM
hi,
LOOP at itab1.
READ TABLE itab2
WITH KEY a = itab1-a
b = itab1-b.
IF sy-subrc NE 0.
DELETE itab1.
ENDIF.
ENDLOOP.
exact syntax depends on how the itabs are defined (i. e. with or without header line)
hope this helps
ec
10-26-2007 10:42 AM
Hi
LOOP AT T_HEADER.
READ TABLE T_ITEM WITH KEY A = T_HEADER-A
B = T_HEADER-B.
IF SY-SUBRC <> 0.
DELETE T_HEADER.
ENDIF.
ENDLOOP.
Max
10-26-2007 11:00 AM
Hi Max,
Thanks for ur reply.
But I am getting the compilation error as " key B is not expected".
What to do?
Regards,
Kalai
10-26-2007 11:07 AM
Hi
Check how you've defined your table, they should be:
DATA: BEGIN OF T_HEADER OCCURS 0,
A,
B,
............................
END OF T_HEADER.
DATA: BEGIN OF T_ITEM OCCURS 0,
A,
B,
............................
END OF T_ITEM.
So you should write a code like this:
LOOP AT T_HEADER.
READ TABLE T_ITEM WITH KEY A = T_HEADER-A
B = T_HEADER-B.
IF SY-SUBRC <> 0.
DELETE T_HEADER.
ENDIF.
ENDLOOP.
I'm getting any error
Max
10-26-2007 11:23 AM
Hi Max,
I have declared the itab using "standard table of" method.
so how can i do this now?
Regards,
Kalai
10-26-2007 11:34 AM
Hi
No it shouldn't be a problem; which release are you using?
Perhaps you've writen:
LOOP AT T_HEADER.
READ TABLE T_ITEM WITH KEY A = T_HEADER-A
KEY B = T_HEADER-B.
IF SY-SUBRC <> 0.
DELETE T_HEADER.
ENDIF.
ENDLOOP.
Instead of
LOOP AT T_HEADER.
READ TABLE T_ITEM WITH KEY A = T_HEADER-A
B = T_HEADER-B.
IF SY-SUBRC <> 0.
DELETE T_HEADER.
ENDIF.
ENDLOOP.
Perhaps it's better if you post the code where you've defined the table and do the READ statament
Max
10-26-2007 10:43 AM
hi,
i cant get your question exactly.
could you explain me in another way.
Thanks,
Senthil kumar
10-26-2007 10:48 AM
Hi
This is a pretty simply job.
Loop at gt_header into <wa_header>
Read gt_item into gwa_item with key a = gt_header-a
b = gt_header-b.
if sy-subrc <> 0.
Record is not present and hence delete from header
Delete gt_header.
Thanks
Vijay
<b>PLZ REWARD POINTS IF HELPFUL</b>