01
前言
在SAP开发中,屏幕分割需求非常常见,通常的操作方法有两类:一类是使用多个子屏幕;第二类是使用cl_gui_splitter_container类来创建子容器。
第一类方法有个弊端,子屏幕无法拖动调整大小。
本文介绍第二类方法的四种实现方式,子屏幕之间带有可拖动滑块。
方式1:Easy 拆分器容器
方式2:Splitter 拆分器容器
方式3:Docking 容器
方式4:Splitter 屏幕控件
02
Easy 拆分器容器
主要参数有三个:
PARENT 父容器
ORIENTATION 0垂直分割(默认)、1水平分割
SASH_POSITION 分割比例 默认50,屏幕平均分割,滑块居中
其主要属性如下图所示
当调用构造方法之后,会生成两个子容器,赋值给上图两个参数
TOP_LEFT_CONTAINER 为上部分(垂直分割)或左部分(水平分割)
BOTTOM_RIGHT_CONTAINER 为下部分(垂直分割)或右部分(水平分割)
系统DEMO程序: RSDEMO_EASY_SPLITTER_CONTROL
03
Splitter 拆分器容器
主要参数有三个:
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 容器
主要参数有四个:
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 屏幕控件
CL_DYNPRO_SPLITTER类构造方法如下
SPLITTER_NAME 为屏幕上的SpCtr控件名称。
主要方法如下:
在屏幕的PBO事件中调用SET_SASH,设置分隔条位置
在屏幕的PAI事件中调用GET_GUISASH,获取分隔条位置
系统DEMO程序: DEMO_DYNPRO_SPLITTER_CONTROL
06
ABAP示例
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.
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.
SKIP 1.
BEGIN OF BLOCK bl1.
BEGIN OF LINE.
COMMENT 1(10) t01 MODIF ID g1. "docking 选项
PARAMETERS rd5 TYPE c RADIOBUTTON GROUP rg2 DEFAULT 'X' MODIF ID g1 USER-COMMAND uc2.
COMMENT 14(3) t02 FOR FIELD rd5 MODIF ID g1.
PARAMETERS rd6 TYPE c RADIOBUTTON GROUP rg2 MODIF ID g1.
COMMENT 20(3) t03 FOR FIELD rd6 MODIF ID g1.
PARAMETERS rd7 TYPE c RADIOBUTTON GROUP rg2 MODIF ID g1.
COMMENT 26(3) t04 FOR FIELD rd7 MODIF ID g1.
PARAMETERS rd8 TYPE c RADIOBUTTON GROUP rg2 MODIF ID g1.
COMMENT 32(3) t05 FOR FIELD rd8 MODIF ID g1.
END OF LINE.
END OF BLOCK bl1.
DATA url(155).
splitter control
DATA 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 Container
DATA 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 = '下'.
'Easy 拆分器容器'. =
'Splitter 拆分器容器'. =
'Docking 容器'. =
'Splitter 屏幕控件'. =
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF rd3 = abap_false AND screen-group1 = 'G1'.
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
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
url ).
ENDIF.
ENDMODULE.
MODULE set_sash OUTPUT.
).
ENDMODULE.
MODULE cancel.
LEAVE TO SCREEN 0.
ENDMODULE.
MODULE get_sash INPUT.
).
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
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
url ).
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
url ).
url ).
ENDFORM.
FORM show4.
create the splitter control
splitter3 = NEW #( splitter_name = 'SPLITTER' ).
ENDFORM.
*&---------------------------------------------------------------------*
Form LOAD_PIC_FROM_DB
*&---------------------------------------------------------------------*
text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
##PERF_NO_TYPE
FORM 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.
'_OBJECT_ID'. =
'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. 运行程序,测试
温馨提示
如果你喜欢本文,请分享给有需要的朋友,想要获得更多信息,请关注我,若有问题以及建议,请在文末留言或者私信。