The MODIFY Statement in Open SQL

What is the MODIFY Statement?

The MODIFY statement in Open SQL is used for inserting or updating entries in a database table. It has two primary functions:

  1. Insert: Adds a new line if no entry with the same primary key exists.
  2. Update: Modifies an existing line if an entry with the same primary key exists.

Syntax

The basic syntax is:

MODIFY <database table> FROM <work area>

How it Works

  • Inserting a New Line: A new line is inserted if the primary key in the work area is unique.
  • Updating an Existing Line: The existing line is overwritten if a matching primary key is found.
  • Return Code: SY-SUBRC is set to 0 post execution.

Example

Consider this ABAP code snippet:

DATA: gwa_employee TYPE zemployee.

gwa_employee-id      = 6.
gwa_employee-name    = 'JOSEPH'.
gwa_employee-place   = 'FRANKFURT'.
gwa_employee-phone   = '7897897890'.
gwa_employee-dept_id = 5.

MODIFY zemployee FROM gwa_employee.

In this example, the zemployee table is modified based on gwa_employee data.

Observations

  • When there was no entry with the key 6, a new entry was added.
  • Upon modifying the entry with key 6 again but with different data, the existing record was updated.