10-17-2007 4:09 AM
Hi all
I had syntax error in my insert. Below is my requirement for the insert statement.
i gt three input fields.
first input -
> user enter a column of the table to be insert
second input -
> user enter the tablename
third input -
> user enter a value to be insert.
my code
INSERT INTO (second input)
(first input)
VALUES
(third input)
i gt error syntax
10-17-2007 4:11 AM
Hi Gary,
You got wrong syntax of INSERT.
Just do F1 on INSERT and you will get its correct syntax and how to use.
Regards,
Atish
10-17-2007 4:11 AM
Check the syntax of INSERT command. Make your code change accordingly.
INSERT - Insert in a database table
Variants:
INSERT INTO dbtab [CLIENT SPECIFIED] VALUES wa. INSERT INTO (dbtabname) [CLIENT SPECIFIED] VALUES wa.
INSERT INTO (dbtabname) VALUES wa.
INSERT dbtab [CLIENT SPECIFIED] FROM TABLE itab. oder INSERT (dbtabname) [CLIENT SPECIFIED] FROM TABLE itab.
INSERT (dbtabname) ...
INSERT dbtab [CLIENT SPECIFIED]. oder INSERT *dbtab [CLIENT SPECIFIED]. oder
INSERT (dbtabname) [CLIENT SPECIFIED] ... .
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. 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".
By default, data are inserted only in the current client. If you use CLIENT SPECIFIED, automatic client handling is switched off. This allows you to insert data across all clients even when dealing withclient-specific 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.
INSERT belongs to the Open SQL command set.
Notes
1. 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.
2. When inserting lines using a view, all fields of the
database table that are not in the view are set to their initial value
(see TABLES) - if they were defined with NOT NULL in the ABAP/4 Dictionary. Otherwise they are set to NULL.
3. Authorization checks (see The SAP Authorization Concept) are not supported by the INSERT statement. You must include these in the program yourself.
4. Lines specified with the INSERT command are not finally added to the database table until after a database commit (see Logical Unit of Work (LUW)). Prior to this, you can cancel any changes to the database with a database rollback (see Programming Transactions.
5. In the dialog system, you cannot rely on the locking mechanism used by the database system (see Database Locking) to synchronize simultaneous access to the same database by several users. Therefore, it is often necessary to use SAP's locking mechanism (see SAP Locking).
Variant 1
INSERT INTO dbtab [CLIENT SPECIFIED] VALUES wa. or
INSERT INTO (dbtabname) [CLIENT SPECIFIED] VALUES wa.
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 (see TABLES). 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 SY-DBCNT contains the number of inserted lines (0 or 1).
The Return code 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
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.
Variant 2
INSERT dbtab [CLIENT SPECIFIED]. or
INSERT *dbtab [CLIENT SPECIFIED]. or
INSERT (dbtabname) [CLIENT SPECIFIED] ...
Addition:
... FROM wa
See Cannot Use Short Forms und
Cannot Use *Work Areas.
Effect
These are the SAP-specific short forms for the statements explained under variant 1.
INSERT INTO dbtab VALUES dbtab. or
INSERT INTO dbtab VALUES *dbtab. or
INSERT INTO (dbtabname) VALUES wa.
If you declare the name of the database table directly, the program must contain an appropriate TABLES statement.
If the name of the databse table is determined at runtime, you have to specifiy the addition ...FROM wa. 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:
SY-SUBRC = 0:
Line successfully inserted.
SY-SUBRC = 4:
Line could not be inserted, since a line with the same key already exists.
Example
Add a line to a database table:
TABLES SAIRPORT.
SAIRPORT-ID = 'NEW'.
SAIRPORT-NAME = 'NEWPORT APT'.
INSERT SAIRPORT.
Addition
... FROM wa
Effect
The values for the line to be inserted are not taken from the table work area dbtab, but from the explicitly specified work area wa. The work area wa must also satisfy the conditions described in variant 1. As with this variant, the addition allows you to specify the name of the database table directly or indirectly.
Note
If a work area is not explicitly specified, the values for the line to be inserted are taken from the table work area dbtab if the statement is in a FORM or FUNCTION where the table work area is stored in a formal parameter or local variable of the same name.
Variant 3
INSERT dbtab FROM TABLE itab. or
INSERT (dbtabname) [CLIENT SPECIFIED] FROM TABLE itab.
Addition:
... ACCEPTING DUPLICATE KEYS
Effect
Mass insert: Inserts all lines of the internal table itab in a single operation. The lines of itab must satisfy 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:
SY-SUBRC = 0:
All lines successfully inserted. Any other result causes a runtime error.
Note
If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0 after the call.
Addition
... ACCEPTING DUPLICATE KEYS
Effect
If a line cannot be inserted, the processing does not terminate with a runtime error, but the return code of SY-SUBRC is merely set to 4. All the remaining lines are inserted when the command is executed.
ashish
10-17-2007 4:20 AM
Hi,
insert into a Particualr column is not Possible.
so you can first append it to a work area and then into the table using insert statement.
regards
Gururaj