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:Β 

Regarding Insert statement

Former Member
0 Kudos
102

Hi

Can you please tell me what is the wrong in below INSERT satement.

Its giving as "FAILED".

data : It_vbrp type standard table of vbrp with header line,

it_vbak type standard table of vbak with header line,

it_vbap type standard table of vbap with header line,

wa_vbak type vbak,

wa_vbap type vbap.

wa_vbak-vbeln = '0090005178'.

insert into vbak values wa_vbak.

if sy-subrc ne 0.

write : 'failed'.

else.

write πŸ˜• 'success'.

endif.

Regards

Sandeep Reddy

1 ACCEPTED SOLUTION

Former Member
0 Kudos
61

Hi,

INSERT for Database Tables

Inserts entries from database tables.

Syntax

INSERT <dbtab> FROM <wa>.

INSERT <dbtab> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS].

Inserts one line from the work area <wa> or several lines from the internal table <itab> into the database table <dbtab>. The ACCEPTING DUPLICATE KEYS addition prevents a runtime error from occurring if two entries have the same primary key. Instead, it merely discards the duplicate

INSERT for Field Groups

Defines the structure of field groups for extract datasets.

Syntax

INSERT <f1>... <f n> INTO <fg>.

Includes the fields <fi> in the field group <fg>, thus defining a line structure for an extract dataset.

INSERT for any Internal Table

Inserts lines from internal tables of any type.

Syntax

INSERT <line>|LINES OF <jtab> [FROM <n1>] [TO <n 2>]

INTO TABLE <itab>

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Inserts a line <line> or a set of lines from the internal table <jtab> into the internal table <itab>. If <jtab> is an index table, you can use the FROM and TO additions to restrict the lines inserted. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the inserted line or the relevant data reference is stored in <dref> after the statement.

INSERT for Index Tables

Inserts entries in index tables.

Syntax

INSERT <line>|LINES OF <jtab> [FROM <n1>] [TO <n 2>]

INTO <itab> [INDEX <idx>]

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Inserts a line <line> or a set of lines from the internal table <jtab> into the internal table <itab>before the line with the index <idx>. If <jtab> is an index table, you can use the FROM and TO additions to restrict the lines inserted. If you omit the INDEX addition, you can only use the statement within a LOOP. A new line containing values is inserted before the current line. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the inserted line or the relevant data reference is stored in <dref> after the statement.

Regards,

Priya.

5 REPLIES 5

Former Member
0 Kudos
62

Hi,

INSERT for Database Tables

Inserts entries from database tables.

Syntax

INSERT <dbtab> FROM <wa>.

INSERT <dbtab> FROM TABLE <itab> [ACCEPTING DUPLICATE KEYS].

Inserts one line from the work area <wa> or several lines from the internal table <itab> into the database table <dbtab>. The ACCEPTING DUPLICATE KEYS addition prevents a runtime error from occurring if two entries have the same primary key. Instead, it merely discards the duplicate

INSERT for Field Groups

Defines the structure of field groups for extract datasets.

Syntax

INSERT <f1>... <f n> INTO <fg>.

Includes the fields <fi> in the field group <fg>, thus defining a line structure for an extract dataset.

INSERT for any Internal Table

Inserts lines from internal tables of any type.

Syntax

INSERT <line>|LINES OF <jtab> [FROM <n1>] [TO <n 2>]

INTO TABLE <itab>

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Inserts a line <line> or a set of lines from the internal table <jtab> into the internal table <itab>. If <jtab> is an index table, you can use the FROM and TO additions to restrict the lines inserted. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the inserted line or the relevant data reference is stored in <dref> after the statement.

INSERT for Index Tables

Inserts entries in index tables.

Syntax

INSERT <line>|LINES OF <jtab> [FROM <n1>] [TO <n 2>]

INTO <itab> [INDEX <idx>]

[ASSIGNING <FS> | REFERENCE INTO <dref>].

Inserts a line <line> or a set of lines from the internal table <jtab> into the internal table <itab>before the line with the index <idx>. If <jtab> is an index table, you can use the FROM and TO additions to restrict the lines inserted. If you omit the INDEX addition, you can only use the statement within a LOOP. A new line containing values is inserted before the current line. If you use ASSIGNING or INTO REFERENCE, field symbol <FS> refers to the inserted line or the relevant data reference is stored in <dref> after the statement.

Regards,

Priya.

Former Member
0 Kudos
61

hi check example ,

DATA: int TYPE i,

dref TYPE REF TO i.

DATA: int_tab LIKE STANDARD TABLE OF int,

ref_tab LIKE HASHED TABLE OF dref

WITH UNIQUE KEY table_line.

DO 10 TIMES.

INSERT sy-index

INTO int_tab INDEX 1

REFERENCE INTO dref.

INSERT dref

INTO TABLE ref_tab.

ENDDO.

LOOP AT int_tab INTO int.

WRITE / int.

ENDLOOP.

SKIP.

LOOP AT ref_tab INTO dref.

WRITE / dref->*.

ENDLOOP.

regards,

venkat.

Former Member
0 Kudos
61

Hi ,

In the work area you are using to insert data into the table assign the value of the client i.e the field MANDT .

Once you assign the value to client your statement must work:

Regards

Arun

vinod_vemuru2
Active Contributor
0 Kudos
61

Hi,

Please check your VBAK table whether an entry already exist with this number. If no then it should work perfectly. If yes then we cant insert data into any table with same key. Also specification of Clint field is optional.

thanks,

Vinod.

Former Member
0 Kudos
61

Hi

do like this u will get the output

data : It_vbrp type standard table of vbrp with header line,

it_vbak type standard table of vbak with header line,

it_vbap type standard table of vbap with header line,

wa_vbak type vbak,

wa_vbap type vbap.

wa_vbak-vbeln = '0090005178'.

INSERT INTO vbak CLIENT SPECIFIED values wa_vbak .

if sy-subrc ne 0.

write : 'failed'.

else.

write πŸ˜• 'success'.

endif.

note: dont insert the same record.it will give failed message.

To specify the database table statically, enter the following for <target>:

INSERT INTO <dbtab> [CLIENT SPECIFIED] <lines>.

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

To specify the database table dynamically, enter the following for <target>:

INSERT INTO (<name>) [CLIENT SPECIFIED] <lines>.

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

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

Edited by: Jyothsna M on Feb 29, 2008 12:07 PM