Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Applies to:

SAP ECC 6.0 (Release 700, SP 12).


This article explains how to avoid modify and delete statements inside loop...end loop statements using field symbols. 

Author(s):  Rahul Babukuttan

Company:     Applexus Technologies (P) Ltd.
Created on:  11 January 2012
Author(s) Bio

Rahul Babukuttan, Applexus Technologies (P) Ltd.
B.Tech Computer Science Graduate, working as SAP Technology Consultant

Table of Contents


In order to modify/delete records of internal tables we use modify/delete inside loop...end loop statements in ABAP.  This may lead to serious performance issues if the internal table we use is very large. We can simply move these modify/delete statements outside the loop..end loop statements thus optimizing the performance. We can achieve this by the use of field symbols.

How we can achieve this?

For modify:

Step 1: We loop the internal table into field symbol, any assignment to the field symbol will modify the data directly without modify statement. Thus minimizing the use of "MODIFY" statement

For deletion:

Step 1: We need to modify the internal table type by adding one field named deletion indicator at the end of the type declaration.

Step 2: We check for specific condition inside the loop..end loop statement and the deletion indicator is set which satisfies our required condition

Step 3: Outside the loop..end loop, we write the delete statement by adding the condition DELETE itab WHERE deletion indicator eq 'X'.

Case Study

Given below is the abap coding done to delete all records from internal table T_VBAP for all materials which is marked for deletion (LVORM field) in the MARA internal table T_MARA.

//This is a code sample block

TYPES: BEGIN OF ty_vbap,
        vbeln TYPE  vbeln_va,
        posnr TYPE  posnr_va,
        matnr  TYPE matnr,
        kwmeng TYPE  kwmeng,
        del_indicator TYPE char01, "Deletion marker
       END OF ty_vbap,

       BEGIN OF ty_mara,
         matnr TYPE matnr,
         lvorm TYPE lvorm,
       END OF ty_mara.

      lt_vbap TYPE STANDARD TABLE OF ty_vbap,
      t_mara TYPE STANDARD TABLE OF ty_mara.

FIELD-SYMBOLS: <fs_vbap> TYPE ty_vbap.

SELECT vbeln
  FROM vbap
  INTO TABLE t_vbap
  UP TO 3000 ROWS.

  lt_vbap[] = t_vbap[].
  SORT lt_vbap BY matnr.
                             COMPARING matnr.

  SELECT matnr lvorm
    FROM mara
    INTO TABLE t_mara
    FOR ALL ENTRIES IN lt_vbap
    WHERE matnr EQ lt_vbap-matnr.


LOOP AT t_vbap ASSIGNING <fs_vbap>.
  IF <fs_vbap>-matnr CS 'abcd'.
    READ TABLE t_mara WITH KEY matnr = <fs_vbap>-matnr
                               lvorm = 'X'
                      TRANSPORTING NO FIELDS.
    IF sy-subrc EQ 0.
      <fs_vbap>-del_indicator = 'X'. "mark for deletion
    <fs_vbap>-kwmeng = 20.  "instead of modify statement we assign values directly to field symbols

DELETE t_vbap WHERE del_indicator  EQ 'X'.

In the code above, instead of using a modify statement inside the loop..end loop statement we assign the field symbol <fs_vbap> and make changes to the field of the field symbol which reflects to the values directly.

Note: Instead of putting the delete statement inside the loop..end loop statement, we mark the records which needs to be deleted based on the particular condition and do the deletion outside the loop.

Related Content

Useful Information

Short quick summary to catch the reader's attention and of course the search engine

  • No labels