开启掘金成长之旅!这是我参与「掘金日新计划 · 12 月更文挑战」的第7天,点击查看活动详情
序
HELLO ,这里是百里,一个学习中的ABAPER ,在SAP系统ALV报表展示中,经常会遇到下钻数据到新的关联报表或者标准界面展示内容.前篇讲述了下钻数据通过窗口展示关联ALV报表数据,此项内容存在优点也存在缺点,优点就是配置简单,展示内容不影响元数据内容可以横项对比展示. 缺点,就是无法过分定制化配置,如编辑,按钮,usercomed等数据内容都不可以使用.此项讲的内容就为在数据互动下钻基础上展示关联ALV,同时可以完全跟ALV内容一致,可以增加按钮及用户事件 .
下钻简介
在ALV报表展示中.会出现关键字段下钻,展示某个界面或者系统自带界面.此时需要给增加 user_command
事件. 下钻内容包括,展示具体某个界面,系统界面,与关键字对应的ALV界面.
技术介绍
本篇内容在ALV基础上,通过数据下钻关联字段内容展示新ALV数据.关键单就是刷新界面函数及用户事件操作.
代码语言:javascript复制"ALV展示报表数据配置"
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.
"CALL METHOD gs_grid->check_changed_data.
gs_glay-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_glay
is_layout_lvc = wa_layout
" i_grid_settings = gs_grid "新
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.
"用户事件子例程,通过获取单机行内容,将数据存入到内表数据,在进行操作"
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
*
WHEN '&IC1'.
CASE rs_selfield-fieldname.
WHEN 'ZROWTT' or 'DMBTR1' .
CHECK rs_selfield-value IS NOT INITIAL.
READ TABLE gt_data INDEX rs_selfield-tabindex INTO DATA(l_temp). "获取单击行
IF l_temp-zcashcode is NOT INITIAL .
PERFORM show_item USING l_temp-zcashcode .
ELSE .
MESSAGE '该行没有科目明细' TYPE 'I' .
ENDIF.
WHEN 'DMBTR2' .
CHECK rs_selfield-value IS NOT INITIAL.
READ TABLE gt_data INDEX rs_selfield-tabindex INTO DATA(l_temp2). "获取单击行
IF l_temp2-zcashcode is NOT INITIAL .
PERFORM show_item_sum USING l_temp2-zcashcode .
ELSE .
MESSAGE '该行没有科目明细' TYPE 'I' .
ENDIF .
endcase .
实例展示
本项实例是财务相关数据内容,ALV一内容展示科目汇总数据,下钻数据内容对应的科目明细内容,再次下钻内容为对应的行明细内容的详细表单 .
数据定义
代码语言:javascript复制TABLES : acdoca ,ZSSD001 .
"数据准备
"跳转data
TYPES : BEGIN OF ty_item_data ,
rbukrs TYPE bukrs , "公司代码
gjahr TYPE gjahr , "会计年度
poper TYPE poper , "会计期间
txt50 TYPE txt50_skat , "科目名称
racct TYPE racct , "会计科目
belnr TYPE belnr_d, "凭证编号
bktxt TYPE bktxt , "凭证抬头文本
zcashcode TYPE zcashcode , " 现金流量表项
zcstxt TYPE zcstxt , "现金流量表项描述
rtcur TYPE fins_currt, "货币
drcrk TYPE shkzg , "借贷标识
HSL TYPE fins_vtcur12 , "余额
BUDAT TYPE acdoca-BUDAT ,
BLDAT TYPE acdoca-BLDAT ,
BLART TYPE acdoca-BLART ,
USNAM TYPE acdoca-USNAM ,
END OF ty_item_data .
TYPES : BEGIN OF ty_DMBTR1 ,
ZCASHCODE type ZCASHCODE,
FISCYEARPER TYPE acdoca-FISCYEARPER,
gjahr TYPE gjahr ,
HSL TYPE FINS_VTCUR12 ,
END OF ty_DMBTR1 .
DATA : GT_item_Data TYPE TABLE of ty_item_data .
DATA : gs_dmbtr1 TYPE ty_DMBTR1 .
DATA : gt_dmbtr1 TYPE TABLE of ty_DMBTR1 .
获取数据
代码语言:javascript复制data : l_year_low TYPE gjahr .
data : l_year_high TYPE gjahr .
l_year_high = p_FISC-high 0(4) .
l_year_low = p_FISC-low 0(4) .
select ZCASHCODE, FISCYEARPER
,gjahr , SUM( HSL ) as HSL from ACDOCA
where
RLDNR = '0L' and RACCT >='1001000000' and RACCT <='1012999999'
and gjahr >= @l_year_low and gjahr <= @l_year_high
" and gjahr in @p_gjahr " and SUBSTRING( BUDAT , 1, 6 ) in @p_FISC "
" and FISCYEARPER in @p_FISC
and RBUKRS = @s_RBUKRS
GROUP BY ZCASHCODE,FISCYEARPER ,gjahr
into TABLE @gt_DMBTR1 .
SORT gt_DMBTR1 by ZCASHCODE FISCYEARPER gjahr .
一层数据展示
代码语言:javascript复制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.
"CALL METHOD gs_grid->check_changed_data.
gs_glay-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_glay
is_layout_lvc = wa_layout
" i_grid_settings = gs_grid "新
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.
二层数据展示
代码语言:javascript复制add_col 'RBUKRS' space space '公司代码' space space space space space.
add_col 'GJAHR' space space '会计年度' space space space space space.
add_col 'POPER' space space '会计期间' space space space space space.
add_col 'BUDAT' space space '过账日期' space space space space space.
add_col 'BLDAT' space space '凭证日期' space space space space space.
add_col 'USNAM' space space '用户名' space space space space space.
add_col 'BLART' space space '凭证类型' space space space space space.
add_col 'BELNR' space space '凭证编号' space space space space space.
add_col 'RACCT' space space '会计科目' space space space space space.
add_col 'TXT50' space space '科目名称' space space space space space.
add_col 'BKTXT' space space '凭证抬头文本' space space space space space.
add_col 'DRCRK' space space '借贷标识' space space space space space.
add_col 'RTCUR' space space '货币' space space space space space.
add_col 'HSL' space space '余额' space space space space space.
add_col 'ZCASHCODE' space space '现金流量表项' space space space space space.
add_col 'ZCSTXT' space space '现金流量表项描述' space space space space space.
g_layout-cwidth_opt = 'X'.
gs_glay-edt_cll_cb = abap_true. " 选中复选款,立刻触发data changed 事件 " 选中复选款,立刻触发data changed 事件
data : ls_msg TYPE char20 .
ls_msg = '现金流量表累计明细' . "&& zcashcode .
"MOVE-CORRESPONDING lt_zcashcode to GT_item_Data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_callback_pf_status_set = 'USER_STATUS'
i_callback_user_command = 'USER_COMMAND1'
* i_grid_settings = gs_glay
is_layout_lvc = g_layout
it_fieldcat_lvc = lt_fieldcat_item
i_default = 'X'
I_GRID_TITLE = '现金流量表累计明细'
i_save = ''
* it_events = gt_event
TABLES
t_outtab = GT_item_Data
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
"REFRESH lt_zcashcode .
CLEAR ls_msg .
ENDFORM.
FORM user_command1 USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
*
WHEN '&IC1'.
CASE rs_selfield-fieldname.
WHEN 'BELNR' .
CHECK rs_selfield-value IS NOT INITIAL.
READ TABLE GT_item_Data INDEX rs_selfield-tabindex INTO DATA(l_temp2). "获取单击行
SET PARAMETER ID 'BLN' FIELD rs_selfield-value.
SET PARAMETER ID 'BUK' FIELD l_temp2-RBUKRS.
SET PARAMETER ID 'GJR' FIELD l_temp2-GJAHR.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
ENDCASE .
ENDCASE .
endform .
结果
一级界面
下钻二级界面
再次下钻三级界面
技术总结
本篇文章讲解了数据在同一界面内多次下钻数据及二次下钻内容可附带用户操作及usercomd,hot等技术操作.通过学习本篇文章可以熟练应对工作中的多次下钻的业务需求.可以实现客户工作中的大部分需求 .
书卷多情似故人,晨昏忧乐每相亲.这里是百里一个努力的学习者.努力学习好好记录,点滴进步,就是成功.