Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Open Sql Insert

Former Member
0 Kudos
1,211

Hi Friends!

Using insert can we use direct to insert record in database table its possibe whats the syntax.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
286

Hi

INSERT

... { {VALUES wa}

| {FROM wa|{TABLE itab [ACCEPTING DUPLICATE KEYS]}} }.

1. ... {VALUES wa} | {FROM wa} ...

2. ... FROM TABLE itab [ACCEPTING DUPLICATE KEYS] ...

After FROM and VALUES, you can specify a non-table-type data object wa. After FROM, you can also specify an internal table itab. The contents of the row(s) to be inserted are taken from these data objects

Reward points for useful Answers

Regards

Anji

7 REPLIES 7

Former Member
0 Kudos
287

Hi

INSERT

... { {VALUES wa}

| {FROM wa|{TABLE itab [ACCEPTING DUPLICATE KEYS]}} }.

1. ... {VALUES wa} | {FROM wa} ...

2. ... FROM TABLE itab [ACCEPTING DUPLICATE KEYS] ...

After FROM and VALUES, you can specify a non-table-type data object wa. After FROM, you can also specify an internal table itab. The contents of the row(s) to be inserted are taken from these data objects

Reward points for useful Answers

Regards

Anji

Former Member
0 Kudos
286

hi,

Yes it is possible.

Former Member
0 Kudos
286

Hi,

The Open SQL statement for inserting data into a database table is:

<b>INSERT INTO <target> <lines>.</b>

It allows you to insert one or more lines into the database table <target>. You can only insert lines into 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 <target> either statically or dynamically.

<b>Example Program</b>


TABLES SPFLI.

DATA WA TYPE SPFLI.

WA-CARRID = 'LH'.
WA-CITYFROM = 'WASHINGTON'.
...
INSERT INTO SPFLI VALUES WA.

WA-CARRID = 'UA'.
WA-CITYFROM = 'LONDON'.
...
INSERT SPFLI FROM WA.

SPFLI-CARRID = 'LH'.
SPFLI-CITYFROM = 'BERLIN'.
...
INSERT SPFLI.

Regards

Sudheer

sreeramkumar_madisetty
Active Contributor
0 Kudos
286

Hi Rahul

You can NOT use option accepting duplicate keys with wa.

Option accepting duplicate keys only work with table itab NOT wa.

INSERT dbtab FROM TABLE itab. or

INSERT (dbtabname) FROM TABLE itab.

Additions

... CLIENT SPECIFIED

... ACCEPTING DUPLICATE KEYS

Please try to build internal table.

data: begin of itab occurs 0.

include structure zcitorderout.

data: end of itab.

data: wa_zcitorderout like zcitorderout.

wa_zcitorderout-vbeln = nast-objky.

itab = wa_zcitorderout.

append itab.

insert zcitorderout from table itab accepting duplicate keys.

Regards,

Sree

Former Member
0 Kudos
286

former_member196280
Active Contributor
0 Kudos
286

Yes it is possible.

INSERT <Table name>.

But not advisable.

Regards,

SaiRam

Former Member
0 Kudos
286

Hi Rahul,

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.

Effect

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.

Notes

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 (with regard to this UNIQUE index).

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 Dictionary. Otherwise they are set to NULL.

Authorization checks (see The SAP Authorization Concept) are not supported by the INSERT statement. You must include these in the program yourself.

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).

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).

PS: please reward if useful..