如何在选择屏幕上进行动态展示屏幕字段,并且进行必输项检查控制
1. 选择屏幕定义
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_r1 TYPE c RADIOBUTTON GROUP grp USER-COMMAND uc DEFAULT 'X'. "核价申请
SELECTION-SCREEN COMMENT 2(23) TEXT-002 FOR FIELD p_r1.
PARAMETERS: p_r2 TYPE c RADIOBUTTON GROUP grp. "核价清单
SELECTION-SCREEN COMMENT 27(23) TEXT-003 FOR FIELD p_r2.
SELECTION-SCREEN END OF LINE.
PARAMETERS: p_vkorg TYPE vbak-vkorg MODIF ID md1.
SELECT-OPTIONS: s_zdjba FOR zsdt040a-zdjba MODIF ID md2 MATCHCODE OBJECT zdjba_esh, "核价单号
s_zhjrq FOR zsdt040a-zhjrq MODIF ID md2, "核价日期
s_kunnr FOR zsdt040a-kunnr MODIF ID md2, "客户
s_vkorg FOR zsdt040a-vkorg MODIF ID md2, "销售组织
s_status FOR zsdt040a-status MODIF ID md2. "审批状态
SELECTION-SCREEN END OF BLOCK b1.
注意:1. 需要给radio button指定功能码,比如上面程序代码中指定的功能码为uc
2. 需要对选择屏幕上需要进行动态显示的字段进行分组,哪些字段属于一组进行动态控制,可以通过modif id进行分组
2. 屏幕字段属性设置
INITIALIZATION.
PERFORM frm_init.
AT SELECTION-SCREEN OUTPUT.
PERFORM frm_set_attribute.
*&---------------------------------------------------------------------*
*& Form frm_init
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_init .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_attribute
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_set_attribute .
LOOP AT SCREEN.
IF p_r1 IS NOT INITIAL.
IF screen-group1 = 'MD2'.
screen-invisible = 1.
screen-active = 0.
screen-required = 0.
ELSE.
screen-invisible = 0.
screen-active = 1.
screen-required = 2.
ENDIF.
ELSE.
IF screen-group1 = 'MD1'.
screen-invisible = 1.
screen-active = 0.
ELSE.
screen-invisible = 0.
screen-active = 1.
IF screen-name = 'S_ZHJRQ-LOW'.
screen-required = 2.
ENDIF.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDFORM.
注意:1. 屏幕字段的显示与隐藏可以通过screen的属性invisible和active进行控制
2. 屏幕字段是否需要必输,可以通过screen的属性required进行控制,required有三个值:0和1和2,其中0表示不用必输,1表示必输且会进行必输检查,2也表示必输,但是只是展示必输的标识,但不会做必输检查,如果赋值为2要进行必输检查控制的话,需要单独在AT SELECTION-SCREEN中进行检查控制,选择2的目的是为了在点击radio button切换的时候,不会因为有必输的检查标识不能自动来回切换
3. 必输检查控制
AT SELECTION-SCREEN.
PERFORM frm_check_input.
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form frm_check_input
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_check_input .
IF sy-ucomm <> 'UC' AND
sy-ucomm <> '%011'.
IF p_r1 IS NOT INITIAL.
IF p_vkorg IS INITIAL.
IF sy-langu = '1'.
MESSAGE '在必填字段 "销售组织" 中进行输入' TYPE 'E'.
ELSE.
MESSAGE 'Make an entry in mandatory field "Sales Organization"' TYPE 'E'.
ENDIF.
ENDIF.
ELSE.
IF s_zhjrq[] IS INITIAL.
IF sy-langu = '1'.
MESSAGE '在必填字段 "核价日期" 中进行输入' TYPE 'E'.
ELSE.
MESSAGE 'Make an entry in mandatory field "Valuation date"' TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
注意:排除某些功能码的目的是为了,在触发这些功能码的时候,无需做必输的检查,比如上面代码中排除了radio button的功能码UC,所以在点击radio button按钮的时候,不会做在这个radio button展示的屏幕字段信息进行必输检查
效果图如下: