Syntax to insert a line to internal table
INSERT <work area> INTO TABLE <internal table>. OR INSERT <work area> INTO <internal table> INDEX <index>.
The first INSERT statement without INDEX addition will simply add the record to the end of the internal table. But if we want to insert the line to specific location i.e. if we want to insert it as second record then we need to specify 2 as the index in the INSERT statement.
*--------------------------------------------------------------* *Data Types *--------------------------------------------------------------* TYPES: BEGIN OF ty_student, id(5) TYPE n, name(10) TYPE c, END OF ty_student. *--------------------------------------------------------------* *Data Declaration *--------------------------------------------------------------* DATA: gwa_student TYPE ty_student. DATA: it TYPE TABLE OF ty_student. gwa_student-id = 1. gwa_student-name = 'JOHN'. INSERT gwa_student INTO TABLE it. gwa_student-id = 2. gwa_student-name = 'JIM'. INSERT gwa_student INTO TABLE it. gwa_student-id = 3. gwa_student-name = 'JACK'. INSERT gwa_student INTO TABLE it. WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5. LOOP AT it INTO gwa_student. WRITE:/ gwa_student-id, gwa_student-name. ENDLOOP. SKIP. WRITE:/ 'After using Index addition' COLOR 4. gwa_student-id = 4. gwa_student-name = 'RAM'. INSERT gwa_student INTO it INDEX 2. WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5. LOOP AT it INTO gwa_student. WRITE:/ gwa_student-id, gwa_student-name. ENDLOOP.
Serkan AKKAVAK Computer Engineer ABAP Developer & SAP S/4 HANA Logistics Consultant Contact : serkurumsal@yandex.com
Social Plugin