An Internal table is a temporary table gets created in the memory of application server during program execution and gets destroyed once the program ends. It is used to hold data temporarily or manipulate the data. It contains one or more rows with same structure.
An internal table can be defined using the keyword TABLE OF in the DATA statement. Internal table can be defined by the following ways.
TYPES: BEGIN OF ty_student, id(5) TYPE n, name(10) TYPE c, END OF ty_student. DATA: gwa_student TYPE ty_student. "Referring to local data type DATA: it1 TYPE TABLE OF ty_student. "Referring to local data object DATA: it2 LIKE TABLE OF gwa_student. "Referring to data type in ABAP dictionary DATA: it3 TYPE TABLE OF mara.
Use the APPEND statement to add data to internal table. First define the work area i.e. define a field string with a structure similar to row of the internal table. Then place the data in the work area and use the APPEND statement to add the data from work area to internal table.
*--------------------------------------------------------------* *Data Types *--------------------------------------------------------------* TYPES: BEGIN OF ty_student, id(5) TYPE n, name(10) TYPE c, END OF ty_student. DATA: gwa_student TYPE ty_student. *--------------------------------------------------------------* *Data Declaration *--------------------------------------------------------------* "Referring to local data type DATA: it TYPE TABLE OF ty_student. gwa_student-id = 1. gwa_student-name = 'JOHN'. APPEND gwa_student TO it. gwa_student-id = 2. gwa_student-name = 'JIM'. APPEND gwa_student TO it. gwa_student-id = 3. gwa_student-name = 'JACK'. APPEND gwa_student TO it.
After the last APPEND statement in the above program, internal table ‘IT’ has the following 3 entries. But the internal table values are not persistent i.e. the internal table and its values are discarded once the program ends.
ID | Name |
---|---|
1 | JOHN |
2 | JIM |
3 | JACK |
Usually internal tables are used to hold data from database tables temporarily for displaying on the screen or further processing. To fill the internal table with database values, use SELECT statement to read the records from the database one by one, place it in the work area and then APPEND the values in the work area to internal table.
DATA: gwa_employee TYPE zemployee, gt_employee TYPE TABLE OF zemployee. SELECT * FROM zemployee INTO gwa_employee. APPEND gwa_employee TO gt_employee. ENDSELECT.
After ENDSELECT the internal table GT_EMPLOYEE contains all the records that are present in table ZEMPLOYEE.
Using INTO TABLE addition to SELECT statement we can also read multiple records directly into the internal table directly. No work area used in this case. This select statement will not work in loop, so no ENDSELECT is required.
SELECT * FROM zemployee INTO TABLE gt_employee.
very easy and simple example,easy to understand, very good example for a starter learner
Nice blog, internal tables very easy to undserstand but for me some times I get confused between it and the work area.
good answers
what is the difference between like and type in abap programming
LIKE refers to data object(example variable which occupy memory) and TYPE refers to data type (Template of variable which does not occupy memory).
super
Excellent piece of information on sap abap, I feel it is right place to get info on SAP ABAP. This was really something, I had been looking for days. Too excited to view your other blogs on ABAP. we provide SAP ABAP ONLINE TRAINING.
By 2001, all but the most basic functions were written in ABAP. In 1999, SAP released an object-oriented extension to ABAP called ABAP Objects, along with R/3 release 4.6.
ABAP Query is a tool that enables you to create lists by navigating through menus. It does notrequire programming knowledge.
SAP ABAP ONLINE TRAINING
good clear and crispy explaination
what is work area
it’s very useful and easy to learn, Thank you…..!