ALV双击单元格,进入另一个ALV界面

REPORT ztest_alv_two .
TYPE-POOLS : slis.
DATA: BEGIN OF gt_mara OCCURS 0,
      matnr LIKE mara-matnr,
      mtart LIKE mara-mtart,
      END OF gt_mara.
DATA: BEGIN OF gt_marc OCCURS 0,
      matnr LIKE marc-matnr,
      werks LIKE marc-werks,
      END OF gt_marc.

START-OF-SELECTION.
  PERFORM get_mara.
  PERFORM alv_display.
*&---------------------------------------------------------------------*
*&      Form  get_mara
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_mara.
  SELECT matnr mtart UP TO 10 ROWS INTO TABLE gt_mara FROM mara.
ENDFORM.                    " get_mara
*&---------------------------------------------------------------------*
*&      Form  alv_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM alv_display.
  DATA: ws_fieldcat       TYPE slis_t_fieldcat_alv WITH HEADER LINE,
       ws_fieldgroups_tab TYPE slis_t_sp_group_alv,
       ws_layout          TYPE slis_layout_alv,
       ws_sortfields_tab  TYPE slis_t_sortinfo_alv WITH HEADER LINE,
       ws_events          TYPE slis_t_event.
  DATA: v_repid LIKE sy-repid.
  DATA: nn TYPE i VALUE 0.
  DATA: title TYPE lvc_title.

  DEFINE hout.
    nn = nn + 1.
    ws_fieldcat-tabname   = 'GT_MARA'.
    ws_fieldcat-fieldname = '&1'.
    ws_fieldcat-seltext_m =  &2.
    ws_fieldcat-col_pos   =  nn.
    ws_fieldcat-outputlen =  &3.
    ws_fieldcat-datatype  = '&4'.
    ws_fieldcat-do_sum    = '&5'.
    ws_fieldcat-lzero     = 'X'.
    ws_fieldcat-no_zero   = 'X'.
    append ws_fieldcat.
    clear ws_fieldcat.
  END-OF-DEFINITION.
  hout matnr 'material'            18 char ''.
  hout mtart 'material group'         4 char ''.

  SORT gt_mara BY matnr  mtart.
  MOVE 'title' TO title.
  ws_layout-zebra        = 'X'.
  v_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = v_repid
      is_layout               = ws_layout
      it_fieldcat             = ws_fieldcat[]
      i_callback_user_command = 'USER_COMMAND'
      it_special_groups       = ws_fieldgroups_tab[]
      it_sort                 = ws_sortfields_tab[]
      it_events               = ws_events[]
      i_grid_title            = title
    TABLES
      t_outtab                = gt_mara
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.
ENDFORM.                    " alv_display
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield
.
  CASE r_ucomm.
    WHEN '&IC1'.
      IF rs_selfield-sel_tab_field = 'GT_MARA-MATNR'.
        PERFORM get_marc.
        PERFORM display_two.
      ENDIF.
  ENDCASE.
ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  get_marc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_marc.
  SELECT matnr werks INTO TABLE gt_marc FROM marc
                      FOR ALL ENTRIES IN gt_mara
                      WHERE matnr = gt_mara-matnr.
ENDFORM.                    " get_marc
*&---------------------------------------------------------------------*
*&      Form  display_two
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_two.
  DATA: ws_fieldcat       TYPE slis_t_fieldcat_alv WITH HEADER LINE,
       ws_fieldgroups_tab TYPE slis_t_sp_group_alv,
       ws_layout          TYPE slis_layout_alv,
       ws_sortfields_tab  TYPE slis_t_sortinfo_alv WITH HEADER LINE,
       ws_events          TYPE slis_t_event.
  DATA: v_repid LIKE sy-repid.
  DATA: nn TYPE i VALUE 0.
  DATA: title TYPE lvc_title.

  DEFINE hout.
    nn = nn + 1.
    ws_fieldcat-tabname   = 'GT_MARC'.
    ws_fieldcat-fieldname = '&1'.
    ws_fieldcat-seltext_m =  &2.
    ws_fieldcat-col_pos   =  nn.
    ws_fieldcat-outputlen =  &3.
    ws_fieldcat-datatype  = '&4'.
    ws_fieldcat-do_sum    = '&5'.
    ws_fieldcat-lzero     = 'X'.
    ws_fieldcat-no_zero   = 'X'.
    append ws_fieldcat.
    clear ws_fieldcat.
  END-OF-DEFINITION.
  hout matnr 'material'            18 char ''.
  hout werks 'plant'         4 char ''.

  SORT gt_marc BY matnr  werks.
  MOVE 'title2' TO title.
  ws_layout-zebra        = 'X'.
  v_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program = v_repid
            is_layout          = ws_layout
            it_fieldcat        = ws_fieldcat[]
*            I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
            it_special_groups  = ws_fieldgroups_tab[]
            it_sort            = ws_sortfields_tab[]
            it_events          = ws_events[]
            i_grid_title       = title
       TABLES
            t_outtab           = gt_marc
       EXCEPTIONS
            program_error      = 1
            OTHERS             = 2.
ENDFORM.                    " display_two


你可能感兴趣的:(ALV双击单元格,进入另一个ALV界面)