Skip to end of metadata
Go to start of metadata

Achievement

By clicking down or up button, the table width could be changed dynamically - each time the button is clicked, 
the width increases or shrinks at 10 px interval.
1. Create a table view with toolbar defined:
2. Create the attribute gt_toolbar_button in controller class:
Define the on click handling logic for button DOWN and UP:

 
3. Create two event handler for DOWN and UP:
  
  method EH_ONDOWN.
    change( iv_up = abap_false ).
  endmethod.
  
  method EH_ONUP.
    change( iv_up = abap_true ).
  endmethod.
  
The implementation of change method:
  
  method CHANGE.
   CALL METHOD me->configuration_descr->get_config_data
     RECEIVING
        rv_result                = DATA(lv_xml)
     EXCEPTIONS
        config_not_found         = 1.
   CHECK sy-subrc = 0.
   DATA(ls_config_data) = cl_bsp_dlc_table_utility=>conf_xml_to_abap( lv_xml ).
   LOOP AT ls_config_data-columndefinition ASSIGNING FIELD-SYMBOL(<column>).
      <column>-width = GET_WIDTH( iv_up = iv_up iv_old_value = <column>-width ).
   ENDLOOP.
   DATA(lv_xml_changed) = cl_bsp_dlc_table_utility=>conf_abap_to_xml( ls_config_data ).
   DATA(lr_configuration2) = CAST if_bsp_dlc_config_table_layout( me->configuration_descr ).
   lr_configuration2->set_active_table_layout( iv_config_data = lv_xml_changed ).
  endmethod.
  
The implementation of get_width method:
  
  method GET_WIDTH.
     DATA lv_new TYPE i.
     DATA lv_temp TYPE string.
     lv_temp = iv_old_value.
     REPLACE ALL OCCURRENCES OF 'px' IN lv_temp WITH space.
     CONDENSE lv_temp NO-GAPS.
     lv_new = lv_temp.
     IF iv_up = abap_true.
       lv_new = lv_new + 10.
     ELSE.
       lv_new = lv_new - 10.
     ENDIF.
     lv_temp = lv_new.
     value = lv_temp && 'px'.
     CONDENSE value NO-GAPS.
  endmethod.
  
Signature of these two methods:
  
 methods CHANGE
    importing
      !IV_UP type ABAP_BOOL .
  methods GET_WIDTH
    importing
      !IV_OLD_VALUE type STRING
      !IV_UP type ABAP_BOOL
    returning
      value(VALUE) type STRING .

  • No labels