Application Development and Automation 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: 
Read only

reports

Former Member
0 Likes
1,192

Hi all,

What is the difference between Append and Insert.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,173

Hi

Can I use insert statement to insert into internal table. or can i use insert instead of append

12 REPLIES 12
Read only

rahulkavuri
Active Contributor
0 Likes
1,173

INSERT statement inserts a single record into the database table.

Syntax

Tables: sflight.

Sflight-carrid = ‘LH’.

Sflight-connid = ‘234’.

Insert sflight.

Table sflight is inserted with the record. The SY_SUBRC is returned for this statement. If the entry already exists then the SY_SUBRC is set to non-zero value and you can do processing for existing record by giving some error message.

Both APPEND and INSERT add records..

As far as I know we generally use APPEND statement when we are adding lines to an Internal table...

Award points if found helpful

Read only

SantoshKallem
Active Contributor
0 Likes
1,173

Append command is used to insert a new record in to an internal table.

insert is used to update Table.

Read only

Former Member
0 Likes
1,173

Hi,

<b>Insert:</b>

INSERT [{<wa>|INITIAL LINE} INTO] <itab> [INDEX <idx>].

Inserts a new line into table. For tables with a header line the source area can be omitted. With INDEX option, the new line is inserted before the line which has the index <idx>. After the insertion, the new entry has the index <idx> and the index of the following lines is incremented by 1.

If the table consists of <idx> - 1 entries, the system appends the new entry after the last existing table line. If the table has less than <idx> - 1 entries, the system cannot insert the entry: SY-SUBRC = 4. If success, SY-SUBRC = 0.

Use INSERT without the INDEX option is allowed only within a LOOP - ENDLOOP loop by inserting the new entry before the current line (i.e. the line which has the index returned by SY-TABIX).

INSERT LINES OF <itab1> [FROM <idx1>] [TO <idx2>] INTO <itab2> [INDEX <idx>].

Inserts lines from one table into another table. Default inserts entire table. Can be up to 20 times faster than inserting lines line by line in a loop.

<b>

Appending Lines:</b>

APPEND [{<wa>|INITIAL LINE} TO] <itab>.

Appends a new line to table. For tables with a header line the source area can be omitted. After statement, the SY-TABIX contains the index of the appended line.

APPEND LINES OF <itab1> [FROM <idx1>] [TO <idx2>] TO <itab2>.

Appends lines from one table to another table. Default appends entire table. After statement, the SY-TABIX contains the index of the last appended line. About 3 to 4 times faster than appending lines line by line in a loop.

APPEND [<wa> TO] <itab> SORTED BY <f>.

Inserts the new line so that the internal table <itab> is sorted in descending order by the field <f>. If you use the SORTED BY option, the table can contain only the number of lines specified in the OCCURS parameter. If you add more lines than specified, the last line is discarded. This is useful for creating ranked lists of limited length (e.g. "Top Ten"). For ranked lists containing more than 100 entries, use instead the SORT for performance reasons.

Read only

0 Likes
1,173

I didnt get u

Read only

Former Member
0 Likes
1,174

Hi

Can I use insert statement to insert into internal table. or can i use insert instead of append

Read only

0 Likes
1,173

Yes, you can use the INSERT statement to insert into internal table. Say that you want to insert a record into the second row of the table. You could use INDEX here.

insert itab index 2.

Regards,

Rich Heilman

Read only

0 Likes
1,173

Hi,

Thanks for the answer. I have some more doubt.

If I use append where will the value be stored in header or the body. and what about insert.If I just use

Insert itab.

will it be inserted in the first index. then if I use the same statement the second time what will happen to the first value

Read only

Former Member
0 Likes
1,173

Hello

Read only

0 Likes
1,173

Thanks for the answer. I have some more doubt.

If I use append where will the value be stored in header or the body. and what about insert.If I just use

Insert itab.

will it be inserted in the first index. then if I use the same statement the second time what will happen to the first value

Read only

SantoshKallem
Active Contributor
0 Likes
1,173

it stores from header to body

insert itab.

will it be inserted in the first index. then if I use the same statement the second time what will happen to the first value

here it increases the index.

index is used to place the record in specific location.

Read only

0 Likes
1,173

thanx dude.....

Read only

SantoshKallem
Active Contributor
0 Likes
1,173

select statement retrive the record and places in header.

append statement moves the record from header to body.