What is Insert Statement
To insert a single row into an internal table, use the insert statement.
Syntax for the insert Statement
The following is the syntax for the insert statement.
insert [wa into] it [index n]
where:
- wa is a work area with the same structure as a row of internal table it.
- n is a numeric literal, variable, or constant.
The following points apply:
- If wa is specified, the contents of wa are inserted into it. wa must have the same structure as it.
- If wa is not specified, the contents of the header line are inserted into it. If it does not have a header line, wa must be specified.
- If index is specified, the new row is inserted before row n. Row n then becomes row n+1.
- The insert statement can be used inside or outside of loop at it. If it is outside, the index addition must be specified. If it is inside, index is optional. If it is not specified, the current row is assumed.
Listing 1 contains a sample program that uses the insert statement.
Listing 1 Use the insert Statement to Insert a Single Row into an Internal Table
1 report ztx1204. 2 data: begin of it occurs 5, 3 f1 like sy-index, 4 end of it. 5 6 do 5 times. 7 it-f1 = sy-index. 8 append it. 9 enddo. 10 11 it-f1 = -99. 12 insert it index 3. 13 14 loop at it. 15 write / it-f1. 16 endloop. 17 18 loop at it where f1 >= 4. 19 it-f1 = -88. 20 insert it. 21 endloop. 22 23 skip. 24 loop at it. 25 write / it-f1. 26 endloop.
The code in Listing 1 produces this output:
1
2
99-
3
4
5
1
2
99-
3
88-
4
88-
5
Popularity: 6% [?]






