首页 > 编程语言 >SAP dialog使用选择屏幕+容器展现 步骤+源码

SAP dialog使用选择屏幕+容器展现 步骤+源码

时间:2024-01-24 16:34:16浏览次数:39  
标签:dialog 源码 ui ls func alv grid SAP &-----------------------------------------

系统自带的选择都是单选的,但是需求不一定是单选的,那么需要和选择屏幕一样的范围选择要怎么做呢,以下是一个样例,通过查询物料号来展现物料表的数据。

9000屏幕

创建屏幕

设置屏幕类型

布局编辑

构建一个子屏幕subscreen用于防止选择屏幕,构建一个客制化容器contain用于存放查询结果展现

添加ok_code

9001子屏幕

SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN.
  SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME.
    SELECT-OPTIONS:
      s_matnr FOR mara-matnr.
  SELECTION-SCREEN: END OF BLOCK blk1.
SELECTION-SCREEN END OF SCREEN 9001.

9000 PBO&PAI

PROCESS BEFORE OUTPUT.
 MODULE STATUS_9000.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_9000.
 MODULE user_exit_9000 AT EXIT-COMMAND.

PBO

一般来说PBO 和 PAI 我会分成两个包含文件,也是后期维护的时候便于查找

MODULE status_9000 OUTPUT.
  SET PF-STATUS 'STANDARD_9000'.
  SET TITLEBAR 'TITLE_9000'.
ENDMODULE.

创建状态栏

其中注意以下 $exit 需要改成退出命令

创建标题

PAI

MODULE user_command_9000 INPUT.
  save_ok = ok_code.
  CLEAR:ok_code.

  CASE save_ok.
    WHEN '$BACK'.
      LEAVE TO SCREEN 0.
    WHEN '$ROLL'.
      LEAVE TO SCREEN 0.
    WHEN '$SEARCH'.
      PERFORM frm_get_data.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.

MODULE user_exit_9000 INPUT.
  LEAVE PROGRAM.
ENDMODULE.

将子屏幕放入9000屏幕中

代码变更

PROCESS BEFORE OUTPUT.
  CALL SUBSCREEN: subscreen INCLUDING sy-repid dynn_9001.
  MODULE status_9000.
*
PROCESS AFTER INPUT.
  CALL SUBSCREEN: subscreen.
  MODULE user_command_9000.
  MODULE user_exit_9000 AT EXIT-COMMAND.

选择屏幕展示

到了这里已经完成了一半的工作量了,使用dialog已经可以通过范围选择来进行数据查询了

获取数据

这里就简单的获取数据,展示两个字段即可

FORM frm_get_data .
  SELECT
    from mara
  FIELDS
    mara~matnr,
    mara~mtart
  where mara~matnr in @s_matnr
  INTO CORRESPONDING FIELDS OF TABLE @gt_mara.

ENDFORM.

定义并实例化内表

TYPES: BEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
       END OF ty_mara.

DATA: gt_mara TYPE STANDARD TABLE OF ty_mara.

构建展示容器

PBO代码更新

MODULE status_9000 OUTPUT.
  SET PF-STATUS 'STANDARD_9000'.
  SET TITLEBAR 'TITLE_9000'.
  PERFORM frm_screen.
ENDMODULE.

变量

DATA : wa_container        TYPE scrfname VALUE 'CONTAIN',
       alv_grid            TYPE REF TO cl_gui_alv_grid,
       wa_custom_container TYPE REF TO cl_gui_custom_container.

DATA: gt_fieldcat TYPE lvc_t_fcat,
      gs_layout   TYPE lvc_s_layo.

例程frm_screen

  PERFORM frm_set_layout.  "设置ALV输出格式
  PERFORM frm_set_fieldcat.  "设置ALV输出字段
  PERFORM frm_set_toolbar.   "设置alv状态栏

  IF wa_custom_container IS INITIAL .
    CREATE OBJECT wa_custom_container
      EXPORTING
        container_name = wa_container.

    CREATE OBJECT alv_grid
      EXPORTING
        i_parent = wa_custom_container.

    "实例化方法
*    CREATE OBJECT event_receiverundo.

    "新增按钮
*    SET HANDLER event_receiverundo->handle_toolbar_prod FOR alv_grid_prod.
*    SET HANDLER event_receiverundo->handle_ucomm FOR alv_grid_prod.

  ENDIF.

  CALL METHOD alv_grid->set_table_for_first_display
    EXPORTING
      i_structure_name     = 'GS_PROD'
      is_layout            = gs_layout
      it_toolbar_excluding = gt_ui_func
    CHANGING
      it_outtab            = gt_mara
      it_fieldcatalog      = gt_fieldcat.
  PERFORM frm_refresh_alv USING alv_grid.

例程frm_set_layout

FORM frm_set_layout .
  gs_layout = VALUE #( zebra = abap_on
                        cwidth_opt = abap_on ).
ENDFORM.

例程frm_set_fieldcat

FORM frm_set_fieldcat .
  
  DEFINE _set_fieldcat.
    APPEND VALUE #(
      fieldname = &1
      ref_table = &2
      ref_field = &3
      coltext = &4
      scrtext_l = &4
      scrtext_m = &4
      scrtext_s = &4
    ) TO gt_fieldcat.
  END-OF-DEFINITION.

  _set_fieldcat 'MATNR' 'MARA' 'MATNR' '物料号'. "
  _set_fieldcat 'MTART' 'MARA' 'MTART' '物料类型'. "

ENDFORM.

例程frm_set_toolbar

控制容器中alv的按钮

FORM frm_set_toolbar .
 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_refresh_alv

刷新容器中的数据

FORM frm_refresh_alv  USING pv_grid TYPE REF TO cl_gui_alv_grid.

  CALL METHOD pv_grid->check_changed_data. "检查ALV更改数据

  pv_grid->get_frontend_layout( IMPORTING es_layout = DATA(ls_layout) ).
  ls_layout-cwidth_opt = abap_on.
  pv_grid->set_frontend_layout( is_layout = ls_layout ).


  CALL METHOD cl_gui_control=>set_focus
    EXPORTING
      control = pv_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.
ENDFORM.

这样就完成了,下过如上面最初展示的那样

以下是源码提供

我这边分了几个包含文件和主文件

主文件代码

*&---------------------------------------------------------------------*
*& Report Y_PNJ_DEMO15
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT y_pnj_demo15.

INCLUDE y_pnj_demo015_top.
INCLUDE y_pnj_demo015_pbo.
INCLUDE y_pnj_demo015_pai.
INCLUDE y_pnj_demo015_per.

TABLES: mara.

"定义 9002的选择屏幕
SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN.
  SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME.
    SELECT-OPTIONS:
      s_matnr FOR mara-matnr.
  SELECTION-SCREEN: END OF BLOCK blk1.
SELECTION-SCREEN END OF SCREEN 9001.

*&---------------------------------------------------------------------*
*&INITIALIZATION/选择屏幕前初始化(选择屏幕展示之前执行)
*&---------------------------------------------------------------------*
INITIALIZATION .

*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN OUTPUT/选择屏幕控制(第二屏输出)
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT .

*&---------------------------------------------------------------------*
*& AT SELECTION-SCREEN/选择屏幕执行(参数输入检查)
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN .

*&---------------------------------------------------------------------*
*& START-OF-SELECTION/开始选择屏幕(点击执行按钮之后执行的语块)
*&---------------------------------------------------------------------*
START-OF-SELECTION .
  CALL SCREEN 9000.

*&---------------------------------------------------------------------*
*& END-OF-SELECTION/结束选择屏幕(程序结束处理,输出等)
*&---------------------------------------------------------------------*
END-OF-SELECTION .

*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .

  SELECT
    from mara
  FIELDS
    mara~matnr,
    mara~mtart
  where mara~matnr in @s_matnr
  INTO CORRESPONDING FIELDS OF TABLE @gt_mara.

ENDFORM.

Y_PNJ_DEMO015_TOP

变量文件

*&---------------------------------------------------------------------*
*& 包含               Y_PNJ_DEMO015_TOP
*&---------------------------------------------------------------------*

*&---Variable
DATA: ok_code TYPE sy-ucomm, " 用于接收屏幕操作
      save_ok TYPE sy-ucomm. " 接入屏幕操作 并清空ok_code

DATA: dynn_9001(4) VALUE '9001'.

TYPES: BEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
       END OF ty_mara.

DATA: gt_mara TYPE STANDARD TABLE OF ty_mara,
      gs_mara TYPE ty_mara.

"屏幕的容器
DATA : wa_container        TYPE scrfname VALUE 'CONTAIN',
       alv_grid            TYPE REF TO cl_gui_alv_grid,
       wa_custom_container TYPE REF TO cl_gui_custom_container.

DATA: gt_fieldcat TYPE lvc_t_fcat,
      gs_layout   TYPE lvc_s_layo.

DATA: gt_ui_func TYPE ui_functions. "隐藏alv菜单控件

Y_PNJ_DEMO015_PBO

PBO

*&---------------------------------------------------------------------*
*& 包含               Y_PNJ_DEMO015_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
  SET PF-STATUS 'STANDARD_9000'.
  SET TITLEBAR 'TITLE_9000'.
  PERFORM frm_screen.
ENDMODULE.

Y_PNJ_DEMO015_PAI

PAI

*&---------------------------------------------------------------------*
*& 包含               Y_PNJ_DEMO015_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
  save_ok = ok_code.
  CLEAR:ok_code.

  CASE save_ok.
    WHEN '$BACK'.
      LEAVE TO SCREEN 0.
    WHEN '$ROLL'.
      LEAVE TO SCREEN 0.
    WHEN '$SEARCH'.
      PERFORM frm_get_data.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.

*&---------------------------------------------------------------------*
*&      Module  USER_EXIT_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_exit_9000 INPUT.
  LEAVE PROGRAM.
ENDMODULE.

Y_PNJ_DEMO015_PER

例程

*&---------------------------------------------------------------------*
*& 包含               Y_PNJ_DEMO015_PER
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form frm_screen
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_screen .

  PERFORM frm_set_layout.  "设置ALV输出格式
  PERFORM frm_set_fieldcat.  "设置ALV输出字段
  PERFORM frm_set_toolbar.   "设置alv状态栏

  IF wa_custom_container IS INITIAL .
    CREATE OBJECT wa_custom_container
      EXPORTING
        container_name = wa_container.

    CREATE OBJECT alv_grid
      EXPORTING
        i_parent = wa_custom_container.

    "实例化方法
*    CREATE OBJECT event_receiverundo.

    "新增按钮
*    SET HANDLER event_receiverundo->handle_toolbar_prod FOR alv_grid_prod.
*    SET HANDLER event_receiverundo->handle_ucomm FOR alv_grid_prod.

    CALL METHOD alv_grid->set_table_for_first_display
      EXPORTING
        i_structure_name     = 'GS_MARA'
        is_layout            = gs_layout
        it_toolbar_excluding = gt_ui_func
      CHANGING
        it_outtab            = gt_mara
        it_fieldcatalog      = gt_fieldcat.
  ENDIF.

  PERFORM frm_refresh_alv USING alv_grid.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_layout
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_set_layout .
  gs_layout = VALUE #( zebra = abap_on
                        cwidth_opt = abap_on ).
ENDFORM.

*&---------------------------------------------------------------------*
*& Form frm_set_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_set_fieldcat .

  DEFINE _set_fieldcat.
    APPEND VALUE #(
      fieldname = &1
      ref_table = &2
      ref_field = &3
      coltext = &4
      scrtext_l = &4
      scrtext_m = &4
      scrtext_s = &4
    ) TO gt_fieldcat.
  END-OF-DEFINITION.

  _set_fieldcat 'MATNR' 'MARA' 'MATNR' '物料号'. "
  _set_fieldcat 'MTART' 'MARA' 'MTART' '物料类型'. "

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_toolbar
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_set_toolbar .
  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.
*&---------------------------------------------------------------------*
*& Form frm_refresh_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> ALV_GRID
*&---------------------------------------------------------------------*
FORM frm_refresh_alv  USING pv_grid TYPE REF TO cl_gui_alv_grid.

  CALL METHOD pv_grid->check_changed_data. "检查ALV更改数据

  pv_grid->get_frontend_layout( IMPORTING es_layout = DATA(ls_layout) ).
  ls_layout-cwidth_opt = abap_on.
  pv_grid->set_frontend_layout( is_layout = ls_layout ).


  CALL METHOD cl_gui_control=>set_focus
    EXPORTING
      control = pv_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.
ENDFORM.

标签:dialog,源码,ui,ls,func,alv,grid,SAP,&-----------------------------------------
From: https://www.cnblogs.com/pnj-owowa/p/17984569

相关文章

  • win10 下载 Chromium 源码并编译
      https://www.yangdx.com/2022/07/215.html 辅助看 https://blog.csdn.net/weixin_42081389/article/details/132127613 上面的走完,在编译的时候 下载ninja-win.zip下面放到pathhttps://github.com/ninja-build/ninja/releases cmd要管理员权限   报......
  • Nacos源码下载与运行
    早先在linux环境下搭建过nacos环境即Centos安装部署nacos实战,本次是从官网上下载源码,本地运行看看,记录过程,方便备查。第一步、Nacos源码下载推荐到nacos官网下载Github地址,本次选择最新版,1.4.7版本,可下载Sourcecode源码,解压即可,如下图所示。解压后的目标结构如下所示,关注conf......
  • 源码包的部署
    例:安装nginx1、解压nginx[root@fishman-160~]#tar-zxvfnginx-1.25.1.tar.gz2、编译[[email protected]]#./configure--prefix=/usr/local/nginx#prefiex指定安装路径checkingforOS+Linux4.18.0-500.el8.x86_64x86_64checkingforCcompiler........
  • 深入解析互联网医院APP开发流程与源码搭建
    本篇文章,深入解析互联网医院APP的开发流程,并提供关于源码搭建的一些建议。 一、确定需求与功能在开始互联网医院APP的开发之前,首先需要明确项目的需求和功能。这包括用户端的预约挂号、在线咨询、报告查看等功能,以及医生端的排班管理、病历查看等功能。确保需求明确,有助于后续的流......
  • Additional Information for Homogeneous System Copy on SAP HANA with Encrypted Ba
    SymptomAdditionalinformationwhenexecutingahomogeneoussystemcopyforanSAPsystemonSAPHANAwhenthedatabackupisencrypted.Ifadatarecovery stepperform_database_recovery_tenantfailswitherror:  SAPDBTechJDBC:[448]:recoverycouldnot......
  • openssh9.6 源码编译与交叉编译
    环境ubunut18.04。x86平台openssh9.6,这里我是要移植到别的机器。不是在本地使用所以我要编出两个版本x86和armubunutx86版本编译过程准备工作安装依赖库,可以通过apt包管理安装,也可以源码安装,我们这里需要zlib,openssl和pamlinux安装pam库centossudoyuminstall......
  • e4a开发的一款手机银行app虚拟转账回执单生成器源码分享下载 -23软件网
    编写一个虚拟转账回执单生成器的源码对于E4A(EasyforAndroid)开发环境来说是一个有趣的项目。E4A是一个简化Android应用开发的工具,它允许开发者使用较为简单的编程语言和工具来创建应用。以下是一个简单的示例代码,用于创建一个模拟的手机银行App中的虚拟转账回执单生成器。请注意......
  • e4a开发的一款同花顺股票持仓模拟器源码分享下载-24软件网
    确定应用的主要功能:模拟股票买卖、持仓展示、盈亏计算等。界面设计:清晰、直观的用户界面,方便用户操作。环境搭建:安装E4A开发环境,准备必要的库和工具。编写代码:界面设计:使用E4A的UI组件设计应用界面。数据处理:编写股票数据获取、处理的逻辑。模拟交易:实现买卖股票的逻辑,包括......
  • WhatsApp自动回复脚本:从入门到精通!
    在这个数字时代,社交媒体已经成为我们生活中不可或缺的一部分,特别是WhatsApp,这款全球流行的即时通讯工具,为我们提供了与亲朋好友、客户和业务伙伴之间即时交流的便利。但有时候,我们无法及时回复消息,或者想要实现某些自动化的操作,这时,WhatsApp自动回复脚本就显得尤为重要,那么,如何开发......
  • xgboost源码阅读
    xgboost分享介绍xgboost全称是extremeGradientBoosting,可以看做是GBDT算法(GradientBoostingDecisionTree)的高效实现。1.1Boosting思想Boosting方法训练基分类器时采用串行的方式,各个基分类器之间有依赖。它的基本思路是将基分类器层层叠加,每一层在训练的时候,对前一层......