ABAP 选择屏幕按钮

2023-10-13 19:20:11 浏览数 (1)

导语:在做一些批导程序,或者程序附带配置表的时候,需要用到选择屏幕按钮,下面分享一下如何实现选择屏幕按钮。

一、定义选择屏幕按钮

选择屏幕按钮,SAP给预留了五个,也就是说最多可以定义五个,随着选择屏幕一起定义。

关键字:SELECTION-SCREEN FUNCTION KEY 1. 最多可以写到KEY 5.

代码语言:javascript复制
TABLES :t001,sscrfields.
SELECTION-SCREEN BEGIN OF BLOCK blc_001 WITH FRAME TITLE TEXT-001.
  PARAMETERS : p_werks TYPE werks_d.
  SELECT-OPTIONS : s_bukrs FOR t001-bukrs.
SELECTION-SCREEN END OF BLOCK blc_001.
"增加预留的选择屏幕按钮
SELECTION-SCREEN FUNCTION KEY 1.

二、在INITIALIZATION事件下给予按钮图标和名称

代码语言:javascript复制
INITIALIZATION."初始化

  PERFORM frm_botton.
*&---------------------------------------------------------------------*
*& Form frm_botton
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_botton .

  CLEAR functxt.
  functxt-icon_id   = icon_table_settings. "图标,可以通过ICON查找
  functxt-icon_text = '维护【学生信息表】'."描述
  sscrfields-functxt_01 = functxt.
  "如果还有其他按钮依次添加到functxt_02、functxt_03、functxt_04、functxt_05中

ENDFORM.

三、在AT SELECTION-SCREEN中实现按钮事件

代码语言:javascript复制
AT SELECTION-SCREEN.

  PERFORM frm_botton_command.
*&---------------------------------------------------------------------*
*& Form frm_botton_command
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_botton_command .
  "在相对应的按钮下写实现功能
  CASE sscrfields-ucomm..
    WHEN 'FC01'. "识别按钮
    WHEN 'FC02'. "识别按钮
    WHEN 'FC03'. "识别按钮
    WHEN 'FC04'. "识别按钮
    WHEN 'FC05'. "识别按钮
  ENDCASE.

ENDFORM.

四、完整代码

代码语言:javascript复制
TABLES :t001,sscrfields.
SELECTION-SCREEN BEGIN OF BLOCK blc_001 WITH FRAME TITLE TEXT-001.
  PARAMETERS : p_werks TYPE werks_d.
  SELECT-OPTIONS : s_bukrs FOR t001-bukrs.
SELECTION-SCREEN END OF BLOCK blc_001.
"增加预留的选择屏幕按钮
SELECTION-SCREEN FUNCTION KEY 1.

INITIALIZATION."初始化

  PERFORM frm_botton.

AT SELECTION-SCREEN.

  PERFORM frm_botton_command.

START-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form frm_botton
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_botton .

  CLEAR functxt.
  functxt-icon_id   = icon_table_settings."icon_view_form
  functxt-icon_text = '维护【学生信息表】'.
  sscrfields-functxt_01 = functxt.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_botton_command
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_botton_command .

  CASE sscrfields-ucomm..
    WHEN 'FC01'. "识别按钮

  ENDCASE.

ENDFORM.

0 人点赞