*动态内表alv显示时要求某些单元格显示颜色
*wa_fldcat-datatype不能添加LVC_T_SCOL类型,在创建好内表之后,再添加颜色列.
DATA:
wa_fldcat TYPE lvc_s_fcat,
lt_fldcat TYPE lvc_t_fcat,
dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
comp_tab TYPE cl_abap_structdescr=>component_table WITH HEADER LINE.
FIELD-SYMBOLS:
<dyn_table> TYPE STANDARD TABLE,
<dyn_wa>. wa_fldcat-fieldname = 'COL1'.
wa_fldcat-datatype = 'CHAR'.
wa_fldcat-outputlen = .
wa_fldcat-coltext = 'COL1'.
APPEND wa_fldcat TO lt_fldcat.
... CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
* i_style_table =
it_fieldcatalog = lt_fldcat
* i_length_in_byte =
IMPORTING
ep_table = dy_table
* e_style_fname =
EXCEPTIONS
generate_subpool_dir_full =
OTHERS = .
IF dy_table IS BOUND.
ASSIGN dy_table->* TO <dyn_table>.
itab_type ?= cl_abap_tabledescr=>describe_by_data( <dyn_table> ).
struct_type ?= itab_type->get_table_line_type( ).
comp_tab[] = struct_type->get_components( ).
comp_tab-name = 'COLOR'.
struct_type ?= cl_abap_typedescr=>describe_by_name( 'LVC_S_SCOL' ).
comp_tab-type = cl_abap_tabledescr=>create( struct_type ).
INSERT comp_tab INTO comp_tab INDEX .
struct_type = cl_abap_structdescr=>create( comp_tab[] ).
itab_type = cl_abap_tabledescr=>create( struct_type ). CREATE DATA dy_table TYPE HANDLE itab_type.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDIF.