ALV之按照不同TCODE隐藏按钮
序
HELLO ,这里是百里,一个学习中的ABAPER,在工作中,我们会经常遇到代码复用,或者只需要一些修改就可以实现某些功能的需求. 或者相同界面,不同TCODE显示不同的功能按键.来解决不同公司的业务场景. 此时就用到了今天的需求,隐藏不同的TCODE按钮.
什么是隐藏按钮
们昨天讲了增加按钮,那么讲一下如何隐藏按钮. 隐藏按钮的动作是按照不同业务场景实现对应的业务功能,比如实际场景中,我们一个ALV中过账的区别,针对所有数据,A按钮过账A公司的数据,B按钮过账B公司的数据,C按钮过账C 公司数据. 或者当触发某个条件时我们就不显示什么按钮.
技术解析
我们主要是通过调用slis_t_extab
中的函数,实现将传入的按钮内容隐藏的效果.
DATA : lw_tab LIKE LINE OF rt_extab.
lw_tab-fcode = '&按钮名称1'.
APPEND lw_tab TO rt_extab.
lw_tab-fcode = '&按钮名称2'.
APPEND lw_tab TO rt_extab
SET PF-STATUS 'STD' EXCLUDING rt_extab. .
实例讲解
本案例主要讲述内容是在ALV展示界面中增加3个按钮,通过配置将两个按钮隐藏,从而达到实现效果.
数据准备
" 数据准备
TYPES : BEGIN OF ty_Data ,
DOCCODE TYPE char20 ,
ZROWID TYPE char20 ,
MATCODE TYPE char20 ,
MATNAME TYPE char20 ,
UOM TYPE char20 ,
MEMO TYPE char20 ,
message TYPE char20 ,
END OF ty_Data .
data : gs_Data TYPE ty_Data .
data : gt_data TYPE TABLE of ty_Data .
" alv 通用变量
DATA: wa_layout TYPE lvc_s_layo.
DATA:wa_fieldcat TYPE lvc_s_fcat,
gt_fieldcat TYPE lvc_t_fcat.
DATA gs_grid TYPE lvc_s_glay. "新
选择屏幕
" 选择屏幕
SELECTION-SCREEN BEGIN OF BLOCK block WITH FRAME TITLE text-001 .
PARAMETERS : p_text TYPE char20 .
SELECTION-SCREEN END OF BLOCK block .
子例程设定
FORM get_Data .
select * from ZWDEMOTABLE1 AS A INTO CORRESPONDING FIELDS OF TABLE @gt_datA .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form diaplay_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM diaplay_data .
PERFORM set_alv_layout.
PERFORM bulid_fieldcat.
PERFORM call_alv_func.
ENDFORM.
FORM set_alv_layout .
CLEAR: wa_layout.
wa_layout-zebra = 'X'. "斑马线
wa_layout-cwidth_opt = 'X'. "自动列宽
ENDFORM.
*&---------------------------------------------------------------------*
*& Form bulid_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM bulid_fieldcat .
DEFINE add_col.
* ADD 1 TO pos.
* lw_fieldcat-col_pos = pos.
wa_fieldcat-fieldname = &1.
wa_fieldcat-ref_field = &2.
wa_fieldcat-ref_table = &3.
wa_fieldcat-scrtext_l = &4.
wa_fieldcat-outputlen = &5.
wa_fieldcat-no_zero = &6.
wa_fieldcat-edit = &7.
wa_fieldcat-edit_mask = &8.
wa_fieldcat-key = &9.
CASE wa_fieldcat-fieldname.
WHEN OTHERS.
ENDCASE .
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR : wa_fieldcat.
END-OF-DEFINITION.
REFRESH: gt_fieldcat.
" add_col 'slbox' space space '选项' space space space space space.
add_col 'DOCCODE' space space '单号' space space space space space.
add_col 'ZROWID' space space 'zrowid' space space space space space.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form call_alv_func
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM call_alv_func .
DATA :gt_event TYPE slis_t_event,
gs_event TYPE slis_alv_event.
" MOVE 'DATA_CHANGED' TO gs_event-name.
" MOVE 'ALV_DATA_CHANGED' TO gs_event-form.
APPEND gs_event TO gt_event.
gs_grid-edt_cll_cb = abap_true. " 选中复选款,立刻触发data changed 事件
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid "回调程序
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
i_grid_settings = gs_grid
is_layout_lvc = wa_layout
it_fieldcat_lvc = gt_fieldcat "需要显示的内表的列
i_save = 'A'
it_events = gt_event
TABLES
t_outtab = gt_DAta "需要显示的数据
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM.
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
DATA : lw_tab LIKE LINE OF rt_extab.
REFRESH rt_extab.
IF p_text = '1' .
" 删除按钮
lw_tab-fcode = 'DEMO1'.
APPEND lw_tab TO rt_extab.
ENDIF.
IF p_text = '2' .
" 删除按钮
lw_tab-fcode = 'DEMO2'.
APPEND lw_tab TO rt_extab.
ENDIF.
IF p_text = '3' .
" 删除按钮
lw_tab-fcode = 'DEMO3'.
APPEND lw_tab TO rt_extab.
ENDIF.
SET PF-STATUS 'STD' EXCLUDING rt_extab.
" SET TITLEBAR 'TIT_1000'.
ENDFORM.
调用子例程
INITIALIZATION .
AT SELECTION-SCREEN .
START-OF-SELECTION .
PERFORM get_Data .
ENd-OF-SELECTION .
PERFORM diaplay_data.
结果
我们在选择屏幕界面通过配置内容,从而实现按钮的显示及隐藏
选择屏幕额界面
当我们输入 1 时, 隐藏1显示demo2 ,demo3
当我们输入2 时, 隐藏2 显示demo1 ,demo3
以上实现我们所需功能.
技术总结
今天讲的内容是,在工作中常用的隐藏ALV界面当中的按钮, 学会此需求以后可以应对当同一ALV界面根据权限显示不同按钮的需求. 活灵活用以解决更多问题.
百里鸡汤
春读书,兴味长,磨其砚,笔花香。读书求学不宜懒,天地日月比人忙。燕语莺歌希领悟,桃红李白写文章。寸阳分阴须爱惜,休负春色与时光。——熊伯伊《四季读书歌·春》
这里是百里,一个努力的学习者. 努力学习好好记录,点滴进步,就是成功.
- 点赞
- 收藏
- 关注作者
评论(0)