sapdev logo background
sapdev logo sapdev logo
Comments

ABAP MODIFY statement command to modify date within database tables and internal tables




Change an internal table using the ABAP MODIFY statement command
Changing values within an internal table using MODIFY is a very powerfull yet simple process to perform. The code below demonstrates how you can populate an internal table and then change the value of a specific field within that internal table.

*&-----------------------------------------------------------*
*& Report  ZMODIFYITAB                                       *
*&                                                           *
*&-----------------------------------------------------------*
*& Example of Modifying an internal table value              *
*&                                                           *
*&-----------------------------------------------------------*
*&-Created By details----------------------------------------*
*&                                                           *
*& Author : www.sapdev.co.uk                                 *
*&  SAP ABAP development                                    *
*&-----------------------------------------------------------*
Report  ZMODIFYITAB.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
 END OF t_ekpo.

DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
      wa_ekpo TYPE t_ekpo.

**************************************************************
*Start-of-selection.
START-OF-SELECTION.

  select ebeln ebelp statu aedat matnr menge meins netpr peinh
   up to 10 rows
    from ekpo
    into table it_ekpo.

**************************************************************
*End-of-selection.
END-OF-SELECTION.

  loop at it_ekpo into wa_ekpo.
    wa_ekpo-netpr = '100'.
    MODIFY it_ekpo INDEX sy-tabix FROM wa_ekpo
         TRANSPORTING netpr.
  endloop.

Add/Change a row in internal table

You would not use the modify command to add an entry to an internal table, this would be done using the APPEND command. When updating an itab simply read the table first to check if an entry exists with required key and then MODIFY or APPEND based on the result:

READ it_ekpo into wa_ekpo with key ebeln = ld_ebeln.
if sy-subrc eq 0.
  MODIFY it_ekpo  from wa_ekpo index sy-tabix.
else.
  APPEND wa_ekpo to it_ekpo.
endif.

MODIFY a database table from a work area
The below abap code demonstrates how to add or update a SAP database table row with the contents of a work area (structure).

* Updates database table Zdtable with the contents of wa_itab
MODIFY Zdtable FROM wa_itab.

If you only want to update a single field within a database table you might want to use the UPDATE command instead.



MODIFY a database table from an internal table
The below abap code shows how to add or update a SAP database table row with the contents of a internal table.

* Updates database table Zdtable with the contents of it_itab
MODIFY Zdtable FROM TABLE it_itab.




comments powered by Disqus