Professional Documents
Culture Documents
1. Internal Table
2. Work area
3. Difference Between Internal tables & workarea
4. Declaring Internal Tables
5. Read Data from Database into ITAB
6. Processing Data from internal Tables
a. Display Data from ITAB
b. Adding records (APPEND / INSERT)
c. Modify Records from ITAB (MODIFY)
d. Reading Data from ITAB(READ)
e. Delete Records from ITAB (DELETE)
f. Delete Adjacent Duplicate Records
g. Append of Internal Tables Lines (COLLECT)
h. Types of Internal Tables
i. Types of Declaring Internal Tables
j. Declaring STANDARD Tables
==============================================
===================
Internal Tables
Internal tables are used to obtain data from a fixed structure for dynamic use
in ABAP. Each line in the internal table has the same field structure. The
main use for internal tables is for storing and formatting data from a
database table within a program.
Workarea
Work areas are single rows of data. It should have the same format as any of
the internal tables. It is used to process the data in an internal table one line
at a time.
In ABAP, internal tables are Array (Group) Of Structures, Where the structure
is group of fields (record).
Memory Allocation for Internal Tables Is Dynamic Thus internal tables are
dynamic data objects, since they can contain any number of lines of a
particular type.
The only restrictions on the number of lines an internal table may contain are
the limits of your system installation the maximum memory that can be
occupied by an internal table (including its internal administration) is 2
gigabytes. A More realistic figure is up to 500 megabytes. An additional
restriction for hashed tables is that they may not contain more than 3 million
entries.
The line types of internal tables can be any ABAP data types - elementary,
structured, or
Internal tables.
Syntax to Select the Data From Database Table into Internal Table:
SELECT <F1>
<F2 >
<F3>
……..
INTO TABLE <ITAB>
FROM <DBT>
WHERE <Condition If Any>.
Note: Make Sure that the structure(Order) of Fields in the SELECT and
Internal Table
Should be Same, Because the Content Of 1st Field in the SELECT is
transferred to the 1st
Field Of <ITAB> and Similarly 2nd ,3rd , etc.
Example Program:
Display the list of German Companies Details (Company Code, Name, City,
Country ) from t001.
SELECT BUKRS
BUTXT
ORT01
Note: After the SELECT Data from Database Table is transferred to Internal
Table.
LOOP Points to the First record by Default and Collect it into <WA> and
Process the Data from the WA>.
FROM <N1> TO <N2> is Optional, If We Ignore it, All the Records are
Transferred, Else only the records from <N1> TO <N2> are Transferred.
Finding No of Records:
DESCRIBE TABLE <ITAB> LINES <V_LINES>. “ ( V-LINES TYPE I).
'The No of Records from <ITAB> is collected into V-LINES.
SORT:
To Arrange the Records into Ascending / Descending Groups.
SORT <ITAB> ASCENDING / DESCENDING BY <F1> <F2>...
NOTE: Make sure that the Internal Table is sorted to Apply BINARY SEARCH.
DELETING Records:
NOTE: Make sure that the Duplicates Should be Adjacent. Which can be done
through Sorting.
MODIFY:
Either Single / Multiple Records Modification are always through <WA>.
HEADER LINE: Is the Default (Implicit) Work Area, Defined by the System,
with
The name of internal table.
Note: Here Both Internal Table and Work Areas are defined with the Same
Name i.e., IT_T001.
NOTE : <ITAB>s With HEADER LINE is Not Recommended, Instead SAP
Recommends Explicit Work Areas.
This is the most appropriate type if you need a table which is sorted as you
fill it. You fill sorted tables using the INSERT statement. Entries are inserted
according to the sort sequence defined through the table key.
Hashed Tables:
This is the most appropriate type for ally table where the main operation is
key access.
Hashed tables are useful if you want to construct and use an internal table
which
Resembles a database table or for processing large amounts of data.
NOTE: Whenever the same Internal Table is used again and again in the
same Program.
it is better to INITIALIZE (Clear the Current Current) and before we use it
again.
CLEAR:
CLEAR<Variable>.
NOTE: The <Variable> Can be a normal Variable, Work Area, Internal Table
etc. So that CLEAR Can Clear the Contents Of the Corresponding
Variable.
Note: If you are using internal tables with Header lines, remember that the
header line and the body of the table have the same name. If you want to
address the body of the table in a comparison, you must place two brackets [
] after the table name.
As with the CLEAR statement, the memory used by the table before you
initialized it remains allocated.
You can always use FREE to initialize an internal table and also release its
memory space That is allocated and which is not Possible through CLEAR and
REFRESH.
Note : Both CLEAR and REFRESH Can Clear Only the Contents but they
cannot release the Memory Occupied. After a FREE statement, you can
address the internal table again. When you refill the table, the system has to
allocate new memory space to the lines.