SAP ITAB CLASS ATTRIBUTES AS KEY
Get Example source ABAP code based on a different SAP table
ARTICLE
Attributes of Objects as Internal Table Keys
If the line type of an internal table includes an object reference variable from
If a table contains lines without structure with the type of a reference variable, the attributes of the object to which a line points can be addressed using
Notes
You can use the attribute access, provided that
When using the
Example CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA a1 TYPE i.
ENDCLASS.
DATA: BEGIN OF itab_line,
col1 TYPE i,
col2 TYPE REF TO c1,
END OF itab_line.
DATA itab LIKE HASHED TABLE OF itab_line WITH UNIQUE KEY col1.
DO 5 TIMES.
itab_line-col1 = sy-index.
CREATE OBJECT itab_line-col2.
itab_line-col2->a1 = sy-index ** 2.
INSERT itab_line INTO TABLE itab.
ENDDO.
* SORT
SORT itab BY col2->a1 DESCENDING.
* DELETE
DELETE itab WHERE col2->a1 = 9.
* READ
READ TABLE itab INTO itab_line WITH KEY col2->a1 = 4.
WRITE: / itab_line-col1, itab_line-col2->a1.
SKIP.
* MODIFY
itab_line-col2->a1 = 100.
MODIFY itab FROM itab_line TRANSPORTING col2
WHERE col2->a1 = 4.
* LOOP
LOOP AT itab INTO itab_line WHERE col2->a1 > 1.
WRITE: / itab_line-col1, itab_line-col2->a1.
ENDLOOP.