Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
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).

Summary

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

Introduction

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.

DATA: t_vbap TYPE STANDARD TABLE OF ty_vbap,
      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
       posnr
       matnr
       kwmeng
  FROM vbap
  INTO TABLE t_vbap
  UP TO 3000 ROWS.

IF t_vbap[] IS NOT INITIAL.
  lt_vbap[] = t_vbap[].
  SORT lt_vbap BY matnr.
  DELETE ADJACENT DUPLICATES FROM lt_vbap
                             COMPARING matnr.

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

ENDIF.


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
    ENDIF.
  ELSE.
    <fs_vbap>-kwmeng = 20.  "instead of modify statement we assign values directly to field symbols
  ENDIF.
ENDLOOP.

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

http://tcodes.ofsap.com/tcode.php?tcode=V-48

http://help.sap.com/saphelp_40b/helpdata/en/92/58b507417011d189ec0000e81ddfac/content.htm

http://www.se80.co.uk/sapfms/s/sd_k/sd_konp_select.htm

Useful Information

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



  • No labels