An internal table is a temporary table stored in RAM on the
application server. It is created and filled by a program during execution and
is discarded when the program ends. Like a database table, an internal table
consists of one or more rows with an identical structure, but unlike a database
table, it can’t hold data after the program ends. Use it as temporary storage
for manipulating data or as a temporary private buffer.
Most Of the times, Each Department want to see the same data
in a different view and want to Manipulate according their requirements and
that Manipulated data is NOT required by the other departments So that Data in Database
Should not be changed , When the Changes are required by all the Departments.
Instead the Copy of the required Database Tables should be fetched into Program
and Manipulate it accordingly,
Which doesn't change the Data base. To Maintain
the Copy Of the Database Table Data in the Program, the Program should have a
variable (Temporary Table) , Which is Nothing but Internal Table.
- Internal tables are like array of a structure.
- They resemble data tables.
- They are used to store & process data extracted from database tables.
- They can dynamically manage memory allocation & deallocation.
An internal
table consists of a body and an optional header line.
The body
holds the rows of the internal table. All rows within it have the same
structure. The term “internal table” itself usually refers to the body of the
internal table.
The header
line is a field string with the same structure as a row of the body, but it can
only hold a single row. It is a buffer used to hold each record before it is
added or each record as it is retrieved from the internal table.
Syntax:
DATA :
BEGIN OF <Internal table name> OCCURS
<n>,
<Field Structure / Line Type>,
END OF < Internal table name
>.
Example:
DATA :
BEGIN OF ITAB OCCURS 3,
A TYPE I,
B TYPE I,
END OF ITAB.
To define an internal table body, use occurs n on the definition of any field string except tables. Occurs creates the body of the internal table. The memory for the body is not allocated until the first row is added to it. Without occurs, you only have a field string.
To define an internal table with a header line, you must include either begin of or with header line in the definition. A header line is automatically created if begin of appears in the definition. If you use like instead of begin of, the internal table will not have a header line unless you add with header line after the occurs clause.
The only time you would create an internal table without a header line is in the case of a nested internal table. A nested internal table can't have a header line.
Defining Internal Tables with & without a header line:
TYPES : BEGIN OF STRUCT, ------> Defining Structure
A TYPE I,
B TYPE I,
END OF STRUCT.
DATA ITAB2 LIKE STRUCT OCCURS 10 -----> Doesn't have a header line
DATA ITAB3 LIKE STRUCT OCCURS 10 WITH HEADER LINE -->With header line
In the above code, ITAB1 is an internal table because of the presence of the occurs clause. It has two components A and B. Each type is I. This internal table has a header line because the definition contains the words begin of.
ITAB2 contains the same components as defined in the structure. ITAB2 doesn't have a header line because neither "begin of" nor "with header line" appear in the definition.
ITAB3 definition is almost same as that of ITAB2. The difference is the addition "with header line". This, of course, causes ITAB3 to have a header line.
To define an internal table body, use occurs n on the definition of any field string except tables. Occurs creates the body of the internal table. The memory for the body is not allocated until the first row is added to it. Without occurs, you only have a field string.
To define an internal table with a header line, you must include either begin of or with header line in the definition. A header line is automatically created if begin of appears in the definition. If you use like instead of begin of, the internal table will not have a header line unless you add with header line after the occurs clause.
The only time you would create an internal table without a header line is in the case of a nested internal table. A nested internal table can't have a header line.
Defining Internal Tables with & without a header line:
TYPES : BEGIN OF STRUCT, ------> Defining Structure
A TYPE I,
B TYPE I,
END OF STRUCT.
DATA : BEGIN OF ITAB1 OCCURS 3, ------> Defining Internal Table with a
A TYPE I, header line.
B TYPE I,
END OF ITAB.DATA ITAB2 LIKE STRUCT OCCURS 10 -----> Doesn't have a header line
DATA ITAB3 LIKE STRUCT OCCURS 10 WITH HEADER LINE -->With header line
In the above code, ITAB1 is an internal table because of the presence of the occurs clause. It has two components A and B. Each type is I. This internal table has a header line because the definition contains the words begin of.
ITAB2 contains the same components as defined in the structure. ITAB2 doesn't have a header line because neither "begin of" nor "with header line" appear in the definition.
ITAB3 definition is almost same as that of ITAB2. The difference is the addition "with header line". This, of course, causes ITAB3 to have a header line.
excellent post thanks for sharing from Sankar
ReplyDelete