Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Internal table of Class Type

Former Member
0 Likes
460

Hi!

I' ve a problem with accessing the attributes of objects (global class type) stored in an internal table via READ TABLE ... WITH KEY.

Let' s say my class is something like


CLASS foo DEFINITION.
PUBLIC SECTION.
DATA: foo_key TYPE STRING.
....

and now I' d like to do an operation like


DATA: lt_foo TYPE TABLE OF REF TO foo,
             ls_foo like line of lt_foo.

* fill table
...

* read table with special key

READ TABLE lt_foo into ls_foo
   WITH KEY  foo_key = 'ABC'.

This gives me an compile error.

Has anybody got an idea how to access the objects attributes in the read table-statement?

Regards,

Thomas

1 ACCEPTED SOLUTION
Read only

Sm1tje
Active Contributor
0 Likes
433

You are appending an instance into an internal table. When you now want to access the attributes you'll have to do this:

loop at lt_foo into ls_foo.

if ls_foo->foo_key = 'ABC'.

DO THIS.

else.

DO THAT / OR DO NOTHING.

endif.

endloop.

Hi!

I' ve a problem with accessing the attributes of objects (global class type) stored in an internal table via READ TABLE ... WITH KEY.

Let' s say my class is something like


CLASS foo DEFINITION.
PUBLIC SECTION.
DATA: foo_key TYPE STRING.
....

and now I' d like to do an operation like


DATA: lt_foo TYPE TABLE OF REF TO foo,
             ls_foo like line of lt_foo.

* fill table
...

* read table with special key

READ TABLE lt_foo into ls_foo
   WITH KEY  foo_key = 'ABC'.

This gives me an compile error.

Has anybody got an idea how to access the objects attributes in the read table-statement?

Regards,

Thomas

2 REPLIES 2
Read only

Sm1tje
Active Contributor
0 Likes
434

You are appending an instance into an internal table. When you now want to access the attributes you'll have to do this:

loop at lt_foo into ls_foo.

if ls_foo->foo_key = 'ABC'.

DO THIS.

else.

DO THAT / OR DO NOTHING.

endif.

endloop.

Read only

Former Member
0 Likes
433

An objects attribute in a table can be accessed via TABLE_LINE->attr.