Entering content frame

Inserting or Changing Lines Locate the document in its SAP Library structure

To insert lines into a database table regardless of whether there is already a line in the table with the same primary key, use the following:

MODIFY target lines.

If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like IINSERT - that is, the line is added.

If the database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE - that is, the line is changed.

For performance reasons, you should use MODIFY only if you really cannot distinguish between these two options in your program.

You can add or change one or more lines lines  in a database table target. As described in the section Inserting Table Lines, the database table target can be specified statically and dynamically.

Inserting or Changing Single Lines

To insert or change a single line in a database table, use the following for lines:

MODIFY target FROM wa.

The contents of the work area wa are written to the database table dbtab. The work area wa must be a data object with at least the same length and alignment as the line structure of the database table. The data is placed in the database table according to the line structure of the table, and regardless of the structure of the work area. It is a good idea to define the work area with reference to the structure of the database table.

If the database table does not already contain a line with the same primary key as specified in the work area, a new line is inserted. If the database table does already contain a line with the same primary key as specified in the work area, the existing line is overwritten. If the line could not be processed – for example, because a line with the same unique secondary index exists in the database – sy-subrc is set to 4, otherwise to 0

A shortened form of the above statement is:

MODIFY dbtab.

In this case, the contents of the table work area dbtab are inserted into the database table with the same name. You must declare this table work area using the TABLESstatement. In this case, it is not possible to specify the name of the database table dynamically. Table work areas with the same name as the database table (necessary before Release 4.0) should no longer be used for the sake of clarity.

Inserting or Changing Several Lines

To insert or change several lines in a database table, use the following for lines:

MODIFY target FROM TABLE itab.

Those lines of the internal table itab for which there is not already a primary key in the database table are inserted into the table. Those lines of the internal table itab for which there is already a primary key in the database table overwrite the existing line there. The same rules apply to the line type of itab as to the work area wa described above.

If the line could not be processed – for example, because a line with the same unique secondary index exists in the database – sy-subrc is set to 4, otherwise to 0. sy-dbcnt is set to the number of changed lines.

 

 

Leaving content frame