Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  COLLECT 

COLLECT - result

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... { ASSIGNING <fs> [CASTING] } 
  | { REFERENCE INTO dref }.

Effect

The addition ASSIGNING is used to assign the inserted or existing row to a field symbol <fs> and the addition REFERENCE INTO is used to set a reference to the row in a reference variable.

The syntax and meaning are the same as when specifying the output behavior in the statement READ TABLE and the same restrictions apply regarding the modification of key fields for primary and secondary table keys. In particular, inline declarations using the declaration operators DATA and FIELD-SYMBOL are possible.


Example

The statement COLLECT is executed until the column num reaches the value 100 for one of the three possible key values.

TYPES: 
  BEGIN OF line, 
    key TYPE c LENGTH 1, 
    num TYPE i, 
  END OF line. 
DATA 
  itab TYPE SORTED TABLE OF line 
            WITH UNIQUE KEY key. 

DATA(rnd) = cl_abap_random_int=>create( seed = + sy-uzeit 
                                      min  = 1 
                                       max  = 3 ). 

DO. 
  COLLECT VALUE line( key = COND #( LET r = rnd->get_next( ) IN 
                                  WHEN r = 1 THEN 'X' 
                                   WHEN r = 2 THEN 'Y' 
                                   WHEN r = 3 THEN 'Z' ) 
                      num = 1 ) INTO itab 
          ASSIGNING FIELD-SYMBOL(<fs>). 
  IF <fs>-num = 100. 
    EXIT. 
  ENDIF. 
ENDDO. 

cl_demo_output=>display( itab ).