Wednesday, June 10, 2009

Inserting or Changing Lines

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 .

If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like INSERT, 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 cannot distinguish between these two options in your ABAP program.

You can add or change one or more lines in a database table . You can only insert or change lines in an ABAP Dictionary view if it only contains fields from one table, and its maintenance status is defined as Read and change. You may specify the database table either statically or dynamically.

Specifying a Database Table

To specify the database table statically, enter the following for :

MODIFY [CLIENT SPECIFIED] .

where is the name of a database table defined in the ABAP Dictionary.

To specify the database table dynamically, enter the following for :

MODIFY () [CLIENT SPECIFIED] .

where the field contains the name of a database table defined in the ABAP Dictionary.

You can use the CLIENT SPECIFIED addition to disable automatic client handling.

Inserting or Changing Single Lines

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

MODIFY FROM .

The contents of the work area are written to the database table . The work area 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. SY-SUBRC is always set to 0.

A shortened form of the above statement is:

MODIFY .

In this case, the contents of the table work area are inserted into the database table with the same name. You must declare this table work area using the TABLES statement. 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:

MODIFY FROM TABLE .

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

SY-SUBRC is always set to 0. SY-DBCNT is set to the number of lines in the internal table.

Leaving content frame

No comments:

Blog Archive