1. INSERT
INTO dbtab VALUES wa.
oder
INSERT INTO (dbtabname) VALUES wa. oder
INSERT dbtab FROM
wa. oder
INSERT (dbtabname) FROM wa.
2. INSERT dbtab FROM
TABLE itab. oder
INSERT (dbtabname) FROM TABLE itab.
3.
INSERT dbtab. oder
INSERT *dbtab.
Inserts new lines in a database table (see relational
database). 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 variable dbtabname. In both cases, the database table must be defined in the
ABAP Dictionary. By default, data is only inserted 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 Dictionary with the maintenance status "No restriction".
INSERT belongs to the Open SQL command set.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs.See Open SQL and Unicode.
INSERT INTO dbtab VALUES wa.
or
INSERT INTO (dbtabname) VALUES wa. or
INSERT dbtab FROM
wa. or
INSERT (dbtabname) FROM wa.
1. ... CLIENT
SPECIFIED
2. ... CONNECTION con
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
line structure of the database table 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 line structure
of dbtab, and the alignment
of the work area wa must correspond to the alignment of
the line structure. Otherwise, a runtime error occurs.
If the database table
dbtab or the work area wa
contain strings, wa
must be compatible with the line structure of dbtab.
When the command has been executed, the system field SY-DBCNT contains the number of inserted lines (0 or 1).
The Return Code is set as follows:
Insert the customer Robinson in the current client:
DATA: wa TYPE scustom.
wa-id = '12400177'.
wa-name =
'Robinson'.
wa-postcode = '69542'.
wa-city = 'Heidelberg'.
wa-custtype = 'P'.
wa-discount = '003'.
wa-telephone = '06201/44889'.
INSERT INTO scustom VALUES wa.
... CLIENT SPECIFIED
Automatic client handling is switched off. This allows
you to process data on a cross-client
basis for client-specific tables. The client field is then treated like a normal table field which the
program must fill with values in the work area wa.
The addition CLIENT SPECIFIED must be specified directly after the name of the database table.
Insert the customer Robinson in client 2:
DATA: wa TYPE scustom.
wa-mandt = '002'.
wa-id =
'12400177'.
wa-name = 'Robinson'.
wa-postcode =
'69542'.
wa-city = 'Heidelberg'.
wa-custtype =
'P'.
wa-discount = '003'.
wa-telephone = '06201/44889'.
INSERT scustom CLIENT SPECIFIED FROM wa.
... CONNECTION con
The Open SQL command is not executed on the
standard database, but on the secondary
database connection
specified with con. con
is the name of the databse connection as it was specified in the table DBCON
in the column
CON_NAME. The database connection con can also
be specified dynamically in the form (source_text), where
the field source_text contains the name of the database
connection and must be type
C or STRING.
The CONNECTION con addition must be specified directly
after the name of the database table or after the CLIENT SPECIFIED addition.
INSERT dbtab FROM TABLE
itab. oder
INSERT (dbtabname) FROM TABLE itab.
1. ... CLIENT
SPECIFIED
2. ...
ACCEPTING DUPLICATE KEYS
3. ... CONNECTION con
Mass insert: All lines of the internal table itab are
inserted in one single operation. The lines of itab must
fulfill the same conditions as the work area wa in variant
1.
When the command has been executed, the system field SY-DBCNT
contains the number of inserted lines.
The Return Code is set as follows:
If the internal table
itab is empty, SY-SUBRC and SY-DBCNT are set to 0 after the call.
... CLIENT SPECIFIED
As with variant 1.
... ACCEPTING DUPLICATE KEYS
If a line cannot be inserted, the system does not
terminate with a runtime
error but only sets the return value SY-SUBRC to 4. All other lines are inserted after the command is executed.
... CONNECTION con
As with variant 1.
INSERT dbtab. or
INSERT *dbtab.
1. ... CLIENT
SPECIFIED
2. ... CONNECTION con
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.
See
Cannot Use Short Forms and Cannot Use * Work Areas.
This variant is obsolete.
These are the SAP-specific short forms of variant 1. They have the same effect as variant 1, but the
work area is not specified explicitly. Instead, the system implicitly uses the table work area
dbtab or *dbtab
declared using a TABLES statement.
is equivalent to
When the command has been executed, the system field SY-DBCNT contains the number of lines inserted (0 or 1).
The Return Code is set as follows:
Add a line to a database table:
TABLES sairport.
sairport-id = 'NEW'.
sairport-name = 'NEWPORT APT'.
INSERT sairport.
... CLIENT SPECIFIED
As with variant 1.
... CONNECTION con
As with variant 1.
Inserting Lines in Tables