My goal is to show the data of a internal table using an instance of the cl_salv_table class created via the factory method.
When the internal table is defined as STANDARD TABLE it works, but when I change the definition to anything else (like SORTED) I get a compiler error telling me the type of the provided table is type incompatible to the formal parameter T_TABLE. I stubled across this post Sorted table with parameter t_table of cl_salv_table class where it is explained that the factor method only accepts STANDARD TABLE so I have to use one and can't insert a sorted table.
I came up with a workaround by converting the non-standard internal table into a standard table by using SQL's SELECT * FROM sourceTab INTO TABLE @DATA(outputTab) but this causes a compiler error message saying fields of type STRG can't be used in SQL as soon as I have string fields included in the table type - sometimes a field of type string is easier to handle than a CHAR40.
report ztest.
types:
begin of my_table_tt,
material_number type matnr,
material_text type string,
end of my_table_tt,
my_table_t type sorted table of my_table_tt with non-unique key material_number.
data:
salv_table type ref to cl_salv_table.
data my_table type my_table_t.
insert value my_table_tt( material_number = '4711' material_text = `Test123` )
into table my_table.
insert value my_table_tt( material_number = '4712' material_text = `Test456` )
into table my_table.
insert value my_table_tt( material_number = '4713' material_text = `Test789` )
into table my_table.
select *
from @my_table as mt " <------ Compiler error
into table @data(output_table).
cl_salv_table=>factory(
exporting list_display = abap_false
importing r_salv_table = salv_table
changing t_table = output_table
).
salv_table->get_functions( )->set_all( abap_true ).
salv_table->display( ).
Question:
For internal tables based on a local custom type with fields of type STRING and defined as non-standard how can I convert them into a type that can be displayed using the cl_salv_table class?
Self-answer:
1.) Create a internal table TYPE STANDARD TABLE or TYPE TABLE
2.) use CORRESPONDING #( )
in reference to the code I posted earlier:
data output_table type table of my_table_tt.
output_table = corresponding #( my_table ).
Now the factory method accepts the output_table variable and it can be displayed.