Syntax for Insert in data base table

Variants

1. INSERT INTO dbtab VALUES wa. or INSERT INTO (dbtabname) VALUES wa.

2. INSERT dbtab. or INSERT *dbtab. or INSERT (dbtabname) ...

3. INSERT dbtab FROM TABLE itab. or INSERT (dbtabname) FROM TABLE itab.

Effect

Inserts new lines in a database table .

You can specify the name of the database table either in the program itself in the form dbtab or at runtime as the contents of the field dbtabname . In both cases, the database table must be defined in the ABAP/4 Dictionary . If the program contains the name of the database table, it must also include a corresponding TABLES statement.

Normally, lines are inserted only in the current client. Data can only be inserted using a view if the view refers to a single table and was defined in the ABAP/4 Dictionary with the maintenance status "No restriction".

INSERT belongs to the Open SQL command set.

You cannot insert a line if a line with the same primary key already exists or if a UNIQUE index already has a line with identical key field values.

When inserting lines using a view , all fields of the database table that are not in the view are set to their initial value - if they were defined with NOT NULL in the ABAP/4 Dictionary . Otherwise they are set to NULL .

Since the INSERT statement does not perform authorization checks , you must program these yourself.

Lines specified in the INSERT command are not actually added to the database table until after the next ROLLBACK WORK .Lines added within a transaction remain locked until the transaction has finished. The end of a transaction is either a COMMIT WORK , where all database changes performed within the transaction are made irrevocable, or a ROLLBACK WORK , which cancels all database changes performed within the transaction.

Variant 1

INSERT INTO dbtab VALUES wa. or INSERT INTO (dbtabname) VALUES wa.

Addition

... CLIENT SPECIFIED

Effect

Inserts one line into a database table.

The line to be inserted is taken from the work area wa and the data read from left to right according to the structure of the table work area dbtab . Here, the structure of wa is not taken into account. For this reason, the work area wa must be at least as wide (see DATA ) as the table
work area dbtab and the alignment of the work area wa must correspond to the alignment of the table work area.

Otherwise, a runtime error occurs. When the command has been executed, the system field SYDBCNT contains the number of inserted lines (0 or 1).

The return code value is set as follows:

SY-SUBRC = 0 Line was successfully inserted.

SY_SUBRC = 4 Line could not be inserted since a line with the same key already exists.

Example

Insert the customer Robinson in the current client:

TABLES SCUSTOM.
SCUSTOM-ID = '12400177'.
SCUSTOM-NAME = 'Robinson'.
SCUSTOM-POSTCODE = '69542'.
SCUSTOM-CITY = 'Heidelberg'.
SCUSTOM-CUSTTYPE = 'P'.
SCUSTOM-DISCOUNT = '003'.
SCUSTOM-TELEPHONE = '06201/44889'.
INSERT INTO SCUSTOM VALUES SCUSTOM.

Addition

... CLIENT SPECIFIED

Effect

Switches off automatic client handling. This allows you to insert data across all clients even when dealing with clientspecific tables. The client field is then treated like a normal table field which you can program to accept values in the work area wa that contains the line to be inserted.

The addition CLIENT SPECIFIED must be specified immediately after the name of the database table.

Example

Insert the customer Robinson in client 2:

TABLES SCUSTOM.
SCUSTOM-MANDT = '002'.
SCUSTOM-ID = '12400177'.
SCUSTOM-NAME = 'Robinson'.
SCUSTOM-POSTCODE = '69542'.
SCUSTOM-CITY = 'Heidelberg'.
SCUSTOM-CUSTTYPE = 'P'.
SCUSTOM-DISCOUNT = '003'.
SCUSTOM-TELEPHONE = '06201/44889'.
INSERT INTO SCUSTOM CLIENT SPECIFIED VALUES
SCUSTOM.

1 comment :