Application Development 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: 

how to delete an entry from..

Former Member
0 Kudos

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

8 REPLIES 8

JozsefSzikszai
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Hi Max,

Thanks for ur reply.

But I am getting the compilation error as " key B is not expected".

What to do?

Regards,

Kalai

0 Kudos

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

0 Kudos

Hi Max,

I have declared the itab using "standard table of" method.

so how can i do this now?

Regards,

Kalai

0 Kudos

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

Former Member
0 Kudos

hi,

i cant get your question exactly.

could you explain me in another way.

Thanks,

Senthil kumar

Former Member
0 Kudos

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>