美文网首页
ABAP OO ALV实操

ABAP OO ALV实操

作者: JayDragon | 来源:发表于2022-01-12 15:00 被阅读0次

以前一直都是使用Function ALV实现报表需求,最近接到个需求,说是希望可以在手持设备上也能使用(具体怎么弄暂时不清楚),我就思索把选择界面和ALV放在一块显示,如下图:

执行&操作界面.png

自定义Screen 100,上面放置选择条件的子屏幕控件,下面放置展示ALV的容器控件:

屏幕制作器界面.png
子屏幕选择界面:
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
  SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: s_equnr FOR eqbs-equnr,    "设备号
                    s_kdauf FOR eqbs-kdauf,    "销售订单
                    s_kdpos FOR eqbs-kdpos.    "销售订单行项
    PARAMETERS: p_pcode TYPE zpp01-pcode, "整机序列号
                p_lgort TYPE mard-lgort.  "接收库位
  SELECTION-SCREEN END OF BLOCK bk1.
SELECTION-SCREEN END OF SCREEN 101.

Screen 100屏幕逻辑流:

PROCESS BEFORE OUTPUT.
  MODULE display_data.
  MODULE status_0100.
  CALL SUBSCREEN subscreen INCLUDING sy-repid '101'.

PROCESS AFTER INPUT.
  CALL SUBSCREEN subscreen.
  MODULE exit_command_0100 AT EXIT-COMMAND.
  MODULE user_command_0100.

Screen 100 PBO:

MODULE display_data OUTPUT.
  IF gr_container IS INITIAL.
    CREATE OBJECT gr_container
      EXPORTING
        container_name = 'ALV_CONTAINER'.
    CREATE OBJECT gr_grid
      EXPORTING
        i_parent = gr_container.
    "设置布局
    PERFORM frm_set_layout CHANGING gs_layout.
    "获取字段目录
    PERFORM frm_set_fieldcat CHANGING gt_fieldcat.
    CREATE OBJECT gr_event_handler.
    SET HANDLER gr_event_handler->handle_data_changed FOR gr_grid.
    SET HANDLER gr_event_handler->handle_toolbar      FOR gr_grid.
    SET HANDLER gr_event_handler->handle_user_command FOR gr_grid.
    CALL METHOD gr_grid->set_toolbar_interactive.
    "显示ALV
    CALL METHOD gr_grid->set_table_for_first_display
      EXPORTING
        is_layout       = gs_layout
      CHANGING
        it_outtab       = gt_outtab
        it_fieldcatalog = gt_fieldcat.
  ELSE.
    DATA: ls_layout TYPE lvc_s_layo.
    CALL METHOD gr_grid->get_frontend_layout
      IMPORTING
        es_layout = ls_layout.
    ls_layout-cwidth_opt = 'X'.    "最优宽
    CALL METHOD gr_grid->set_frontend_layout
      EXPORTING
        is_layout = ls_layout.
    CALL METHOD gr_grid->refresh_table_display.
  ENDIF.
ENDMODULE.

Screen 100 PAI:

MODULE user_command_0100 INPUT.
 save_ok = ok_code.
 CLEAR ok_code.
 CASE save_ok.
   WHEN '&EXEC'.
     PERFORM frm_get_data.
   WHEN OTHERS.
 ENDCASE.
ENDMODULE.

OO ALV状态栏按钮功能响应事件处理类:

CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS:
      handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
        IMPORTING er_data_changed,
      handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING e_object,
      handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING e_ucomm.
ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION.
  METHOD handle_data_changed.
    PERFORM frm_handle_data_changed USING er_data_changed.
  ENDMETHOD.
  METHOD handle_toolbar.
    PERFORM frm_set_toolbar CHANGING e_object.
  ENDMETHOD.
  METHOD handle_user_command.
    PERFORM frm_user_command USING e_ucomm.
  ENDMETHOD.
ENDCLASS.
DATA gr_event_handler TYPE REF TO lcl_event_handler.

设置工具栏按钮及响应按钮功能:

FORM frm_set_toolbar  CHANGING e_object TYPE REF TO cl_alv_event_toolbar_set.
  DATA ls_button TYPE stb_button.
  CLEAR e_object->mt_toolbar.
  CLEAR ls_button.
  ls_button-function  = '&ALL1'.
  ls_button-quickinfo = '全选'.
  ls_button-text      = '全选'.
  APPEND ls_button TO e_object->mt_toolbar.
  CLEAR ls_button.
  ls_button-function  = '&SAL1'.
  ls_button-quickinfo = '取消全选'.
  ls_button-text      = '取消全选'.
  APPEND ls_button TO e_object->mt_toolbar.
  CLEAR ls_button.
  ls_button-function  = '&POST'.
  ls_button-quickinfo = '移库过账'.
  ls_button-text      = '移库过账'.
  APPEND ls_button TO e_object->mt_toolbar.
ENDFORM.

FORM frm_user_command  USING    e_ucomm TYPE sy-ucomm.
  CASE e_ucomm.
    WHEN '&ALL1'.
      LOOP AT gt_outtab ASSIGNING FIELD-SYMBOL(<lfs_outtab>).
        <lfs_outtab>-check = 'X'.
      ENDLOOP.
    WHEN '&SAL1'.
      LOOP AT gt_outtab ASSIGNING <lfs_outtab>.
        <lfs_outtab>-check = ''.
      ENDLOOP.
    WHEN '&POST'.
      PERFORM frm_post.
    WHEN OTHERS.
  ENDCASE.
  DATA: ls_layout TYPE lvc_s_layo.
  CALL METHOD gr_grid->get_frontend_layout
    IMPORTING
      es_layout = ls_layout.
  ls_layout-cwidth_opt = 'X'.    "最优宽
  CALL METHOD gr_grid->set_frontend_layout
    EXPORTING
      is_layout = ls_layout.
  CALL METHOD gr_grid->check_changed_data.
  CALL METHOD gr_grid->refresh_table_display.
ENDFORM.

相关文章

  • ABAP OO ALV实操

    以前一直都是使用Function ALV实现报表需求,最近接到个需求,说是希望可以在手持设备上也能使用(具体怎么弄...

  • ABAP-ALV-OO

    OOALV 行、列和单元格颜色设置 OOALV 行、列和单元格颜色设置 OOALV中的CHECKBOX字段挺麻烦的...

  • ABAP-ALV-GRID

    ALV简单实例 ABAP ALV使用实例---sflight航班表及其效果界面ABAP:ALV List报表最后页...

  • ALV( SAP List Viewer)报表

    ALV简介 ALV-ABAP List Viewer,也称SAP List Viewer,这里姑且称之为ABA...

  • 2019-11-07关于oo alv后台job问题 alv不展示

    在oo alv执行后台job的时候今天发现一个问题 就是如果你前台执行这个oo alv 程序会出来,但是如果后台运...

  • 浅谈 SAP ABAP 系统里的 ALV 输出方式实现

    什么是 ALV?ALV 最初是 ABAP List Viewer 的缩写,但在 SAP 文档中找到的当前术语是 S...

  • OO ALV与FUNCTION ALV

    OO ALV OOALV中在AT SELECTION-SCREEN事件下使用SET_TABLE_FOR_FIRST...

  • 面相对象ALV(更新中)

    ALV的介绍: ALV是ABAP list Viewer的缩写,是实际业务中用来查询数据修改数据时经常使用的程序....

  • abap oo模板代码

    OO ALV是面向对象的ALV,在使用之前我们需创建一个control容器(屏幕),在通过CUSTOM_CONTA...

  • abap alv 事件

    alv 事件的创建使用 在实际开发中经常要用到 事件 event,在各个alv中的具体使用如下 REUSE_ALV...

网友评论

      本文标题:ABAP OO ALV实操

      本文链接:https://www.haomeiwen.com/subject/jgnbcrtx.html