1. 程式人生 > >ABAP OO 控制元件建立步驟簡單介紹

ABAP OO 控制元件建立步驟簡單介紹

作為 一個ABAPER,必須得熟悉OO 控制元件的使用,如OO ALV、TEXTEDIT、TREE、PICTURE等等。

可使用事務程式碼BIBS-使用者介面設計的範例進行學習,裡面有很全的OO控制元件例子。

下面簡單介紹OO 建立步驟:

1、在自定義螢幕上建立一個自定義控制元件並命名,例:TEXTEDITOR

2、在螢幕PBO中建立CUSTOMER容器

DATA:container TYPE REF TO cl_gui_custom_container.
  CREATE OBJECT container
      EXPORTING
          container_name = 'TEXTEDITOR'
      EXCEPTIONS
          others = 1.
  IF sy-subrc NE 0.
*    add your handling
  ENDIF.
3、建立TEXTEDITOR物件

至於EDITOR裡面的各個引數,可檢視該類中的方法頁簽下的CONSTRUCTOR構造器

DATA: editor TYPE REF TO cl_gui_textedit.
  CREATE OBJECT editor
        EXPORTING
           parent = container
           wordwrap_mode =
               cl_gui_textedit=>wordwrap_at_fixed_position
           wordwrap_position = g_line_length
           wordwrap_to_linebreak_mode = cl_gui_textedit=>true.

4、註冊事件(如果需要進行一些操作響應的話,需要此步驟)
* register editor for event dblclick
  CALL METHOD editor->register_event_dblclick
        EXPORTING  appl_event = 'X'.

5、定義類
CLASS c_event_receiver DEFINITION.
* The class is used to test the events raised by the
* cl_gui_textedit class
  PUBLIC SECTION.
    METHODS event_handler_dblclick
            FOR EVENT dblclick OF cl_gui_textedit.
ENDCLASS.
6、定義類的實現

實現使用者操作響應

CLASS c_event_receiver IMPLEMENTATION.
************************************************************************
* CLASS   c_event_receiver
* METHOD  event_handler_dblclick
************************************************************************
  METHOD event_handler_dblclick.
*   for event dblclick of cl_gui_textedit.
    CALL METHOD editor->get_selection_pos
       IMPORTING
              from_line = from_line
              from_pos = from_pos
              to_line = to_line
              to_pos = to_pos.
  ENDMETHOD.
ENDCLASS.

7、設定處理函式

* Create the event_receiver object and set the handlers for the events
* of the control
  CREATE OBJECT event_receiver.
  SET HANDLER event_receiver->event_handler_dblclick
              FOR editor.

其他OO控制元件大致如此。