SAP 实例 4 CFW
*&---------------------------------------------------------------------*
*& Report demo_cfw *
*&---------------------------------------------------------------------* REPORT demo_cfw. *&---------------------------------------------------------------------*
*& Global Declarations *
*&---------------------------------------------------------------------* * Class Definitions CLASS screen_handler DEFINITION CREATE PRIVATE.
PUBLIC SECTION.
CLASS-DATA screen TYPE REF TO screen_handler.
CLASS-METHODS create_screen.
METHODS constructor.
PRIVATE SECTION.
DATA: container_html TYPE REF TO cl_gui_custom_container,
container_box TYPE REF TO cl_gui_dialogbox_container,
picture TYPE REF TO cl_gui_picture,
tree TYPE REF TO cl_gui_simple_tree,
html_viewer TYPE REF TO cl_gui_html_viewer,
list_viewer TYPE REF TO cl_gui_alv_grid.
METHODS: fill_tree,
fill_picture,
handle_node_double_click
FOR EVENT node_double_click OF cl_gui_simple_tree
IMPORTING node_key,
close_box
FOR EVENT close OF cl_gui_dialogbox_container,
fill_html IMPORTING i_carrid TYPE spfli-carrid,
fill_list IMPORTING i_carrid TYPE spfli-carrid
i_connid TYPE spfli-connid.
ENDCLASS. "screen_handler DEFINITION * Class Implementations CLASS screen_handler IMPLEMENTATION. METHOD create_screen.
IF screen IS INITIAL.
CREATE OBJECT screen.
ENDIF.
ENDMETHOD. "create_screen METHOD constructor.
DATA: l_event_tab TYPE cntl_simple_events,
l_event LIKE LINE OF l_event_tab,
l_docking TYPE REF TO cl_gui_docking_container,
l_splitter TYPE REF TO cl_gui_splitter_container,
l_container_screen TYPE REF TO cl_gui_custom_container,
l_container_top TYPE REF TO cl_gui_container,
l_container_bottom TYPE REF TO cl_gui_container. CREATE OBJECT container_html
EXPORTING container_name = 'CUSTOM_CONTROL'. CREATE OBJECT l_docking
EXPORTING side = cl_gui_docking_container=>dock_at_left
extension = 135. CREATE OBJECT l_splitter
EXPORTING parent = l_docking
rows = 2
columns = 1. l_splitter->set_border(
EXPORTING border = cl_gui_cfw=>false ). l_splitter->set_row_mode(
EXPORTING mode = l_splitter->mode_absolute ). l_splitter->set_row_height(
EXPORTING id = 1
height = 180 ). l_container_top =
l_splitter->get_container( row = 1 column = 1 ).
l_container_bottom =
l_splitter->get_container( row = 2 column = 1 ). CREATE OBJECT picture
EXPORTING parent = l_container_top. CREATE OBJECT tree
EXPORTING parent = l_container_bottom
node_selection_mode =
cl_gui_simple_tree=>node_sel_mode_single. l_event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
l_event-appl_event = ' '. "system event, does not trigger PAI
APPEND l_event TO l_event_tab.
tree->set_registered_events(
EXPORTING events = l_event_tab ).
SET HANDLER me->handle_node_double_click FOR tree. me->fill_picture( ).
me->fill_tree( ).
ENDMETHOD. "constructor METHOD fill_picture.
TYPES pict_line TYPE x LENGTH 1022.
DATA l_mime_api TYPE REF TO if_mr_api.
DATA l_pict_wa TYPE xstring.
DATA l_pict_tab TYPE TABLE OF pict_line.
DATA l_url TYPE c LENGTH 255. l_mime_api = cl_mime_repository_api=>get_api( ). l_mime_api->get(
EXPORTING i_url = '/SAP/PUBLIC/BC/ABAP/Sources/PLANE.GIF'
IMPORTING e_content = l_pict_wa
EXCEPTIONS OTHERS = 4 ). IF sy-subrc <> 0.
RETURN.
ENDIF. l_pict_tab =
VALUE #( LET l1 = xstrlen( l_pict_wa ) l2 = l1 - 1022 IN
FOR j = 0 THEN j + 1022 UNTIL j >= l1
( COND #( WHEN j <= l2 THEN
l_pict_wa+j(1022)
ELSE l_pict_wa+j ) ) ). CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'IMAGE'
subtype = 'GIF'
TABLES
data = l_pict_tab
CHANGING
url = l_url. picture->load_picture_from_url(
EXPORTING url = l_url ).
picture->set_display_mode(
EXPORTING display_mode = picture->display_mode_stretch ).
ENDMETHOD. "fill_picture METHOD fill_tree.
DATA: l_node_table TYPE TABLE OF abdemonode,
l_node TYPE abdemonode,
BEGIN OF l_spfli,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
END OF l_spfli,
l_spfli_tab LIKE SORTED TABLE OF l_spfli
WITH UNIQUE KEY carrid connid. SELECT carrid, connid
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE @l_spfli_tab. l_node-hidden = ' '. " All nodes are visible,
l_node-disabled = ' '. " selectable,
l_node-isfolder = 'X'. " a folder,
l_node-expander = ' '. " have no '+' sign for expansion. LOOP AT l_spfli_tab INTO l_spfli.
AT NEW carrid.
l_node-node_key = l_spfli-carrid.
CLEAR l_node-relatkey.
CLEAR l_node-relatship.
l_node-text = l_spfli-carrid.
l_node-n_image = ' '.
l_node-exp_image = ' '.
APPEND l_node TO l_node_table.
ENDAT.
AT NEW connid.
l_node-node_key = l_spfli-carrid && l_spfli-connid.
l_node-relatkey = l_spfli-carrid.
l_node-relatship = cl_gui_simple_tree=>relat_last_child.
l_node-text = l_spfli-connid.
l_node-n_image = '@AV@'. "AV is the internal code
l_node-exp_image = '@AV@'. "for an airplane icon
ENDAT.
APPEND l_node TO l_node_table.
ENDLOOP. tree->add_nodes(
EXPORTING table_structure_name = 'ABDEMONODE'
node_table = l_node_table ).
ENDMETHOD. "fill_tree METHOD handle_node_double_click.
DATA: l_carrid TYPE spfli-carrid,
l_connid TYPE spfli-connid. l_carrid = node_key(2).
l_connid = node_key+2(4).
IF l_connid IS INITIAL.
fill_html( EXPORTING i_carrid = l_carrid ).
ELSE.
fill_list( EXPORTING i_carrid = l_carrid
i_connid = l_connid ).
ENDIF.
ENDMETHOD. "handle_node_double_click METHOD fill_html.
DATA l_url TYPE scarr-url. IF html_viewer IS INITIAL.
CREATE OBJECT html_viewer
EXPORTING parent = container_html.
ENDIF. SELECT SINGLE url
FROM scarr
WHERE carrid = @i_carrid
INTO @l_url. html_viewer->show_url(
EXPORTING url = l_url ).
ENDMETHOD. "fill_html METHOD fill_list.
DATA: l_flight_tab TYPE TABLE OF demofli,
BEGIN OF l_flight_title,
carrname TYPE scarr-carrname,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
END OF l_flight_title,
l_list_layout TYPE lvc_s_layo. IF container_box IS INITIAL.
CREATE OBJECT container_box
EXPORTING width = 250
height = 200
top = 100
left = 400
caption = 'Flight List'.
SET HANDLER close_box FOR container_box.
CREATE OBJECT list_viewer
EXPORTING i_parent = container_box.
ENDIF. SELECT SINGLE c~carrname, p~cityfrom, p~cityto
FROM ( scarr AS c
INNER JOIN spfli AS p ON c~carrid = p~carrid )
WHERE p~carrid = @i_carrid AND
p~connid = @i_connid
INTO CORRESPONDING FIELDS OF @l_flight_title. SELECT fldate, seatsmax, seatsocc
FROM sflight
WHERE carrid = @i_carrid AND connid = @i_connid
ORDER BY fldate
INTO CORRESPONDING FIELDS OF TABLE @l_flight_tab. l_list_layout-grid_title = l_flight_title-carrname && ` ` &&
i_connid && ` ` &&
l_flight_title-cityfrom && ` ` &&
l_flight_title-cityto. l_list_layout-smalltitle = 'X'. "The list title has small fonts,
l_list_layout-cwidth_opt = 'X'. "the column width is adjusted,
l_list_layout-no_toolbar = 'X'. "the toolbar is suppressed. list_viewer->set_table_for_first_display(
EXPORTING i_structure_name = 'DEMOFLI'
is_layout = l_list_layout
CHANGING it_outtab = l_flight_tab ).
ENDMETHOD. "fill_list METHOD close_box.
list_viewer->free( ).
container_box->free( ).
CLEAR: list_viewer,
container_box.
ENDMETHOD. "close_box ENDCLASS. "screen_handler IMPLEMENTATION *&---------------------------------------------------------------------*
*& Processing Blocks called by the Runtime Environment *
*&---------------------------------------------------------------------* * Event Block START-OF-SELECTION START-OF-SELECTION.
CALL SCREEN 100. * Dialog Module PBO MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
SET TITLEBAR 'TIT_100'.
screen_handler=>create_screen( ).
ENDMODULE. "status_0100 OUTPUT * Dialog Module PAI MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE. "cancel INPUT
Description
On the screen layout of screen 100 is a Custom Control named CUSTOM_CONTROL that covers the entire screen area. In the flow logic, both dialog modules STATUS_0100 and CANCEL are called at which the addition AT EXIT-COMMAND is used for PAI.
In GUI status SCREEN_100, the common symbols of the status bar are occupied with function codes of the type E. The PAI module only serves to exit the program. The most important action to PBO is calling the static method create_screen of the local class screen_handler, in which an object of this class is created.
The instance constructor of the class screen_handler generates container controls for a Picture Control and a Tree Control and afterwards both application controls.
- First, a Docking Control is created with the local reference variable l_docking. By transferring the constant dock_at_left of the class CL_GUI_DOCKING_CONTAINER to the parameter side, a new area is created on the left side of the screen with a width of 135 pixels.
- This screen area is split into two horizontal areas. This is achieved via the local reference variable l_splitter, which creates an object of the class CL_GUI_SPLITTER_CONTAINER and transfers the reference to the Docking Control to the parameter parent.
- Using the functional method get_container, the references to both areas of the splitter-control are determined in the local reference variables l_container_top and l_container_bottom . Afterwards, the application-controls Picture and Tree are generated, at which the parameter parent of each constructor receives one of the references to the areas of the splitter control.
By calling the method set_registered_events, the doubleclick event for the nodes of the tree are activated as system event. The method handle_node_double_click is registered as event handler.
When leaving the instance constructor, all reference variables are deleted. However, the control objects generated in the constructor with local reference variables are not collected by the garbage collection, as they are maintained by references from the CFW.
The method fill_picture imports an image file in GIF format from the MIME Repository into a byte string l_pict_wa, which is then filled into an internal table l_pict_tab. The function module DP_CREATE_URL generates an URL address for this table in the local variable l_url, which is passed to the method load_picture_from_url of the Picture Control.
The method fill_tree generates the tree structure of the tree control in the internal table l_node_table of the row structure ABDEMONODE. Every row of the table describes a node of the tree structure and must have a unique node key node_key for it. The components relatkey and relatship describe the relationships among the nodes.
The node table is generated from the content of the database table SPFLI. At the subnodes, the standard icons for non-expanded and expanded nodes are replaced with aircraft icons.
The event handler method handle_node_double_click imports the parameter node_key of the event node_double_click of the class CL_GUI_SIMPLE_TREE, which contains the key of the selected node. Depending on the content, the methods fill_html or fill_list are called.
When the method fill_html is called for the first time, it generates an object of the class CL_GUI_HTML_VIEWER and links the associated HTML control with the area of the container control to which the reference in container_html points (with the Custom Control on the screen). According to the selected node, the web address of an airline is read and handed over to the method show_url of the HTML control, by which the Homepage of the airline is displayed.
The method fill_list generates a dialog box container and an ALV Grid Control that is displayed in the dialog box. The event handler close_box is registered for the dialog box container. Activation using the method set_registered_events is not necessary here, as the event is activated by the class itself as system event when the object is generated. A list is generated for the selected nodes. By assigning values to some components of the structure l_list_layout of the type lvc_s_layo, it is determined that the list title in displayed in small format, and that the column width of the list is optimized, and that the list should not have an application toolbar. By calling the method set_table_for_first_display of the ALV Grid Control, the list is displayed in the dialog box.
You use the event handler method close_box to close the dialog box. To do this, you call the methods free of the concerned controls one after another and then initialize the respective reference variables. After that, if a node is selected to generate a list, both controls are created again in the method fill_list. All other controls of the program cannot be deleted by the user and will be available until the program ends.
Note
The class CL_SALV_TABLE and other classes with the prefix CL_SALV_ meanwhile offer more comfortable ways of displaying ALV Controls.
SAP 实例 4 CFW的更多相关文章
- SAP 实例 5 CFW Events
REPORT demo_custom_control . * Declarations ***************************************************** CL ...
- SAP 实例 8 HTML from the MIME Repository
REPORT demo_html_from_mime. CLASS mime_demo DEFINITION. PUBLIC SECTION. CLASS-METHODS main. PRIVATE ...
- SAP 实例 6 HTML input
REPORT demo_html_input. CLASS demo DEFINITION. PUBLIC SECTION. CLASS-METHODS main. PRIVATE SECTION. ...
- SAP 实例- 下拉框
效果图 源代码 REPORT rsdemo_dropdown_listbox . DATA init. TABLES scarr. TABLES spfli. TABLES sflight. TABL ...
- SAP 实例- 页签tabsrip
屏幕页签:项目上有一需求,对标准TCODE 一个屏幕增加一个页签.于是做了个例子. 下面屏幕有两个页签. 我们来看一下屏幕结构.100屏幕是主屏幕,101,102是子屏幕,对应页签test1,test ...
- SAP 实例 13 Random Grouping with LOOP
REPORT demo_loop_group_by_random. CLASS demo DEFINITION. PUBLIC SECTION. CLASS-METHODS: main, class_ ...
- SAP 实例 12 List Box with Value List from PBO Module
REPORT demo_dynpro_dropdown_listbox. DATA: name TYPE vrm_id, list TYPE vrm_values, value LIKE LINE O ...
- SAP 实例 10 List Box with value list from input help
*&---------------------------------------------------------------------* *& Report DEMO_DROP ...
- SAP 实例 9 Text output
REPORT demo_show_text. CLASS demo DEFINITION. PUBLIC SECTION. CLASS-METHODS main. ENDCLASS. CLASS de ...
随机推荐
- 2021-ACM-ICPC-济南站 K Search For Mafuyu 【树的遍历与回溯,dfs, 邻接表】
PAT 题目详情 (pintia.cn) 题目 题意描述 n个房间, 有n-1个通道, kanade初始在1,Mafuyu 位置未知,求K到M的最小期望,也就是到每个地方的平均值,注意的是这里的求法, ...
- MySQL启动过程详解三:Innodb存储引擎的启动
Innodb启动过程如下: 1. 初始化innobase_hton,它是一个handlerton类型的指针,以便在server层能够调用存储引擎的接口. 2. Innodb相关参数的检车和初始化,包括 ...
- html 移动端与PC端之间的转换
href 里面写路径 if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackB ...
- 技术分享 | WEB 端常见 Bug 解析
对于 WEB 产品来说,有一些常见的 Bug,本章节挑选一些比较典型的 Bug 进行举例介绍. UI Bug 页面展示的时候,需要根据长度的边界值去设计用例进行验证. 一般来说都会有超长内容的验证 ...
- B08. BootstrapBlazor实战 Menu 导航菜单使用(2)
接上篇: B08. BootstrapBlazor实战 Menu 导航菜单使用(1) 3.项目模板 节省时间,直接使用 Bootstrap Blazor App 模板快速搭建项目 传送门: https ...
- Django学习——Django测试环境搭建、单表查询关键字、神奇的双下划线查询(范围查询)、图书管理系统表设计、外键字段操作、跨表查询理论、基于对象的跨表查询、基于双下划线的跨表查询
Django测试环境搭建 ps: 1.pycharm连接数据库都需要提前下载对应的驱动 2.自带的sqlite3对日期格式数据不敏感 如果后续业务需要使用日期辅助筛选数据那么不推荐使用sqlite3 ...
- .net 项目使用 JSON Schema
.net 项目使用 JSON Schema 最近公司要做配置项的改造,要把appsettings.json的内容放到数据库,经过分析还是用json的方式存储最为方便,项目改动性最小,这就牵扯到一个问题 ...
- redis 2 主从和哨兵
主从: 概念:将一台redis服务器数据复制到其他redis服务器,前者是master,后者是slave.数据复制是单向,从主节点复制到从节点.master以写为主,slave以读为主一个zhu主节点 ...
- IX交换中心网络架构分析
拓扑如上 IX功能介绍 IX交换中心,客户接入交换中心只收取端口费用,在交换中心网内的流量不收取任何费用,一个交换中心是否值得接入主要看该ix所接入的用户 假如客户A是做视频网站,用的视频源是IQY的 ...
- mybatis plus 使用 SQL 保留字(关键字)
MybatisPlus:使用SQL保留字(关键字)的操作 必须要手动在 entity 的字段上加注解,否则最终会报错,因为 mybatis 或者 mybatis plus 不会自动处理