cancel
Showing results for 
Search instead for 
Did you mean: 

Collect Statement

Former Member
0 Kudos

Hi ,

Collect can work With out header line.Give me detailed nformation Abt Collect.

Thanku.

Pavan Reddy.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member480923
Active Contributor
0 Kudos

Hi,

use the following statement


data: wa_output type types_output. 

....

collect wa_output into t_output. 

Hope that Helps

Anirban M.

0 Kudos

Hi,

Example of collect with out headerline and with workarea.

*Work area

DATA: BEGIN OF seats,

carrid TYPE sflight-carrid,

connid TYPE sflight-connid,

seatsocc TYPE sflight-seatsocc,

END OF seats.

*Table

DATA seats_tab LIKE HASHED TABLE OF seats

WITH UNIQUE KEY carrid connid.

*Data in the table

SELECT carrid connid seatsocc

FROM sflight

INTO seats.

COLLECT seats INTO seats_tab.

ENDSELECT.

<b>Collect</b>statement inserts the contents of a work area wa either as single row into an internal table itab or adds the values of its numeric components to the corresponding values of existing rows with the same key. As of Release 6.10, you can use result to set a reference to the inserted or changed row in the form of a field symbol or data reference.

Prerequisite for the use of this statement is that wa is compatible with the row type of itab and all components that are not part of the table key must have a numeric data type (i, p, f).

In standard tables that are only filled using COLLECT, the entry is determined by a temporarily created hash administration. The workload is independent of the number of entries in the table. The hash administration is temporary and is generally invalidated when the table is accessed for changing. If further COLLECT statements are entered after an invalidation, a linear search of all table rows is performed. The workload for this search increases in a linear fashion in relation to the number of entries.

In sorted tables, the entry is determined using a binary search. The workload has a logarithmic relationship to the number of entries in the table.

In hashed tables, the entry is determined using the hash administration of the table and is always independent of the number of table entries.

If no line is found with an identical key, a row is inserted as described below, and filled with the content of wa:

In standard tables the line is appended.

In sorted tables, the new line is inserted in the sort sequence of the internal table according to its key values, and the table index of subsequent rows is increased by 1.

In hashed tables, the new row is inserted into the internal table by the hash administration, according to its key values.

If the internal table already contains one or more rows with an identical key, those values of the components of work area wa that are not part of the key, are added to the corresponding components of the uppermost existing row (in the case of index tables, this is the row with the lowest table index).

The COLLECT statement sets sy-tabix to the table index of the inserted or existing row, in the case of standard tables and sorted tables, and to the value 0 in the case of hashed tables.

Outside of classes, you can omit wa INTO if the internal table has an identically-named header line itab. The statement then implicitly uses the header line as the work area.

COLLECT should only be used if you want to create an internal table that is genuinely unique or compressed. In this case, COLLECT can greatly benefit performance. If uniqueness or compression are not required, or the uniqueness is guaranteed for other reasons, the INSERT statement should be used instead.

The use of COLLECT for standard tables is obsolete. COLLECT should primarily be used for hashed tables, as these have a unique table key and a stable hash administration.

If a standard table is filled using COLLECT, it should not be edited using any other statement with the exception of MODIFY. If the latter is used with the addition TRANSPORTING, you must ensure that no key fields are changed. This is the only way to guarantee that the table entries are always unique and compressed, and that the COLLECT statement functions correctly and benefits performance. The function module ABL_TABLE_HASH_STATE can be used to check whether a standard table is suitable for editing using COLLECT.

Regards,

Sesh

Former Member
0 Kudos

Hi,

Yes, COLLECT will work without a header line, If you use COLLECT with an explicitly specified work area, it must be compatible with the line type of the internal table.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm

Regards

Sudheer