‎2008 Mar 19 5:16 PM
Hi guys,
I need to show a lot of tables with ALV, i need to do something like this.
data: TABLE type tabname,
TI type tabname.
IF OPT_ATV IS NOT INITIAL.
TABLE = 'ZTSDHR005'.
IT = 'ti_ZTSDHR005'.
ENDIF.
IF OPT_FORMATO IS NOT INITIAL.
TABLE = 'ZTSDHR004'.
IT = 'ti_ZTSDHR004'.
ENDIF.
select *
into corresponding fields of table (IT)
from (table)
where erdat in fecha.
then perform the report using ALV with IT.
An error is displayed on select statement due to IT is not an internal table, i need that take the name of the internal table.
any ideas?
‎2008 Mar 19 5:19 PM
I just saw the documentation, you can't assign the internal table name that way.
You need to make a dynamic table
Edited by: Ramiro Escamilla on Mar 19, 2008 6:24 PM
Correcting error
‎2008 Mar 19 5:19 PM
I just saw the documentation, you can't assign the internal table name that way.
You need to make a dynamic table
Edited by: Ramiro Escamilla on Mar 19, 2008 6:24 PM
Correcting error
‎2008 Mar 19 5:30 PM
tks but is not working.
the error displayed is:
Field "(TI)" is unknown. It is neither in one of the specified tables
nor defined by a "DATA" statement. "DATA" statement.
‎2008 Mar 19 5:34 PM
Yes, you can't do that, you need to create a dinamic table for each select you want to use.
Use class CL_ALV_TABLE_CREATE and method CREATE_DYNAMIC_TABLE
If you know how to use ALV it should be easy to understand it
‎2008 Mar 19 5:36 PM
Do it like this...
DATA: dataref TYPE REF TO data,
descr_struct_ref TYPE REF TO cl_abap_structdescr,
wa_fcat TYPE lvc_s_fcat,
it_fieldcatalog TYPE lvc_t_fcat.
DATA: tab_name(20) TYPE c.
tab_name = 'SPFLI'.
FIELD-SYMBOLS: <fs> TYPE ANY,
<component> TYPE abap_compdescr,
<dyn_table> TYPE STANDARD TABLE.
CREATE DATA dataref TYPE (tab_name).
ASSIGN dataref->* TO <fs>.
descr_struct_ref ?= cl_abap_typedescr=>describe_by_data( <fs> ).
LOOP AT descr_struct_ref->components ASSIGNING <component>.
wa_fcat-fieldname = <component>-name.
wa_fcat-ref_table = tab_name.
wa_fcat-ref_field = <component>-name.
APPEND wa_fcat TO it_fieldcatalog.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcatalog
IMPORTING
ep_table = dataref
EXCEPTIONS
OTHERS = 1.
ASSIGN dataref->* TO <dyn_table>.
select *
into corresponding fields of table <dyn_table>
from (tab_name).
Greetings,
Blag.
‎2008 Mar 19 6:06 PM
REPORT create_dynamic_table.
PARAMETERS: p_tbl(80) TYPE c DEFAULT 'TSTC'.
DATA: g_r_table TYPE REF TO data,
g_r_struct TYPE REF TO data,
g_r_structdescr TYPE REF TO cl_abap_structdescr,
g_r_tabledescr TYPE REF TO cl_abap_tabledescr.
FIELD-SYMBOLS: <extract_table> TYPE ANY TABLE.
FIELD-SYMBOLS: <extract_struct> TYPE ANY.
START-OF-SELECTION.
g_r_structdescr ?= cl_abap_typedescr=>describe_by_name( p_tbl ).
g_r_tabledescr = cl_abap_tabledescr=>create(
p_line_type = g_r_structdescr
p_table_kind = cl_abap_tabledescr=>tablekind_std ).
CREATE DATA g_r_table TYPE HANDLE g_r_tabledescr.
CREATE DATA g_r_struct TYPE HANDLE g_r_structdescr.
ASSIGN g_r_table->* TO <extract_table>.
ASSIGN g_r_struct->* TO <extract_struct>.
SELECT * FROM (p_tbl)
INTO CORRESPONDING FIELDS OF TABLE <extract_table>.