前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >matinal:SAP ABAP ALV 屏幕分割splitter的用法解析【代码直接可用】

matinal:SAP ABAP ALV 屏幕分割splitter的用法解析【代码直接可用】

作者头像
matinal
发布2023-10-14 15:10:35
4760
发布2023-10-14 15:10:35
举报
文章被收录于专栏:SAP Technical
代码语言:javascript
复制
REPORT y4_b4_test20.

TABLES: sflight.

"抬头数据输出
TYPES: BEGIN OF ty_head.
         INCLUDE TYPE scarr.
TYPES:   slbox   TYPE c,
         light   TYPE icon_d,
         message TYPE string,
       END OF ty_head.

DATA: gt_head TYPE TABLE OF ty_head,
      gs_head TYPE ty_head.

"行项目数据输出
TYPES: BEGIN OF ty_item.
         INCLUDE TYPE sflight.
TYPES:   slbox   TYPE c,
         light   TYPE icon_d,
         message TYPE string,
       END OF ty_item.

DATA: gt_item TYPE TABLE OF ty_item,
      gs_item TYPE ty_item.

DATA:g_cust_con    TYPE REF TO cl_gui_custom_container.

"字段属性定义
DATA: gs_fcat TYPE lvc_s_fcat.
DATA: gt_fcat_h TYPE lvc_t_fcat,
      gt_fcat_i TYPE lvc_t_fcat.
DATA: gs_layout_h TYPE lvc_s_layo,
      gs_layout_i TYPE lvc_s_layo.
DATA: gs_variant_h TYPE disvariant,
      gs_variant_i TYPE disvariant,
      gv_colno     TYPE i.
DATA: gt_ui_func TYPE ui_functions. "隐藏alv菜单控件

DATA: ok_code TYPE sy-ucomm. "用户功能码接收
DATA: save_ok TYPE sy-ucomm. "用户功能码接收

"ALV grid
DATA: gs_dock        TYPE REF TO cl_gui_docking_container,
      gs_splitter    TYPE REF TO cl_gui_splitter_container, "分割屏幕类
      gs_container_h TYPE REF TO cl_gui_container, "抬头容器
      gs_container_i TYPE REF TO cl_gui_container, "行项目容器
      gs_grid_h      TYPE REF TO cl_gui_alv_grid, "抬头屏幕对象类
      gs_grid_i      TYPE REF TO cl_gui_alv_grid. "行项目屏幕对象类

CONSTANTS: gc_h   TYPE c VALUE 'H'. "抬头标识符
CONSTANTS: gc_i  TYPE c VALUE 'I'. "行项目标识符

"选择屏幕
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
  SELECT-OPTIONS: s_carrid FOR sflight-carrid.
SELECTION-SCREEN END OF BLOCK blk1 .

START-OF-SELECTION.
  "取数
  PERFORM frm_select_data.

END-OF-SELECTION.
  "输出屏幕准备
  PERFORM frm_prepare_alv.
  "调用100屏幕输出
  CALL SCREEN 0100.

MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR 'MAINTITLE' WITH 'OOALV分割'.
ENDMODULE.

MODULE pai INPUT.
  save_ok = ok_code.
  CLEAR ok_code.

  CASE save_ok.
    WHEN '&F03' OR '&F12' OR '&F15'.
      LEAVE TO SCREEN 0. "返回上一个屏幕
    WHEN OTHERS.
  ENDCASE.

ENDMODULE.

MODULE init_alv OUTPUT.

  IF gs_dock IS INITIAL.
    "屏幕分割
    PERFORM frm_split_screen.

    "创建alv grid
    PERFORM frm_create_grid.

    "显示数据
    PERFORM frm_display_alv USING gc_h gs_grid_h.
    PERFORM frm_display_alv USING gc_i gs_grid_i.

  ELSE.
    "alv 刷新
    PERFORM frm_refresh_alv USING gs_grid_h.
    PERFORM frm_refresh_alv USING gs_grid_i.
  ENDIF.

ENDMODULE.

FORM frm_select_data .

  SELECT *
    FROM scarr
    INTO CORRESPONDING FIELDS OF TABLE gt_head
    WHERE carrid IN s_carrid.

  SELECT *
    FROM sflight
    INTO CORRESPONDING FIELDS OF TABLE gt_item
    WHERE carrid IN s_carrid.

ENDFORM.

FORM frm_prepare_alv .
* ALV字段属性
  PERFORM frm_build_fieldcat.

* 屏幕隐藏按钮
  PERFORM frm_build_ui_functions.

* 屏幕布局
  PERFORM frm_set_layout.

* 屏幕自定义布局参数
  PERFORM frm_set_variant.

ENDFORM.

FORM frm_build_fieldcat .
  DEFINE m_fcat_0100.
    CLEAR gs_fcat.
    gs_fcat-fieldname = &1.
    gs_fcat-ref_field = &2.
    gs_fcat-ref_table = &3.
    gs_fcat-coltext   =
    gs_fcat-seltext   =
    gs_fcat-tooltip   =
    gs_fcat-reptext   =
    gs_fcat-scrtext_l = &4.
    gs_fcat-checkbox  = &5.
    gs_fcat-edit      = &6.
    gs_fcat-hotspot       = &7.
    gv_colno          = gv_colno + 1.
    gs_fcat-col_pos   = gv_colno.
    CASE &8.
      WHEN gc_h.
        APPEND gs_fcat TO gt_fcat_h.
      WHEN gc_i.
        APPEND gs_fcat TO gt_fcat_i.
      WHEN OTHERS.
    ENDCASE.

  END-OF-DEFINITION.


  REFRESH: gt_fcat_h.
  CLEAR: gv_colno.

* 抬头屏幕字段
  m_fcat_0100 'CARRID' '' '' '航线代码' '' '' '' gc_h.
  m_fcat_0100 'CARRNAME' '' '' '航线名称' '' '' '' gc_h.
  m_fcat_0100 'CURRCODE' '' '' '航班的本地货币' '' '' '' gc_h.
  m_fcat_0100 'URL' '' '' '航线 URL' '' '' '' gc_h.

  REFRESH: gt_fcat_i.
  CLEAR: gv_colno.
* 行项目屏幕字段
  m_fcat_0100 'CARRID' '' '' '航线代码' '' '' '' gc_i.
  m_fcat_0100 'CONNID' '' '' '航班连接编号' '' '' '' gc_i.
  m_fcat_0100 'FLDATE' '' '' '航班日期' '' '' '' gc_i.
  m_fcat_0100 'PRICE' '' '' '航空运费' '' '' '' gc_i.
  m_fcat_0100 'CURRENCY' '' '' '航班的本地货币' '' '' '' gc_i.
  m_fcat_0100 'PLANETYPE' '' '' '飞机类型' '' '' '' gc_i.
  m_fcat_0100 'SEATSMAX' '' '' '经济舱的最大容量' '' '' '' gc_i.
  m_fcat_0100 'SEATSOCC' '' '' '占据的经济舱座位' '' '' '' gc_i.
  m_fcat_0100 'PAYMENTSUM' '' '' '当前预定总数' '' '' '' gc_i.
  m_fcat_0100 'SEATSMAX_B' '' '' '商务舱的最大容量' '' '' '' gc_i.
  m_fcat_0100 'SEATSOCC_B' '' '' '占据的商务舱座位' '' '' '' gc_i.
  m_fcat_0100 'SEATSMAX_F' '' '' '头等舱的最大容量' '' '' '' gc_i.
  m_fcat_0100 'SEATSOCC_F' '' '' '占据的头等舱座位' '' '' '' gc_i.

ENDFORM.

FORM frm_build_ui_functions.

  DATA: ls_ui_func TYPE ui_func.

  REFRESH: gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_copy .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_copy_row .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_cut .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_refresh .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_move_row .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_paste .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_paste_new_row .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_undo .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_pc_file .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_delete_row .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_insert_row .
  APPEND ls_ui_func TO gt_ui_func.
  ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_append_row.
  APPEND ls_ui_func TO gt_ui_func.

ENDFORM. " FRM_BUILD_UI_FUNCTIONS

FORM frm_set_layout .

  CLEAR: gs_layout_h.
  gs_layout_h-zebra      = 'X'.        "striped pattern
  gs_layout_h-cwidth_opt = 'X'.        "Optimized width

  gs_layout_i = gs_layout_h.

ENDFORM. " FRM_SET_LAYOUT

FORM frm_set_variant .

  "用于区分抬头和项目的布局

  CLEAR: gs_variant_h.
  gs_variant_h-handle = '1001'.
  gs_variant_h-report = sy-repid.

  CLEAR: gs_variant_i.
  gs_variant_i-handle = '2001'.
  gs_variant_i-report = sy-repid.

ENDFORM. " FRM_SET_VARIANT

FORM frm_split_screen.

****************开始*******************
  "创建屏幕容器:comtainer
*  CREATE OBJECT gs_dock
*    EXPORTING
*      repid                       = sy-repid
*      dynnr                       = '0100'
**     side                        = cl_gui_docking_container=>property_floating
*      side                        = cl_gui_docking_container=>dock_at_left
*      extension                   = 200
*      metric                      = 0
*      ratio                       = 95
*    EXCEPTIONS
*      cntl_error                  = 1
*      cntl_system_error           = 2
*      create_error                = 3
*      lifetime_error              = 4
*      lifetime_dynpro_dynpro_link = 5
*      OTHERS                      = 6.
*  IF sy-subrc <> 0.
*    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*  ENDIF.

*  CREATE OBJECT gs_splitter
*    EXPORTING
*      parent  = gs_dock
*      rows    = 2
*      columns = 1.

*********************结束***********************

****************开始*******************
  IF g_cust_con IS INITIAL.
    CREATE OBJECT g_cust_con
      EXPORTING
        container_name = 'GC_CON'.
  ENDIF.

*拆分成二行一列部分*
  CREATE OBJECT gs_splitter
    EXPORTING
      parent  = g_cust_con
      rows    = 2
      columns = 1.
*********************结束***********************

*第一行一列*
  CALL METHOD gs_splitter->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = gs_container_h.

*第二行一列*
  CALL METHOD gs_splitter->get_container
    EXPORTING
      row       = 2
      column    = 1
    RECEIVING
      container = gs_container_i.

ENDFORM.

FORM frm_create_grid .

  "创建抬头屏幕对象
  CREATE OBJECT gs_grid_h
    EXPORTING
      i_parent = gs_container_h.

  "准备输入事件
  CALL METHOD gs_grid_h->set_ready_for_input
    EXPORTING
      i_ready_for_input = 1.

  "check data changed
  CALL METHOD gs_grid_h->check_changed_data.

  "数据变更事件
  CALL METHOD gs_grid_h->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_modified.

  "创建行项目屏幕对象
  CREATE OBJECT gs_grid_i
    EXPORTING
      i_parent = gs_container_i.

ENDFORM. " FRM_CREATE_GRID

FORM frm_display_alv USING pv_flg TYPE c
                           pv_grid TYPE REF TO cl_gui_alv_grid .

  CASE pv_flg.
    WHEN gc_h.

      CALL METHOD pv_grid->set_table_for_first_display
        EXPORTING
*         I_CONSISTENCY_CHECK           = 'X'
          is_variant                    = gs_variant_h
          it_toolbar_excluding          = gt_ui_func
          i_save                        = 'A'
          i_default                     = 'X' "允许定义默认布局
          is_layout                     = gs_layout_h
        CHANGING
          it_outtab                     = gt_head
          it_fieldcatalog               = gt_fcat_h
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    WHEN gc_i.

      CALL METHOD pv_grid->set_table_for_first_display
        EXPORTING
*         I_CONSISTENCY_CHECK           = 'X'
          is_variant                    = gs_variant_i
          it_toolbar_excluding          = gt_ui_func
          i_save                        = 'A'
          i_default                     = 'X' "允许定义默认布局
          is_layout                     = gs_layout_i
        CHANGING
          it_outtab                     = gt_item
          it_fieldcatalog               = gt_fcat_i
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.

    WHEN OTHERS.
  ENDCASE.

ENDFORM. " FRM_DISPLAY_ALV

FORM frm_refresh_alv USING pv_grid TYPE REF TO cl_gui_alv_grid.

  "刷新变量
  DATA: ls_stable TYPE lvc_s_stbl.

  "刷新显示
  CLEAR ls_stable.
  ls_stable-row = 'X'."基于行刷新
  ls_stable-col = 'X'."基于列刷新
  CALL METHOD pv_grid->refresh_table_display
    EXPORTING
      is_stable = ls_stable
    EXCEPTIONS
      finished  = 0
      OTHERS    = 0.

ENDFORM. " FRM_REFRESH_ALV

代码语言:javascript
复制
*100屏幕
PROCESS BEFORE OUTPUT.
  MODULE pbo .
  MODULE init_alv .

PROCESS AFTER INPUT.
  MODULE pai .
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档