ABAP Control Framework(1): Container容器
作者:互联网
ABAP Control Framework
ABAP屏幕组件示例Tcode:GUIT,Program: SAPM_GUITEST_PORTABLE。ABAP Control Framework可以显示GRID ALV,Picture,TextEdit, HTML,Calendar,Tree,Toolbar等。这些组件通过类实现,命名:CL_GUI_XXXX。
1.Container
Container容器父类:CL_GUI_CONTAINER;
SAP Custom Container: CL_GUI_CUSTOM_CONTAINER;
SAP Dialogbox Container: CL_GUI_DIALOGBOX_CONTAINER;
SAP Docking Container: CL_GUI_DOCKING_CONTAINER;
SAP Splitter Container: CL_GUI_SPLITTER_CONTAINER;
SAP Easy Splitter Container: CL_GUI_EASY_SPLITTER_CONTAINER;
示例:
创建各种容器,需要创建screen 100
CLASS c4_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS:m_dialog_close FOR EVENT close OF cl_gui_dialogbox_container IMPORTING sender. ENDCLASS. CLASS c4_event_handler IMPLEMENTATION. METHOD m_dialog_close. sender->free( ). ENDMETHOD. ENDCLASS. CLASS c4 DEFINITION. PUBLIC SECTION. DATA:lo_custom_container TYPE REF TO cl_gui_custom_container. DATA:lo_dialog_container TYPE REF TO cl_gui_dialogbox_container. DATA:lo_docking_container TYPE REF TO cl_gui_docking_container. DATA:lo_splitter_container TYPE REF TO cl_gui_splitter_container. DATA:lo_easy_splitter_container TYPE REF TO cl_gui_easy_splitter_container. METHODS:init_custom_container. METHODS:init_dialog_container. METHODS:init_docking_container. METHODS:init_splitter_container. METHODS:init_easy_splitter_container. ENDCLASS. CLASS c4 IMPLEMENTATION. METHOD:init_custom_container. DATA:lv_parent TYPE REF TO cl_gui_container. DATA:lv_container_name TYPE C LENGTH 30 VALUE 'CUSTOM_CONTROL'. "控制外观和动作,cl_gui_control中ws_*定义 DATA:lv_style TYPE I VALUE cl_gui_control=>ws_sysmenu. "cl_gui_container=>LIFETIME_DEFAULT,, "LIFETIME_IMODE:leave program,leave transaction,销毁 "LIFETIME_DYNPRO:和screen保持一致,call screen,call transaction,不会销毁 DATA:lv_lifetime TYPE I VALUE cl_gui_container=>lifetime_dynpro. CREATE OBJECT lo_custom_container EXPORTING "parent container "parent = lv_parent "screen painer定义的cutom control name,必须参数 container_name = lv_container_name style = lv_style lifetime = lv_lifetime "repid = sy-repid "container所在screen "dynnr = '100' "是否关闭自动program id,dynnr no_autodef_progid_dynnr = '' EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. ENDMETHOD. METHOD:init_dialog_container. DATA:lv_parent TYPE REF TO cl_gui_container. DATA:lv_width TYPE I VALUE 200. DATA:lv_height TYPE I VALUE 100. DATA:lv_style TYPE I VALUE cl_gui_control=>ws_sysmenu. DATA:lv_lifetime TYPE I. DATA:lv_caption TYPE C LENGTH 30 VALUE 'title'. "METRIC_MM:millimeter;METRIC_PIXEL:pixel metric;METRIC_DEFAULT; DATA:lv_metric TYPE I VALUE cl_gui_dialogbox_container=>metric_default. "method:set_caption,设置title DATA:lv_name TYPE string VALUE 'dialog1'. "创建dialog CREATE OBJECT lo_dialog_container EXPORTING "parent = lv_parent width = lv_width height = lv_height style = lv_style repid = sy-repid dynnr = '100' lifetime = lv_lifetime "顶部距离 top = 100 "左边距离 left = 100 "标题 caption = lv_caption no_autodef_progid_dynnr = '' metric = lv_metric "dialog name name = lv_name. "设置事件 SET HANDLER c4_event_handler=>m_dialog_close FOR lo_dialog_container. "设置dialog title lo_dialog_container->set_caption( 'change title' ). ENDMETHOD. METHOD:init_docking_container. DATA:lv_parent TYPE REF TO cl_gui_container. "DOCK_AT_LEFT;DOCK_AT_TOP;DOCK_AT_BOTTOM;DOCK_AT_RIGHT DATA:lv_side TYPE I VALUE cl_gui_docking_container=>dock_at_left. "扩展,宽度高度 DATA:lv_extension TYPE I VALUE '100'. DATA:lv_style TYPE I. DATA:lv_lifetime TYPE I. "title DATA:lv_caption TYPE C LENGTH 30 VALUE 'title'. DATA:lv_metric TYPE I. "屏幕百分比,优先于extension DATA:lv_ratio TYPE I. DATA:lv_name TYPE string. "创建docking容器 CREATE OBJECT lo_docking_container EXPORTING "parent = lv_parent dynnr = '100' repid = sy-repid side = lv_side extension = lv_extension style = lv_style lifetime = lv_lifetime caption = lv_caption metric = lv_metric ratio = lv_ratio no_autodef_progid_dynnr = '' name = lv_name. "设置docking dock at lo_docking_container->dock_at( cl_gui_docking_container=>dock_at_right ). "设置docking float "PROPERTY_DOCKING;PROPERTY_FLOATING lo_docking_container->float( cl_gui_docking_container=>property_docking ). "设置extension lo_docking_container->set_extension( 100 ). "设置caption lo_docking_container->set_caption( 'change title' ). ENDMETHOD. METHOD:init_splitter_container. DATA:lv_parent TYPE REF TO cl_gui_container. DATA:lv_shell TYPE I. DATA:lv_width TYPE I VALUE 400. DATA:lv_height TYPE I VALUE 400. DATA:lv_metric TYPE C LENGTH 4. "ALIGN_AT_BOTTOM;ALIGN_AT_LEFT;ALIGN_AT_RIGHT;ALIGN_AT_TOP DATA:lv_align TYPE I VALUE cl_gui_splitter_container=>align_at_left. DATA:lv_name TYPE string. DATA:lo_control TYPE REF TO cl_gui_control. DATA:lv_result TYPE I. DATA:lo_container TYPE REF TO cl_gui_container. "生成一个两行两列的容器 CREATE OBJECT lo_splitter_container EXPORTING link_dynnr = '100' link_repid = sy-repid shellstyle = lv_shell left = 0 top = 0 width = lv_width height = lv_height metric = lv_metric align = lv_align parent = lv_parent "行,列格子 rows = 2 columns = 2 no_autodef_progid_dynnr = '' name = lv_name. "指定cell,添加control控件 lo_splitter_container->add_control( EXPORTING row = 1 column = 1 control = lo_control IMPORTING result = lv_result ). "指定cell,移除control控件 lo_splitter_container->remove_control( EXPORTING row = 1 column = 1 IMPORTING result = lv_result ). "获取指定cell,作为容器 lo_splitter_container->get_container( EXPORTING row = 1 column = 1 ). "设置border lo_splitter_container->set_border( abap_true ). "获取行,列数 lo_splitter_container->get_columns( IMPORTING result = lv_result ). lo_splitter_container->get_rows( IMPORTING result = lv_result ). "设置行列 "MODE_DESIGN;MODE_RUN "lo_splitter_container->set_column_mode( ). "lo_splitter_container->set_column_width( ). "lo_splitter_container->set_column_sash( ). "lo_splitter_container->set_row_mode( ). "lo_splitter_container->set_row_height( ). "lo_splitter_container->set_row_sash( ). ENDMETHOD. METHOD:init_easy_splitter_container. DATA:lv_metric TYPE C LENGTH 4. DATA:lv_parent TYPE REF TO cl_gui_container. DATA:lv_name TYPE string . "创建两个格子容器 CREATE OBJECT lo_easy_splitter_container EXPORTING link_dynnr = '100' link_repid = sy-repid metric = lv_metric "parent = lv_parent "0:vertical,1:horizontal orientation = 0 sash_position = 50 "1:with border,0:without with_border = 1 name = lv_name. "设置splitter bar位置 lo_easy_splitter_container->set_sash_position( 30 ). ENDMETHOD. ENDCLASS.
标签:Control,splitter,container,DATA,lv,Framework,ABAP,lo,TYPE 来源: https://www.cnblogs.com/tangToms/p/14736918.html