屏幕分割方法汇总

文摘   2024-11-15 08:08   北京  

01

前言

在SAP开发中,屏幕分割需求非常常见,通常的操作方法有两类:一类是使用多个子屏幕;第二类是使用cl_gui_splitter_container类来创建子容器。

第一类方法有个弊端,子屏幕无法拖动调整大小。

本文介绍第二类方法的四种实现方式,子屏幕之间带有可拖动滑块。

方式1:Easy 拆分器容器

方式2Splitter 拆分器容器

方式3Docking 容器

方式4Splitter 屏幕控件


02

Easy 拆分器容器

使用CL_GUI_EASY_SPLITTER_CONTAINER类实现
使用场景:屏幕只需要水平(垂直)分割为左右(上下)两块子屏幕
其构造方法如下图所示

主要参数有三个:

PARENT   父容器

ORIENTATION  0垂直分割(默认)、1水平分割

SASH_POSITION  分割比例 默认50,屏幕平均分割,滑块居中


其主要属性如下图所示

当调用构造方法之后,会生成两个子容器,赋值给上图两个参数

TOP_LEFT_CONTAINER 为上部分(垂直分割)左部分(水平分割)

BOTTOM_RIGHT_CONTAINER 为下部分(垂直分割)或右部分(水平分割)


系统DEMO程序: RSDEMO_EASY_SPLITTER_CONTROL

  

03

Splitter 拆分器容器

使用CL_GUI_SPLITTER_CONTAINER类实现
使用场景:可以将屏幕分割为多行多列
其构造方法如下图所示

主要参数有三个:

PARENT   父容器

ROWS  分割的行数

COLUMNS  分割的列数


其主要方法如下

GET_CONTAINER:获取某行某列的容器

SET_ROW_HEIGHT:设置某行的高度百分比

SET_COLUMN_WIDTH:设置某列的宽度百分比


注:Easy 拆分器容器CL_GUI_EASY_SPLITTER_CONTAINER的构造方法内部也是调用CL_GUI_SPLITTER_CONTAINER类来实现的。


DEMO程序: RSDEMO_SPLITTER_CONTROL


04

Docking 容器

使用CL_GUI_DOCKING_CONTAINER类实现,可以在父屏幕的四周创建一个停靠的子屏幕(类似Windows的任务栏/MAC的程序坞),这个子屏幕可以作为ALV的父容器
使用场景:正常ALV左边加一个导航的树状ALV(Docking 容器); 
                  表头加一个下部明细ALV(Docking 容)
其构造方法如下图所示

主要参数有四个:

REPID   当前报表名称

DYNNR  停靠的父屏幕编号

SIDE  停靠位置:cl_gui_docking_container=>dock_at_left

                            cl_gui_docking_container=>dock_at_right

                            cl_gui_docking_container=>dock_at_top

                            cl_gui_docking_container=>dock_at_bottom

EXTENSION  屏幕大小,非比例


DEMO程序RSDEMO_DOCKING_CONTROL


05

Splitter 屏幕控件

屏幕控件:元素类型为SpCtr,在屏幕布局的控件中看不到它,
                  只能将屏幕分割水平或垂直的两块子屏幕。
使用CL_DYNPRO_SPLITTER类来实现          
使用场景:几乎适用于所有需要屏幕分割的场景,并且有完整的屏幕
                  逻辑流,是以上几种方法所不具备的
控件属性界面如下:
可设置分隔条方向(垂直/水平);子屏幕分割百分比

CL_DYNPRO_SPLITTER类构造方法如下

SPLITTER_NAME 为屏幕上的SpCtr控件名称。


主要方法如下:

在屏幕的PBO事件中调用SET_SASH,设置分隔条位置

在屏幕的PAI事件中调用GET_GUISASH,获取分隔条位置


DEMO程序DEMO_DYNPRO_SPLITTER_CONTROL


06

ABAP示例

1. SE38创建程序                                                            
2. 创建主屏幕100
    类型:通常
    屏幕上添加一个定制控制,名称CUSTOM

    逻辑流代码
PROCESS BEFORE OUTPUT.  MODULE set_status.*PROCESS AFTER INPUT.  MODULE cancel AT EXIT-COMMAND.

3. 从程序DEMO_DYNPRO_SPLITTER_CONTROL复制100屏幕到自己

    创建的程序中,屏幕编号200.

    逻辑流代码

PROCESS BEFORE OUTPUT.  MODULE set_status.  MODULE set_sash.  CALL SUBSCREEN subscreen1       INCLUDING sy-repid '201'.  CALL SUBSCREEN subscreen2       INCLUDING sy-repid '202'.
PROCESS AFTER INPUT. MODULE cancel AT EXIT-COMMAND. MODULE get_sash. CALL SUBSCREEN subscreen1. CALL SUBSCREEN subscreen2.

4. 创建子屏幕201

    类型:子屏幕

    屏幕上添加一个定制控制,名称PIC1

    逻辑流代码

PROCESS BEFORE OUTPUT.  MODULE status_0101.*PROCESS AFTER INPUT.* MODULE USER_COMMAND_0101.

5. 创建子屏幕202,方法同201屏幕

    类型:子屏幕

    屏幕上添加一个定制控制,名称PIC2

    逻辑流代码

PROCESS BEFORE OUTPUT.  MODULE status_0102.*PROCESS AFTER INPUT.* MODULE USER_COMMAND_0102.

6. 创建GUI状态,名称GUI_100

    只需要一个退出按钮

7. 程序代码

*&---------------------------------------------------------------------**& Report zyxs_dynpro_splitter*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT zyxs_dynpro_splitter.TYPE-POOLS cndp.
PARAMETERS: rd1 TYPE c RADIOBUTTON GROUP rg1 DEFAULT 'X' USER-COMMAND uc1, rd2 TYPE c RADIOBUTTON GROUP rg1, rd3 TYPE c RADIOBUTTON GROUP rg1, rd4 TYPE c RADIOBUTTON GROUP rg1.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK bl1. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT 1(10) t01 MODIF ID g1. "docking 选项 PARAMETERS rd5 TYPE c RADIOBUTTON GROUP rg2 DEFAULT 'X' MODIF ID g1 USER-COMMAND uc2. SELECTION-SCREEN COMMENT 14(3) t02 FOR FIELD rd5 MODIF ID g1. PARAMETERS rd6 TYPE c RADIOBUTTON GROUP rg2 MODIF ID g1. SELECTION-SCREEN COMMENT 20(3) t03 FOR FIELD rd6 MODIF ID g1. PARAMETERS rd7 TYPE c RADIOBUTTON GROUP rg2 MODIF ID g1. SELECTION-SCREEN COMMENT 26(3) t04 FOR FIELD rd7 MODIF ID g1. PARAMETERS rd8 TYPE c RADIOBUTTON GROUP rg2 MODIF ID g1. SELECTION-SCREEN COMMENT 32(3) t05 FOR FIELD rd8 MODIF ID g1. SELECTION-SCREEN END OF LINE.SELECTION-SCREEN END OF BLOCK bl1.


DATA url(155).* splitter controlDATA splitter1 TYPE REF TO cl_gui_easy_splitter_container.DATA splitter2 TYPE REF TO cl_gui_splitter_container.DATA splitter2_1 TYPE REF TO cl_gui_splitter_container.DATA splitter3 TYPE REF TO cl_dynpro_splitter.
* Docking ContainerDATA docking TYPE REF TO cl_gui_docking_container.
DATA container TYPE REF TO cl_gui_custom_container.DATA container_pic1 TYPE REF TO cl_gui_custom_container.DATA container_pic2 TYPE REF TO cl_gui_custom_container.DATA container_1 TYPE REF TO cl_gui_container.DATA container_2 TYPE REF TO cl_gui_container.DATA container_3 TYPE REF TO cl_gui_container.DATA container_4 TYPE REF TO cl_gui_container.DATA picture_1 TYPE REF TO cl_gui_picture.DATA picture_2 TYPE REF TO cl_gui_picture.DATA picture_3 TYPE REF TO cl_gui_picture.DATA picture_4 TYPE REF TO cl_gui_picture.DATA init TYPE abap_bool.DATA ok_code TYPE sy-ucomm.


INITIALIZATION. t01 = 'Docking 选项'. t02 = '左'. t03 = '右'. t04 = '上'. t05 = '下'. %_rd1_%_app_%-text = 'Easy 拆分器容器'. %_rd2_%_app_%-text = 'Splitter 拆分器容器'. %_rd3_%_app_%-text = 'Docking 容器'. %_rd4_%_app_%-text = 'Splitter 屏幕控件'.

AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN. IF rd3 = abap_false AND screen-group1 = 'G1'. screen-active = 0. MODIFY SCREEN. ENDIF. ENDLOOP.
START-OF-SELECTION.* Request an URL from the data provider by exporting the pic_data. PERFORM load_pic_from_db CHANGING url.
CASE abap_true. WHEN rd1 OR rd2 OR rd3. CALL SCREEN 100. WHEN rd4. CALL SCREEN 200. ENDCASE.


MODULE set_status OUTPUT. SET PF-STATUS 'GUI_100'. IF init = abap_false. CASE abap_true. WHEN rd1. PERFORM show1. WHEN rd2. PERFORM show2. WHEN rd3. PERFORM show3. WHEN rd4. PERFORM show4. ENDCASE. init = abap_true. ENDIF.ENDMODULE.
MODULE status_0101 OUTPUT. IF container_pic1 IS NOT BOUND.* create a container for the picture_1 container_pic1 = NEW #( container_name = 'PIC1' ). picture_1 = NEW #( parent = container_pic1 ).
* load picture picture_1->load_picture_from_url( url ). ENDIF.ENDMODULE.
MODULE status_0102 OUTPUT. IF container_pic2 IS NOT BOUND.* create a container for the picture_2 container_pic2 = NEW #( container_name = 'PIC2' ). picture_2 = NEW #( parent = container_pic2 ).
* load picture picture_2->load_picture_from_url( url ). ENDIF.ENDMODULE.
MODULE set_sash OUTPUT. splitter3->set_sash( ).ENDMODULE.
MODULE cancel. LEAVE TO SCREEN 0.ENDMODULE.
MODULE get_sash INPUT. splitter3->get_guisash( ).ENDMODULE.
FORM show1.* create a container for the splitter control container = NEW #( container_name = 'CUSTOM' ).
* create the splitter control splitter1 = NEW #( parent = container orientation = 1 ).
* get the containers of the splitter control container_1 = splitter1->top_left_container. container_2 = splitter1->bottom_right_container.
* create the picture controls inside the containers of the splitter picture_1 = NEW #( parent = container_1 ). picture_2 = NEW #( parent = container_2 ).
* load picture picture_1->load_picture_from_url( url ). picture_2->load_picture_from_url( url ).ENDFORM.
FORM show2.* create a container for the splitter control container = NEW #( container_name = 'CUSTOM' ).* create the splitter control splitter2 = NEW #( parent = container rows = 1 columns = 2 ).* get the containers of the splitter control container_1 = splitter2->get_container( row = 1 column = 1 ). container_2 = splitter2->get_container( row = 1 column = 2 ).
* create the child splitter control splitter2_1 = NEW #( parent = container_2 rows = 2 columns = 1 ).* get the containers of the splitter control container_3 = splitter2_1->get_container( row = 1 column = 1 ). container_4 = splitter2_1->get_container( row = 2 column = 1 ).
* create the picture controls inside the containers of the splitter picture_1 = NEW #( parent = container_1 ). picture_2 = NEW #( parent = container_3 ). picture_3 = NEW #( parent = container_4 ).
* load picture picture_1->load_picture_from_url( url ). picture_2->load_picture_from_url( url ). picture_3->load_picture_from_url( url ).ENDFORM.
FORM show3. DATA repid TYPE sy-repid. DATA dynnr TYPE sy-dynnr. DATA side TYPE i. DATA extension TYPE i.* create a container for the splitter control container = NEW #( container_name = 'CUSTOM' ).
repid = sy-repid. dynnr = sy-dynnr.* create the docking container side = COND i( WHEN rd5 = abap_true THEN cl_gui_docking_container=>dock_at_left WHEN rd6 = abap_true THEN cl_gui_docking_container=>dock_at_right WHEN rd7 = abap_true THEN cl_gui_docking_container=>dock_at_top WHEN rd8 = abap_true THEN cl_gui_docking_container=>dock_at_bottom ). extension = COND i( WHEN rd5 = abap_true OR rd6 = abap_true THEN 180 WHEN rd7 = abap_true OR rd8 = abap_true THEN 80 ). docking = NEW #( repid = repid dynnr = dynnr side = side extension = extension ).
* create the picture container picture_1 = NEW #( parent = container ). picture_2 = NEW #( parent = docking ).
* load picture picture_1->load_picture_from_url( url ). picture_2->load_picture_from_url( url ).ENDFORM.
FORM show4.* create the splitter control splitter3 = NEW #( splitter_name = 'SPLITTER' ).ENDFORM.
*&---------------------------------------------------------------------**& Form LOAD_PIC_FROM_DB*&---------------------------------------------------------------------** text*----------------------------------------------------------------------***----------------------------------------------------------------------*##PERF_NO_TYPEFORM load_pic_from_db CHANGING url. DATA query_table LIKE w3query OCCURS 1 WITH HEADER LINE. DATA html_table LIKE w3html OCCURS 1. DATA return_code LIKE w3param-ret_code. DATA content_type LIKE w3param-cont_type. DATA content_length LIKE w3param-cont_len. DATA pic_data LIKE w3mime OCCURS 0. DATA pic_size TYPE i.
REFRESH query_table. query_table-name = '_OBJECT_ID'. query_table-value = 'ENJOYSAP_LOGO'. APPEND query_table.
##FM_OLDED CALL FUNCTION 'WWW_GET_MIME_OBJECT' TABLES query_string = query_table html = html_table mime = pic_data CHANGING return_code = return_code content_type = content_type content_length = content_length EXCEPTIONS object_not_found = 1 parameter_not_found = 2 OTHERS = 3. IF sy-subrc = 0. pic_size = content_length. ENDIF.
CALL FUNCTION 'DP_CREATE_URL' EXPORTING ##NO_TEXT type = 'image' subtype = cndp_sap_tab_unknown size = pic_size lifetime = cndp_lifetime_transaction TABLES data = pic_data CHANGING url = url ##FM_SUBRC_OK EXCEPTIONS OTHERS = 1.
ENDFORM.

 8. 检查程序结构

9. 运行程序,测试

 

END

 

温馨提示

如果你喜欢本文,请分享给有需要的朋友,想要获得更多信息,请关注我,若有问题以及建议,请在文末留言或者私信。





 

 

扫码关注我们

以便获取最新更新内容


 

码农干货铺
永远要保持一种无论何时何地都逼着自己更努力更优秀来享受更好生活的学习状态
 最新文章