其他分享
首页 > 其他分享> > OOALV双屏界面互动

OOALV双屏界面互动

作者:互联网

最近根据用户要求,要将ALV表做成透视表样子。于是想到了OOALV的多屏展示。接着就是一顿万物互联操作,最终形成了一个简单DEMO。

首先做的就是创建程序,接着创建屏幕,接着在屏幕上画2个ALV框。分别取号名字,这里取con1\con2.

 

 

 

 PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE INIT_CON.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.

上面是屏幕代码,程序代码如下

REPORT ZMMR0093.
"使用画屏的方法的双屏DEMO
TYPE-POOLS: ICON.

TABLES: ZTMM006.
DATA GT_ITAB        TYPE STANDARD TABLE OF ZTMM006 .
DATA GS_ITAB        TYPE  ZTMM006 .
*DATA GT_PRINT       TYPE STANDARD TABLE OF EBAN .
DATA:BEGIN OF GS_PRINT OCCURS 0.
    INCLUDE STRUCTURE EBAN.
DATA:BOX(1).
DATA:END OF GS_PRINT.
DATA:GT_PRINT LIKE TABLE OF  GS_PRINT.

DATA:BEGIN OF GS_ITAB_HEAD OCCURS 0.
    INCLUDE STRUCTURE ZTMM006.
DATA:BOX(1).
DATA:END OF GS_ITAB_HEAD.

DATA:GT_ITAB_HEAD LIKE TABLE OF  GS_ITAB_HEAD.


DATA  CON1_REF TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA  CON2_REF TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA  G_GRID1 TYPE REF TO CL_GUI_ALV_GRID.
DATA  G_GRID2 TYPE REF TO CL_GUI_ALV_GRID.

"-------------------------------------
"-----------ALV1的HOTSPOT单击事件------------
"-------------------------------------
"1 定义ALV1的事件

CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS  HANDLE_CLICK
      FOR EVENT HOTSPOT_CLICK
      OF CL_GUI_ALV_GRID

      IMPORTING
          E_ROW_ID
          E_COLUMN_ID
          ES_ROW_NO.
ENDCLASS.

"2 事件的执行方法
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_CLICK.

    MESSAGE E_ROW_ID  TYPE 'S'.

    "清空原来的X
    LOOP AT GT_ITAB_HEAD INTO GS_ITAB_HEAD.
      GS_ITAB_HEAD-BOX = ''.
      MODIFY GT_ITAB_HEAD FROM GS_ITAB_HEAD.
    ENDLOOP.

    "补上当前行的X
    READ TABLE GT_ITAB_HEAD INTO GS_ITAB_HEAD INDEX E_ROW_ID.   "读取当前行
    GS_ITAB_HEAD-BOX = 'X'.
    MODIFY GT_ITAB_HEAD FROM GS_ITAB_HEAD INDEX E_ROW_ID.



    "刷新X
    DATA: LS_STABLE TYPE LVC_S_STBL.
    LS_STABLE-ROW = 'X'.
    LS_STABLE-COL = 'X'.


    CALL METHOD G_GRID1->REFRESH_TABLE_DISPLAY
      EXPORTING
        IS_STABLE      = LS_STABLE
        I_SOFT_REFRESH = 'X'.


    "准备和显示第二个ALV的数据
*    DATA GV_TZNUM LIKE  GT_ZSDT030-TZNUM.
    DATA: GV_TZNUM LIKE ZTMM006-BANFN.

    "得到用户选的一个数据
    LOOP AT GT_ITAB_HEAD INTO GS_ITAB_HEAD.

      IF GS_ITAB_HEAD-BOX = 'X'.

        GV_TZNUM = GS_ITAB_HEAD-BANFN.

      ENDIF.

    ENDLOOP.



    IF GV_TZNUM IS NOT INITIAL.

      SELECT *
      INTO CORRESPONDING FIELDS OF TABLE GT_PRINT
      FROM EBAN AS A
      WHERE A~BANFN = GV_TZNUM.


      DATA GS_LAYOUT2 TYPE LVC_S_LAYO.

      GS_LAYOUT2-CWIDTH_OPT = 'X'.
      GS_LAYOUT2-GRID_TITLE = '详细项目'.
      GS_LAYOUT2-SEL_MODE = 'B'.
      GS_LAYOUT2-ZEBRA = 'X'.



      CALL METHOD G_GRID2->SET_FRONTEND_LAYOUT
        EXPORTING
          IS_LAYOUT = GS_LAYOUT2.



      CALL METHOD G_GRID2->REFRESH_TABLE_DISPLAY
        EXPORTING
          IS_STABLE      = LS_STABLE
          I_SOFT_REFRESH = 'X'.

    ENDIF.
  ENDMETHOD.
ENDCLASS.


"3 事件引用变量
DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.



"-------------------------------------
"-----------ALV1的加图标事件----------
"-------------------------------------
"1 定义ALV1的事件

CLASS LCL_EVENT_RECEIVER2 DEFINITION.
  PUBLIC SECTION.
    METHODS  HANDLE_TOOLBAR
      FOR EVENT TOOLBAR
      OF CL_GUI_ALV_GRID

      IMPORTING E_OBJECT  E_INTERACTIVE.
ENDCLASS.


"2 事件的执行方法
CLASS LCL_EVENT_RECEIVER2 IMPLEMENTATION.
  METHOD HANDLE_TOOLBAR.

    DATA LS_TOOLBAR TYPE STB_BUTTON.

    CLEAR LS_TOOLBAR.
    LS_TOOLBAR-BUTN_TYPE = 3.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.



    CLEAR LS_TOOLBAR.
    LS_TOOLBAR-FUNCTION = 'MYSHEN'.
    LS_TOOLBAR-ICON = ICON_SET_STATE.
    LS_TOOLBAR-QUICKINFO = '审批确认'.
    LS_TOOLBAR-TEXT = '审批确认'.
    LS_TOOLBAR-DISABLED = ''.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

    CLEAR LS_TOOLBAR.
    LS_TOOLBAR-FUNCTION = 'MYSCAN'.
    LS_TOOLBAR-ICON = ICON_STORNO.
    LS_TOOLBAR-QUICKINFO = '取消审批'.
    LS_TOOLBAR-TEXT = '取消审批'.
    LS_TOOLBAR-DISABLED = ''.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.

    CLEAR LS_TOOLBAR.
    LS_TOOLBAR-FUNCTION = 'MYPRINT'.
    LS_TOOLBAR-ICON = ICON_PRINT.
    LS_TOOLBAR-QUICKINFO = '单据打印'.
    LS_TOOLBAR-TEXT = '单据打印'.
    LS_TOOLBAR-DISABLED = ''.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.


  ENDMETHOD.
ENDCLASS.


"3 事件引用变量
DATA EVENT_RECEIVER2 TYPE REF TO LCL_EVENT_RECEIVER2.


"-------------------------------------
"-----------ALV1的加按钮响应事件------
"-------------------------------------
"1 定义ALV1的事件

CLASS LCL_EVENT_RECEIVER3 DEFINITION.
  PUBLIC SECTION.
    METHODS  HANDLE_COMMAND
      FOR EVENT USER_COMMAND
      OF CL_GUI_ALV_GRID

      IMPORTING E_UCOMM.
ENDCLASS.


"2 事件的执行方法
CLASS LCL_EVENT_RECEIVER3 IMPLEMENTATION.
  METHOD HANDLE_COMMAND.

    CASE E_UCOMM.

      WHEN 'MYSHEN'.
        PERFORM SHENFORM.

      WHEN 'MYSCAN'.
        PERFORM  SCANCELFORM .

      WHEN 'MYPRINT'.
        PERFORM  PPPFORM .

    ENDCASE.

  ENDMETHOD.
ENDCLASS.

"3 事件引用变量
DATA EVENT_RECEIVER3 TYPE REF TO LCL_EVENT_RECEIVER3.

"选择屏幕
SELECT-OPTIONS GS_BANFN FOR ZTMM006-BANFN.  "三包索赔单号


START-OF-SELECTION.

  SELECT * FROM ZTMM006 INTO CORRESPONDING FIELDS OF TABLE GT_ITAB WHERE BANFN IN GS_BANFN.
  "为第一个控件准备数据

  LOOP AT GT_ITAB INTO GS_ITAB.

    MOVE GS_ITAB-BANFN  TO GS_ITAB_HEAD-BANFN.
    MOVE GS_ITAB-BNFPO  TO GS_ITAB_HEAD-BNFPO.
    MOVE GS_ITAB-ZFLAG_MSG  TO GS_ITAB_HEAD-ZFLAG_MSG.
    MOVE GS_ITAB-ZFLAG_DATE  TO GS_ITAB_HEAD-ZFLAG_DATE.
    MOVE GS_ITAB-ZFLAG_TIME  TO GS_ITAB_HEAD-ZFLAG_TIME.
    APPEND GS_ITAB_HEAD TO GT_ITAB_HEAD.
    CLEAR GS_ITAB_HEAD.
    CLEAR GS_ITAB.

  ENDLOOP.

  SORT GT_ITAB_HEAD.
  DELETE ADJACENT DUPLICATES FROM GT_ITAB_HEAD.

  CALL  SCREEN 100.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'TOPS'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  INIT_CON  OUTPUT
*&---------------------------------------------------------------------*
*       text 控件初始化模块
*----------------------------------------------------------------------*
MODULE INIT_CON OUTPUT.


  "---------第一个ALV控件-----------------
  IF CON1_REF IS INITIAL.

    DATA GS_LAYOUT1 TYPE LVC_S_LAYO.

    GS_LAYOUT1-CWIDTH_OPT = 'X'.
*    GS_LAYOUT1-GRID_TITLE = '三包索赔单'.
    GS_LAYOUT1-GRID_TITLE = '采购申请传输日志'.
    GS_LAYOUT1-SEL_MODE = 'B'.
    GS_LAYOUT1-ZEBRA = 'X'.


    DATA GT_FIELDCAT TYPE LVC_T_FCAT.
    DATA GS_FIELDCAT TYPE LVC_S_FCAT.

    GS_FIELDCAT-COL_POS   = 1. GS_FIELDCAT-FIELDNAME = 'BOX'.          GS_FIELDCAT-CHECKBOX = 'X'.    GS_FIELDCAT-HOTSPOT = 'X'.       APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
    GS_FIELDCAT-COL_POS   = 2. GS_FIELDCAT-FIELDNAME = 'BANFN'.        GS_FIELDCAT-COLTEXT = 'PR'.      APPEND GS_FIELDCAT TO GT_FIELDCAT. CLEAR GS_FIELDCAT.
    GS_FIELDCAT-COL_POS   = 3. GS_FIELDCAT-FIELDNAME = 'BNFPO'.        GS_FIELDCAT-COLTEXT = 'PRNO'.        APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
    GS_FIELDCAT-COL_POS   = 4. GS_FIELDCAT-FIELDNAME = 'ZFLAG_MSG'.        GS_FIELDCAT-COLTEXT = 'MESSAGE'.        APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
    GS_FIELDCAT-COL_POS   = 5. GS_FIELDCAT-FIELDNAME = 'ZFLAG_DATE'.        GS_FIELDCAT-COLTEXT = 'DATE'.        APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.
    GS_FIELDCAT-COL_POS   = 6. GS_FIELDCAT-FIELDNAME = 'ZFLAG_TIME'.        GS_FIELDCAT-COLTEXT = 'TIME'.        APPEND GS_FIELDCAT TO GT_FIELDCAT.CLEAR GS_FIELDCAT.

    CREATE OBJECT CON1_REF
      EXPORTING
        CONTAINER_NAME = 'CON1'.

    CREATE OBJECT G_GRID1
      EXPORTING
        I_PARENT = CON1_REF.


    "4 注册事件句柄,图标的还必须加在这里,不然不行
    CREATE OBJECT EVENT_RECEIVER2.
    SET HANDLER EVENT_RECEIVER2->HANDLE_TOOLBAR FOR G_GRID1.

    "4 注册事件句柄
    CREATE OBJECT EVENT_RECEIVER.
    SET HANDLER EVENT_RECEIVER->HANDLE_CLICK FOR G_GRID1.

    "4 注册事件句柄
    CREATE OBJECT EVENT_RECEIVER3.
    SET HANDLER EVENT_RECEIVER3->HANDLE_COMMAND FOR G_GRID1.


    CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        IS_LAYOUT       = GS_LAYOUT1
      CHANGING
        IT_OUTTAB       = GT_ITAB_HEAD
        IT_FIELDCATALOG = GT_FIELDCAT.

  ENDIF.

  "---------第二个ALV控件-----------------
  IF CON2_REF IS INITIAL.

    DATA GS_LAYOUT2 TYPE LVC_S_LAYO.

    GS_LAYOUT2-CWIDTH_OPT = 'X'.
    GS_LAYOUT2-GRID_TITLE = '采购申请详细项目'.
    GS_LAYOUT2-SEL_MODE = 'B'.
    GS_LAYOUT2-ZEBRA = 'X'.

    DATA GT_FIELDCAT2 TYPE LVC_T_FCAT.
    DATA GS_FIELDCAT2 TYPE LVC_S_FCAT.

    GS_FIELDCAT2-COL_POS   = 1. GS_FIELDCAT2-FIELDNAME = 'BOX'.          GS_FIELDCAT2-CHECKBOX = 'X'.    GS_FIELDCAT2-HOTSPOT = 'X'.       APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 2. GS_FIELDCAT2-FIELDNAME = 'BANFN'.        GS_FIELDCAT2-COLTEXT = 'PR号'.      APPEND GS_FIELDCAT2 TO GT_FIELDCAT2. CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 3. GS_FIELDCAT2-FIELDNAME = 'BNFPO'.        GS_FIELDCAT2-COLTEXT = 'PR行号'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 4. GS_FIELDCAT2-FIELDNAME = 'BSART'.        GS_FIELDCAT2-COLTEXT = '类型'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 5. GS_FIELDCAT2-FIELDNAME = 'BSTYP'.        GS_FIELDCAT2-COLTEXT = '型号'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 6. GS_FIELDCAT2-FIELDNAME = 'EKGRP'.        GS_FIELDCAT2-COLTEXT = '采购组'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 7. GS_FIELDCAT2-FIELDNAME = 'ERNAM'.        GS_FIELDCAT2-COLTEXT = '创建人'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 7. GS_FIELDCAT2-FIELDNAME = 'ERDAT'.        GS_FIELDCAT2-COLTEXT = '创建时间'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 8. GS_FIELDCAT2-FIELDNAME = 'MATNR'.        GS_FIELDCAT2-COLTEXT = '物料编码 '.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 9. GS_FIELDCAT2-FIELDNAME = 'TXZ01'.        GS_FIELDCAT2-COLTEXT = '物料描述'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.
    GS_FIELDCAT2-COL_POS   = 10. GS_FIELDCAT2-FIELDNAME = 'WERKS'.        GS_FIELDCAT2-COLTEXT = '工厂'.        APPEND GS_FIELDCAT2 TO GT_FIELDCAT2.CLEAR GS_FIELDCAT2.

    CREATE OBJECT CON2_REF
      EXPORTING
        CONTAINER_NAME = 'CON2'.

    CREATE OBJECT G_GRID2
      EXPORTING
        I_PARENT = CON2_REF.


    CALL METHOD G_GRID2->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        IS_LAYOUT       = GS_LAYOUT2
      CHANGING
        IT_OUTTAB       = GT_PRINT[]
        IT_FIELDCATALOG = GT_FIELDCAT2.


  ENDIF.

ENDMODULE.                 " INIT_CON  OUTPUT


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text 这个用户命令,是最上面的 【标准工具条】上的按钮
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.


  CASE SY-UCOMM.

    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'SCAN'.
      LEAVE TO SCREEN 0.
    WHEN OTHERS.

  ENDCASE.


ENDMODULE.                 " USER_COMMAND_0100  INPUT

"------------取消审批的FORM--------------------
FORM SCANCELFORM .
  MESSAGE '你点了取消审批按钮' TYPE 'I'.
ENDFORM.
"------------SHENFORM的FORM--------------------
FORM SHENFORM .
  MESSAGE '你点了审批按钮' TYPE 'I'.
ENDFORM .

"-------------打印FORM-----------------
FORM PPPFORM .
  MESSAGE '你点了打印按钮' TYPE 'I'.
ENDFORM.

 

 

 

 如果用不到新加的按钮  可以换成全选或者取消全选。

 

标签:ITAB,GT,界面,FIELDCAT,双屏,OOALV,GS,FIELDCAT2,TOOLBAR
来源: https://www.cnblogs.com/BruceKing/p/16489250.html