‎2010 Jun 18 11:16 AM
Is it possible to display an internal table of objects using ALV?
I've tried to do so using the following code:
TYPES object_table_type TYPE TABLE OF REF TO zcl_classname.
DATA object_table TYPE object_table_type.
... Fill object_table with objects ...
DATA alv_table TYPE REF TO cl_salv_table.
CALL METHOD cl_salv_table=>factory
IMPORTING r_salv_table = alv_table
EXPORTING t_table = object_table.However, during the factory method, I get a dump because of a dynamic type conflict. The call proceeds as follows (I've omitted all formal parameters but t_table, which is the only relevant one in this case):
1. cl_salv_table=>factory( object_table )
2. cl_salv_table->set_data( object_table )
3. cl_salv_data_descr=>describe_table( object_table )
At this point, the describe_table method calls cl_abap_structdescr=>describe_by_data_ref( ) on a reference to a line in object_table. It expects the method to return an instance of cl_abap_structdescr, but it obviously returns an instance of cl_abap_refdescr, as the table line is in fact a reference to an object. Consequently, a dump occurs.
From this, it looks like ALV just wasn't built to cater for displaying objects. That's understandable, as flat structures are a lot simpler to cater for, but disappointing, given the professed push towards object orientation, and considering how integral ALV is to a lot of ABAP development.
Does anyone know if there is any other, standard way to do this? If there isn't, I'll either write code to automatically convert my objects to structures, or extend cl_salv_model_list and make my own ALV table for displaying objects. (I'd love to extend cl_salv_table, but it's final. Annoyingly. I'd rather final classes be banned than have them be the default option. But that's a rant for another day.)
‎2010 Jun 18 2:42 PM
I guess there is no standard option which would generate an ALV of the Obect Table.
You have to take a step back and think of how ALV would able to interpret your table and generate the ALV. Because the Object would have be a "Complex" structure which could contain another object, internal tables, variables as the attributes. So, now what to display and what not to?
If your object has internal table and if you want to display that table in your ALV, you may try to create an Summary ALV which would display the list of your object in structure manner and a detail ALV to display the contain of each object.
Regards,
Naimesh Patel
‎2010 Jun 18 3:05 PM
That's what I figured. Though I'm not sure I agree with you on the complex structure argument. Structures, too, can contain complex components - other structures, references, table types, and so on. I'm not actually sure how the ALV deals with these. I assume it might only display the components of the structure that are elementary. If this is the case, an identical solution for a table of objects would be appropriate, using read-only public attributes or attributes with corresponding GET_ methods. (But I could be totally off.)
For the purposes of this argument, objects are exactly the same as structures. Objects just have methods. Or that's how it seems to me.
Edited by: James Geddes on Jun 18, 2010 4:20 PM