ABAP - cl_gui_toolbar->delete_all_buttons not working

672 views Asked by At

DATA: lo_toolbar TYPE REF TO cl_gui_toolbar.

  lo_Tree->get_toolbar_object(
    IMPORTING
      er_toolbar = lo_toolbar    " Toolbar Object
  ).

  lo_toolbar->delete_all_buttons(
    EXCEPTIONS
      cntl_error = 1
      others     = 2
  ).
  IF sy-subrc <> 0.
   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  "add my own buttons
  lo_toolbar->add_button(
    EXPORTING
      fcode            = 'ADDROOT'    " Function Code Associated with Button
      icon             = '@04@'    " Icon Name Defined Like "@0a@"
      butn_type        =  cntb_btype_button   " Button Types Defined in CNTB
      quickinfo        =  'Create new portfolio'   " Purpose of Button Text
    EXCEPTIONS
      cntl_error       = 1
      cntb_btype_error = 2
      cntb_error_fcode = 3
      others           = 4
  ).
  IF sy-subrc <> 0.
   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

I have instance of class cl_gui_alv_tree. And i want to delete standard buttons in toolbar and add my own. So I call get_toolbar_object and its method delete_all_buttons but it doesn't work. The output is my button at first position and then standard buttons. Could you help me with that?

1

There are 1 answers

2
icbytes On

If You inspect the code inside the method called "delete_all_buttons", then you will see a call to another method called, "call_method". This is simply an invocation, AKA dynamic method call of methods, which can be passed as arguments, then You will see many lines like these: (do not bother, if it sounds weird, that is, how dynamic method calls are built. At least one way, but in this case we are dealing with ABAP and OLE beyond this scope by the way) .

 WHEN 3.
        CALL METHOD OF H_CONTROL-OBJ VERB = RESULT NO FLUSH
        EXPORTING #1 = P1
                  #2 = P2
                  #3 = P3.

Or some like these:

WHEN 14.
      CALL METHOD OF H_CONTROL-OBJ VERB = RESULT NO FLUSH QUEUEONLY
          EXPORTING #1 = P1
                    #2 = P2
                    #3 = P3
                    #4 = P4
                    #5 = P5
                    #6 = P6
                    #7 = P7
                    #8 = P8
                    #9 = P9
                    #10 = P10
                    #11 = P11
                    #12 = P12
                    #13 = P13
                    #14 = P14.

What You should notice are the keywords "NO FLUSH" and/or "QUEUE ONLY".

For further information mark them and hit F1. The OLE-documentation tells You more if, desired .

They imply, that the sap-gui-frontend will NOT be notified, regardless, what changes are made to the backend's object-representators, only the backend knows the new state, changings, removals, etc.

In general any pbo/pai should synchronize frontend and backend, in fact I even think, only those, where QUEUEONLY is set, are automatically synced on the next cycle.

If You want to force synchronization, just call the static method of the gui-class-control-framwork-base, AKA cl_gui_cfw.

The proper method call will be ( in fact it is the best choice if You want to alter ui controls BUT You cannot rely on any pbo/pai-cycle ) :

CALL METHOD cl_gui_cfw=>flush.

Could I help You ?