Functional ALV系列 (09) - 双击跳转到另外一个ALV

在查看数据的时候,不总是只有一个界面,为了让用户更方便地查看数据,需要根据当前的数据跳转到另外的界面中,比如查看明细等。本文演示 ALV 比较实用的功能:双击 ALV 单元格跳转到另外一个 ALV 中。

要实现的业务场景:报表首先显示航空公司信息,当用户点击航空公司 ID 所在字段的时候,跳转查看航空公司的航班信息。

ALV 常规的代码如下:

abap 复制代码
report  zfalv_dbl_click.

type-pools: slis.

data: gt_scarr type standard table of scarr,
      gs_scarr like line of gt_scarr.

data: gt_spfli type standard table of spfli,
      gs_spfli like line of gt_spfli.


start-of-selection.
  perform get_scarr_data.
  perform frm_disp_data.


*&---------------------------------------------------------------------*
*&      Form  get_scarr_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_scarr_data.
  select * from scarr
    into table gt_scarr.
endform.                    "get_scarr_data

*&---------------------------------------------------------------------*
*&      Form  get_spfli_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form get_spfli_data using p_carrid like scarr-carrid.
  select * from spfli
    into table gt_spfli
   where carrid = p_carrid.
endform.                    "get_spfli_data



*&---------------------------------------------------------------------*
*&      Form  frm_disp_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form frm_disp_data.
  data: lt_fieldcat type slis_t_fieldcat_alv,
        ls_fieldcat type slis_fieldcat_alv.

  clear lt_fieldcat[] .

  call function 'Z_FALV_FIELD_CATALOG'
    exporting
      it_output     = gt_scarr[]
    tables
      field_catalog = lt_fieldcat[].


  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      i_callback_program      = sy-repid
      i_callback_user_command = 'FRM_USER_COMMAND'
      it_fieldcat             = lt_fieldcat[]
    tables
      t_outtab                = gt_scarr[].
endform.                    "frm_disp_data

为了能处理双击事件,下面的代码是必须的:

然后在双击事件中处理跳转的逻辑:

abap 复制代码
form frm_user_command using r_ucomm like sy-ucomm
                  rs_selfield type slis_selfield
.
  case r_ucomm.
    when '&IC1'. " double click
      clear gs_scarr.
      read table gt_scarr into gs_scarr index rs_selfield-tabindex.
      check sy-subrc = 0.

      if rs_selfield-sel_tab_field = 'SCARR-CARRID'.
        perform get_spfli_data using gs_scarr-carrid.
        perform frm_disp_spfli_data.
      endif.
  endcase.
endform.                    "frm_user_command

源码

stonewm/abap-practice

说明:之前放在 gitee 上的代码由于不明原因个人对 repository 进行了删除,ABAP 博文关联的源码都会显示找不到。 github 上的链接仍然是有效的。

相关推荐
我是陈泽3 分钟前
一行 Python 代码能实现什么丧心病狂的功能?圣诞树源代码
开发语言·python·程序员·编程·python教程·python学习·python教学
优雅的小武先生13 分钟前
QT中的按钮控件和comboBox控件和spinBox控件无法点击的bug
开发语言·qt·bug
虽千万人 吾往矣20 分钟前
golang gorm
开发语言·数据库·后端·tcp/ip·golang
创作小达人22 分钟前
家政服务|基于springBoot的家政服务平台设计与实现(附项目源码+论文+数据库)
开发语言·python
郭二哈25 分钟前
C++——list
开发语言·c++·list
杨荧26 分钟前
【JAVA开源】基于Vue和SpringBoot的洗衣店订单管理系统
java·开发语言·vue.js·spring boot·spring cloud·开源
ZPC821032 分钟前
Python使用matplotlib绘制图形大全(曲线图、条形图、饼图等)
开发语言·python·matplotlib
镜花照无眠34 分钟前
Python爬虫使用实例-mdrama
开发语言·爬虫·python
aaasssdddd961 小时前
python和c
c语言·开发语言·python
星星法术嗲人1 小时前
【Java】—— 集合框架:Collections工具类的使用
java·开发语言