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

Internal table

Former Member
0 Likes
460

Hi,

I want to delete some reocrds from the internal table where for a particular field there is not data.


SORT i_mara BY matnr.
  LOOP AT i_final1 INTO is_final1.

    READ TABLE i_mara INTO is_mara WITH KEY
               matnr = is_final1-matnr BINARY SEARCH.
    IF sy-subrc EQ 0.
      CLEAR is_final1.

      MOVE is_mara-normt TO is_final1-normt.

      MODIFY i_final1 FROM is_final1 TRANSPORTING normt.

    ENDIF.

  ENDLOOP.

Say before entering the loop i have 3 records in the internal table i_final1.

After the loop is processed i will still have 3 records but the field normt is filled in only one record.

I want to delete the those records for which the field normrt is empty.

can I do that in the same loop or do I have to write one more loop

Can any one help me regarding this

1 ACCEPTED SOLUTION
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
437

Hi,

You just write this st. after the loop.

delete i_final where normrt = space.

KIndly reward points if it helps.

4 REPLIES 4
Read only

Former Member
0 Likes
437

Hi Hema,

You can do it in the same loop as follows,

SORT i_mara BY matnr.

LOOP AT i_final1 INTO is_final1.

READ TABLE i_mara INTO is_mara WITH KEY

matnr = is_final1-matnr BINARY SEARCH.

IF sy-subrc EQ 0.

<b> IF is_mara-normt IS INITIAL.

DELETE i_final1.

CONTINUE.

ENDIF.</b>

CLEAR is_final1.

MOVE is_mara-normt TO is_final1-normt.

MODIFY i_final1 FROM is_final1 TRANSPORTING normt.

<b>ELSE.

DELETE i_final1.</b>

ENDIF.

ENDLOOP.

Hope this helps..

Sri

Read only

Former Member
0 Likes
437

Hi,

Check this ...

instead of that you can do this way..

delete i_final1 where normrt = ' '.

Regards

vijay

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
438

Hi,

You just write this st. after the loop.

delete i_final where normrt = space.

KIndly reward points if it helps.

Read only

Former Member
0 Likes
437

Hi Hema,

1. U want to delete record from internal table

( IN A LOOP)

2. Simply using

IF is_mara-normt IS INITIAL.

and DELETE

will do your work

3. BUT,

U MAY FACE PROBLEM BCOS OF LOOP.

(IN BETWEEN RECORDS ARE DELETED)

4. Hence, i suggest the following :

(i had also faced similar problem,

hence, this is one good approach

for such delete record problems)

*----


5. In your internal table,

declare one EXTRA Field (say FLAG)

type c.

6. Loop at your logic,

and if

IF is_mara-normt IS INITIAL

Mark FLAG = 'X'.

and modify the internal table.

6. Let the loop ENDLOOP.

*----


7. After this,

Loop at ITAB.

If itab-flag = 'X'.

DELETE ITAB.

ENDIF.

ENDLOOP.

8. Whenever we have to apply logic

for deleting records in internal table(in a loop)

, always follow this FLAG concept.

regards,

amit m.