Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Equivalent of "APPEND INITIAL ASSIGNING" for a hashed itab

OK -

We all know that we don't append wa's to itabs.

Instead, we "append initial line assigning <fs>" and then fillup <fs>,

But what about when I want to use a hashed itab to do an automatic de-dedup (like SAP does "under the covers" with COLLECT.)?

Putting field-symbols aside for the moment, I would code:


and let this insert fail on dup key condition.

So what is the equivalent of this statement with a field-symbol?

I've looked at the "insert result" section of the on-line documentation but I have to confess I don't understand it?

Remember, we want the insert to fail if the key is already present in the hashed itab.


Well, in that case, I would say that you would not use a field symbol to do this. You could, but it would be a little useless, and redundant.

types: begin of t_foo,
        field1 type char2,
        field2 type char2,
        field3 type char2,
        field4 type i,
       end of t_foo.

data: lt_foo type HASHED TABLE OF t_foo
               WITH UNIQUE KEY field1 field2 field3.
data: ls_foo like line of lt_foo.
FIELD-SYMBOLS: <ls_foo> like LINE OF lt_foo.

* Must assign it to use it.
assign ls_foo to <ls_foo>.

clear <ls_foo>.
<ls_foo>-field1 = 'AB'.
<ls_foo>-field2 = 'CD'.
<ls_foo>-field3 = 'EF'.
<ls_foo>-field4 = '2'.
insert <ls_foo> into table lt_foo.

clear <ls_foo>.
<ls_foo>-field1 = 'AB'.
<ls_foo>-field2 = 'CD'.
<ls_foo>-field3 = 'EF'.
<ls_foo>-field4 = '2'.
insert <ls_foo> into table lt_foo.
If sy-subrc <> 0.
   write:/ 'Hey!!! duplicate key here'.

Also, remember, lets not say that you ALWAYS have to use field symbols to access an internal table. You only get the benefit when dealing with internal tables with very large datasets. So if you itab has less than 10 or so rows, you will not see a performance poost by using field symbols.


Rich Heilman

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question