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

相关推荐
胡八一7 小时前
30 分钟上手 exp4j:在 Java 中安全、灵活地计算数学表达式
java·开发语言·安全
郝学胜-神的一滴7 小时前
Linux 进程控制块(PCB)解析:深入理解进程管理机制
linux·服务器·开发语言
后端小张7 小时前
【鸿蒙开发手册】重生之我要学习鸿蒙HarmonyOS开发
开发语言·学习·华为·架构·harmonyos·鸿蒙·鸿蒙系统
胖咕噜的稞达鸭7 小时前
AVL树手撕,超详细图文详解
c语言·开发语言·数据结构·c++·算法·visual studio
007php0078 小时前
百度面试题解析:synchronized、volatile、JMM内存模型、JVM运行时区域及堆和方法区(三)
java·开发语言·jvm·缓存·面试·golang·php
芒果量化8 小时前
Optuna - 自动调参利器&python实例
开发语言·python·算法·机器学习
foundbug9998 小时前
基于CSMA-CA协议的V2X通信MATLAB仿真
开发语言·网络·matlab
WangMing_X8 小时前
C#上位机软件:2.5 体验CLR实现多语言混合编程
java·开发语言·c#
jerryinwuhan8 小时前
pybullet入门到入门_1
开发语言·人工智能·python
豐儀麟阁贵9 小时前
4.4数组的基本操作
java·开发语言·数据结构·算法