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 上的链接仍然是有效的。

相关推荐
aini_lovee几秒前
MATLAB基于小波技术的图像融合实现
开发语言·人工智能·matlab
R1nG86313 分钟前
多线程安全设计 CANN Runtime关键数据结构的锁优化
开发语言·cann
初次见面我叫泰隆14 分钟前
Qt——5、Qt系统相关
开发语言·qt·客户端开发
亓才孓19 分钟前
[Class的应用]获取类的信息
java·开发语言
开开心心就好27 分钟前
AI人声伴奏分离工具,离线提取伴奏K歌用
java·linux·开发语言·网络·人工智能·电脑·blender
Never_Satisfied31 分钟前
在JavaScript / HTML中,关于querySelectorAll方法
开发语言·javascript·html
3GPP仿真实验室1 小时前
【Matlab源码】6G候选波形:OFDM-IM 增强仿真平台 DM、CI
开发语言·matlab·ci/cd
devmoon1 小时前
在 Polkadot 上部署独立区块链Paseo 测试网实战部署指南
开发语言·安全·区块链·polkadot·erc-20·测试网·独立链
lili-felicity1 小时前
CANN流水线并行推理与资源调度优化
开发语言·人工智能
沐知全栈开发1 小时前
CSS3 边框:全面解析与实战技巧
开发语言