

#Itab hibernate code
For instance, the following code will extract unique project numbers from an internal table: LOOP AT lt_project_data ASSIGNING FIELD-SYMBOL() As the name indicates these function similarly to SQL's GROUP BY. Note that using the first method but inserting the values into a dummy table followed by an APPEND LINES OF lt_dummy INTO lt_sorted_values may be faster, but the size of the intermediate tables can muddle that.Īs of ABAP 7.40 Support Package 08 however, the GROUP BY loops offer a better way to extract unique values. READ TABLE lt_sorted_values WITH KEY table_line = -value BINARY SEARCH. For sorted or hashed destination tables, use: LOOP AT lt_itab ASSIGNING. ĭELETE ADJACENT DUPLICATES FROM lt_values.Ĭhecking the presence of a given -value before adding it to the internal table is another way of guaranteeing uniqueness but will probably be much more computationally expensive when inserting into a standard table. Prior to ABAP 7.40's SP08 release, the most efficient way of extracting unique values from an internal table or itab is the following: LOOP AT lt_itab ASSIGNING. But on the other side appends are faster than inserts. The more duplicate entries exist the faster will be the above solution because it avoids the unnecessary appends to the target table. Whether this is more efficient than SORT / DELETE ADJACENT DUPLICATES depends on the number of duplicate entries in itab. This provides the same behavior as with a sorted table but with a standard table.

INSERT -field INTO lt_unique INDEX sy-tabix. READ TABLE lt_unique WITH TABLE KEY table_line = -field If the target must be a STANDARD TABLE and you have an old ABAP stack you can alternatively use DATA: it_unique TYPE STANDARD TABLE OF fieldtype. No need to do the key lookup twice (once for existence check, once for insert). The non-zero sy-subrc of INSERT is simply ignored. Although I do not recommend to use sorted tables for this purpose unless you are really sure that only a few lines will be in the result. The above works with sorted tables as well. This works with any type of the target table.įor an older release use: DATA: it_unique TYPE HASHED TABLE OF fieldtype WITH UNIQUE KEY table_line. GROUP BY -field WITHOUT MEMBERS ( value ) ). If you have 7.40 SP08 or above you can simply use the inline syntax to populate the target table (no need for LOOP GROUP BY): DATA: it_unique TYPE STANDARD TABLE OF fieldtype.
