ABAP – List of all colors available in WebDynpro

SAPThis is a demo webdynpro application to show you a list of all available colors you can use in your WebDynpros.

  1. In SE80 Create new WebDynpro component
  2. In ComponentController create the following Context
    Colors in WebDynpro - ComponentController Context
    Node ALV_COLORS with cardinality 0..n and selection 0..1
    Element NAME with type CHAR30
    Element COLOR with type WDY_UIE_LIBRARY_ENUM_TYPE
  3. In View MAIN, tab Properties – add new Component use:
    ALV_COLORS with type SALV_WD_TABLE
    Colors in WebDynpro - View Component Uses
  4. In View MAIN, tab Layout – add ViewContainerUIElement VIC_ALV_COLORS
    Colors in WebDynpro - View Layout
  5. In View MAIN, tab Context – copy node ALV_COLORS from ComponentController Context
    Colors in WebDynpro - View Context
  6. In View MAIN, tab Methods, impement method WDDOINIT with code attached below
  7. Create new WebDynpro Application for your component and execute it – You should see the following result
    Colors in WebDynpro - WebDynpro colors
METHOD wddoinit.
  """""""""""""""""""""""""""""""""""""""""""""""""
  " data declarations                             "
  """""""""""""""""""""""""""""""""""""""""""""""""
  DATA: ls_stru                TYPE REF TO cl_abap_structdescr,
        lt_comp                TYPE STANDARD TABLE OF abap_componentdescr,
        lo_nd_alv_colors       TYPE REF TO if_wd_context_node,
        lt_alv_colors          TYPE wd_this->elements_alv_colors,
        ls_alv_colors          LIKE LINE OF lt_alv_colors,
        lo_input_field         TYPE REF TO cl_salv_wd_uie_input_field,
        lo_value               TYPE REF TO cl_salv_wd_config_table,
        lo_interfacecontroller TYPE REF TO iwci_salv_wd_table,
        lo_table_settings      TYPE REF TO if_salv_wd_table_settings,
        lo_std_settings        TYPE REF TO if_salv_wd_config_table.

  FIELD-SYMBOLS: <lv_value> TYPE any.
  """""""""""""""""""""""""""""""""""""""""""""""""
  " component usage                               "
  """""""""""""""""""""""""""""""""""""""""""""""""
  DATA(lo_cmp_usage_alv) = wd_this->wd_cpuse_alv_colors( ).
  IF lo_cmp_usage_alv->has_active_component( ) IS INITIAL.
    lo_cmp_usage_alv->create_component( ).
  ENDIF.
  """""""""""""""""""""""""""""""""""""""""""""""""
  " get structure                                 "
  """""""""""""""""""""""""""""""""""""""""""""""""
  ls_stru ?= cl_abap_typedescr=>describe_by_data( 
    cl_wd_table_column=>e_cell_design 
  ).
  lt_comp = ls_stru->get_components( ).
  """""""""""""""""""""""""""""""""""""""""""""""""
  " create table                                  "
  """""""""""""""""""""""""""""""""""""""""""""""""
  LOOP AT lt_comp INTO DATA(ls_comp).
    ASSIGN COMPONENT ls_comp-name 
      OF STRUCTURE cl_wd_table_column=>e_cell_design 
      TO <lv_value>.
    IF <lv_value> IS ASSIGNED.
      ls_alv_colors-name = ls_comp-name.
      ls_alv_colors-color = <lv_value>.
      APPEND ls_alv_colors TO lt_alv_colors.
    ENDIF.
  ENDLOOP.
  """""""""""""""""""""""""""""""""""""""""""""""""
  " set context                                   "
  """""""""""""""""""""""""""""""""""""""""""""""""
  lo_nd_alv_colors = wd_context->get_child_node( 
    name = wd_this->wdctx_alv_colors 
  ).
  lo_nd_alv_colors->bind_table( lt_alv_colors ).
  """""""""""""""""""""""""""""""""""""""""""""""""
  " set cell color                                "
  """""""""""""""""""""""""""""""""""""""""""""""""
  lo_interfacecontroller =   wd_this->wd_cpifc_alv_colors( ).
  lo_value = lo_interfacecontroller->get_model( ).
  DATA(lo_column) = lo_value->if_salv_wd_column_settings~get_column(
    id = 'COLOR' 
  ).
  lo_column->set_cell_design_fieldname( 'COLOR' ).
  """""""""""""""""""""""""""""""""""""""""""""""""
  " table settings                                "
  """""""""""""""""""""""""""""""""""""""""""""""""
  lo_table_settings ?= lo_value.
  lo_table_settings->set_visible_row_count( '100' ).
  lo_std_settings ?= lo_value.
  lo_std_settings->get_toolbar_settings(
    )->set_visible( 
      value = '00' 
  ).
ENDMETHOD.

Leave a Reply