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

@Inserting Records in an Internal Table

Former Member
0 Likes
3,895

Hi,

How can I Insert records in an internal table..such that i can insert the records somewhere in the middle based on the entry in a field?

Hi,

How can I Insert records in an internal table..such that i can insert the records somewhere in the middle based on the entry in a field?

5 REPLIES 5
Read only

Former Member
0 Likes
2,278

INSERT wa INTO TABLE itab INDEX idx .

Effect

This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.

If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.

An exception that cannot be handled is raised when:

idx contains a value less than or equal to 0

A line to be inserted would cause a duplicate entry in tables with a unique table key

A line to be inserted would disrupt the sort order of sorted tables

Within a LOOP loop, you can omit the addition INDEX. Each line to be inserted is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.

Read only

Former Member
0 Likes
2,278

itab-field = <value1>.

insert itab index 1.

itab-field = <value2>.

insert itab index 2.

Read only

Former Member
0 Likes
2,278

Hi,

Hav a look at this.

Insert into an internal table

- INSERT [wa INTO|INITIAL LINE INTO] itab [INDEX idx] [ASSIGNING <fs>|REFERENCE INTO dref].

- INSERT [wa INTO|INITIAL LINE INTO] TABLE itab [ASSIGNING <fs>|REFERENCE INTO dref].

- INSERT LINES OF itab1 [FROM idx1] [TO idx2] INTO itab2 [INDEX idx3].

- INSERT LINES OF itab1 [FROM idx1] [TO idx2] INTO TABLE itab2.

Regards,

Ramkumar.K

Read only

Former Member
0 Likes
2,278

Hi,

Check this out.

Have the record which you want in a work area say "wa".

Now say, you want to append the record after you encounter a particular value "V" in a field say F

data: variable type sy-tabix.

Loop at itab.

if F = V.

variable = sy-tabix.

endif.

endloop.

sy-tabix = variable + 1.

insert wa to itab.

Reward if helpful.

Regards.

Read only

Former Member
0 Likes
2,278

Hi Rama Swamy.......

INSERT WA INTO TABLE IT_VBAK INDEX i .

like that...............

use this syntax ..to insert the record in between the existing records..............