Hi,
FEW BASICS RELATED TO COLLECT STATEMENT :
1. COLLECT allows you to create a unique or summarized
dataset, and you should only use it when this is necessary.
If neither of these characteristics are required, or where
the nature of the table in the application means that it is
impossible for duplicate entries to occur, you should use
INSERT [wa INTO] TABLE itab instead of COLLECT. If you do
need the table to be unique or summarized, COLLECT is the
most efficient way to achieve it.
2. If you use COLLECT with a work area, the work area must be
compatible with the line type of the internal table.
3. If you edit a standard table using COLLECT, you should only
use the COLLECT or MODIFY ... TRANSPORTING f1 f2 ...
statements (where none of f1, f2, ... may be in the key)
enthalten sein). Only then can you be sure that:
- The internal table actually is unique or summarized
- COLLECT runs efficiently. The check whether the dataset
already contains an entry with the same key has a
constant
search time (hash procedure).
If you use any other table modification statements, the
check for entries in the dataset with the same key can only
run using a linear search (and will accordingly take
longer). You can use the function module
ABL_TABLE_HASH_STATE to test whether the COLLECT has a
constant or linear search time for a given standard table.
- go through this simple program.
TYPES: BEGIN OF TY_STRUCTURE,
NAME(20) TYPE C, " UNIQUE KEY..
AGE TYPE I,
END OF TY_STRUCTURE.
DATA: WA_TAB TYPE TY_STRUCTURE,
IT_TAB TYPE HASHED TABLE OF TY_STRUCTURE WITH UNIQUE KEY NAME.
WA_TAB-NAME = 'ADITYA'.
WA_TAB-SALES = 10.
COLLECT WA_TAB INTO IT_TAB.
WA_TAB-NAME = 'JANGID'.
WA_TAB-SALES = 20.
COLLECT WA_TAB INTO IT_TAB.
WA_TAB-NAME = 'ADITYA'.
WA_TAB-SALES = 30.
COLLECT WA_TAB INTO IT_TAB.
Table COMPTAB now has the following contents:
NAME | AGE
ADITYA | 40
JANGID | 20
THANKS!!