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

相关推荐
侃侃_天下2 天前
最终的信号类
开发语言·c++·算法
echoarts2 天前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix2 天前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
每天回答3个问题2 天前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说2 天前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔2 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机
我是菜鸟0713号2 天前
Qt 中 OPC UA 通讯实战
开发语言·qt
JCBP_2 天前
QT(4)
开发语言·汇编·c++·qt·算法
Brookty2 天前
【JavaEE】线程安全-内存可见性、指令全排序
java·开发语言·后端·java-ee·线程安全·内存可见性·指令重排序
百锦再2 天前
[特殊字符] Python在CentOS系统执行深度指南
开发语言·python·plotly·django·centos·virtualenv·pygame