Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

regarding collect & describe

Former Member
0 Kudos

hi

what is the difference between collect statement and describe ?

6 REPLIES 6

Former Member
0 Kudos

Describe - you will get number of lines in internal table

collect - if non numeric columns equal then it will sum numeric columns,other wise it works like append statement.

Thanks

Seshu

Former Member
0 Kudos

Hi,

COLLECT can used to add rows to the interal table ...and will modify the record if all the character values have the same value..

DESCRIBE has lot of additions..like ..FIELD which gives the definitions about the variable..TABLE will give the number of rows in the internal table.

Thanks

Naren

Former Member
0 Kudos

Hi,

COLLECT statement is used to add rows to the internal table ...and while adding it will check the character fields of the already existing records. if all the character fields are same then it will modify the existing record by adding the numeric field values. if they are not same then it will append the record.

DESCRIBE statement is usually used to know the number of records in the internal table. Also it has lot of additions..like ..FIELD which gives the definitions about the variable..TABLE will give the number of rows in the internal table.

thanks,

sksingh

Former Member
0 Kudos

Hi Lokesh,

<b>Describe : </b>It is mainly used to get attributes of a field or an internal table. Field attributes like type, length, output length, help-id, decimals and internal table attributes like no of records, type of table, initially assigned memory using occurs.

<b>Collect : </b>It appends records (single or multiple) to an internal table if no record exists with the same key combination. If any record exists, then it adds up the numeric data and modifies the internal table accordingly.

Reward points if the answer is helpful.

Regards,

Mukul

Former Member
0 Kudos

Hi,

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.

If you use COLLECT with a work area, the work area must be compatible with the line type of the internal table.

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). 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.

Example

Summarized sales figures by company:

TYPES: BEGIN OF COMPANY,

NAME(20) TYPE C,

SALES TYPE I,

END OF COMPANY.

DATA: COMP TYPE COMPANY,

COMPTAB TYPE HASHED TABLE OF COMPANY

WITH UNIQUE KEY NAME.

COMP-NAME = 'Duck'. COMP-SALES = 10. COLLECT COMP INTO COMPTAB.

COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.

COMP-NAME = 'Duck'. COMP-SALES = 30. COLLECT COMP INTO COMPTAB.

Table COMPTAB now has the following contents:

NAME | SALES

-


Duck | 40

Tiger | 20

DESCRIBE - Return attributes of an internal table

Basic form

DESCRIBE TABLE itab.

Effect

Returns the attributes of the internal table itab. You must use at least one of the additions listed below:

Note

The DESCRIBE statement cannot be used for all ABAP types. In connection with ABAP Objects, SAP has introduced a RTTI concept based on system classes to determine type attributes at runtime. This concept applies to all ABAP types and as such covers all the functions of the DESCRIBE TABLE statement.

Reward if helpful

Regards

Raghavendra.D.S