ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ALV小结之三:多层显示ALV

ALV小结之三:多层显示ALV

原创 Linux操作系统 作者:qy1141 时间:2009-06-03 14:01:26 0 删除 编辑

ALV实现多层显示,先看效果图:

源码如下:

TABLES : aufk,
         afih.

TYPE-POOLS: slis.

DATA: BEGIN OF headertab OCCURS 0,
       aufnr LIKE aufk-aufnr,
       auart LIKE aufk-auart,
       autyp LIKE aufk-autyp,
      END OF headertab.

DATA: BEGIN OF itemtab OCCURS 0,
        aufnr LIKE afih-aufnr,
        equnr LIKE afih-equnr,
        iwerk LIKE afih-iwerk,
        ilart LIKE afih-ilart,
        qmnum LIKE afih-qmnum,
      END OF itemtab.

DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: v_repid LIKE sy-repid.
DATA: g_tabname_header TYPE slis_tabname,
      g_tabname_item   TYPE slis_tabname,
      gs_keyinfo TYPE slis_keyinfo_alv.

START-OF-SELECTION.
  v_repid = sy-repid.
  PERFORM. get_data.
  PERFORM. set_alv_layout.
  PERFORM. dis_alv_grid.

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. get_data .
  SELECT * FROM aufk INTO CORRESPONDING FIELDS OF  TABLE headertab
  WHERE auart = 'PM01' AND autyp = '30'.
  IF sy-subrc = 0.
    SELECT * FROM afih AS a INTO CORRESPONDING FIELDS OF TABLE itemtab
    FOR ALL ENTRIES IN headertab WHERE a~aufnr = headertab-aufnr.
  ENDIF.
ENDFORM.                    " get_data
*&---------------------------------------------------------------------*
*&      Form  set_alv_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. set_alv_layout .
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
       i_program_name               =  v_repid
       i_internal_tabname           = 'HEADERTAB'
*     I_STRUCTURE_NAME             =
*     I_CLIENT_NEVER_DISPLAY       = 'X'
       i_inclname                   = v_repid
       i_bypassing_buffer           = 'X'
       i_buffer_active              = ' '
     CHANGING
       ct_fieldcat                  = i_fieldcat
     EXCEPTIONS
       inconsistent_interface       = 1
       program_error                = 2
       OTHERS                       = 3
             .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name               =  v_repid
      i_internal_tabname           = 'ITEMTAB'
*     I_STRUCTURE_NAME             =
*     I_CLIENT_NEVER_DISPLAY       = 'X'
      i_inclname                   = v_repid
      i_bypassing_buffer           = 'X'
      i_buffer_active              = ' '
    CHANGING
      ct_fieldcat                  = i_fieldcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  gs_keyinfo-header01 = 'AUFNR'.
  gs_keyinfo-item01   = 'AUFNR'.
  g_tabname_header = 'HEADERTAB'.
  g_tabname_item   = 'ITEMTAB'.
ENDFORM.                    " set_alv_layout
*&---------------------------------------------------------------------*
*&      Form  dis_alv_grid
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. dis_alv_grid .
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
     EXPORTING
*     I_INTERFACE_CHECK              = ' '
       i_callback_program             = v_repid
*     I_CALLBACK_PF_STATUS_SET       = ' '
*     I_CALLBACK_USER_COMMAND        = ' '
*     IS_LAYOUT                      =
       it_fieldcat                    = i_fieldcat
*     IT_EXCLUDING                   =
*     IT_SPECIAL_GROUPS              =
*     IT_SORT                        =
*     IT_FILTER                      =
*     IS_SEL_HIDE                    =
*     I_SCREEN_START_COLUMN          = 0
*     I_SCREEN_START_LINE            = 0
*     I_SCREEN_END_COLUMN            = 0
*     I_SCREEN_END_LINE              = 0
*     I_DEFAULT                      = 'X'
       i_save                         = 'A'
*     IS_VARIANT                     =
*     IT_EVENTS                      =
*     IT_EVENT_EXIT                  =
       i_tabname_header               = g_tabname_header
       i_tabname_item                 = g_tabname_item
*     I_STRUCTURE_NAME_HEADER        =
*     I_STRUCTURE_NAME_ITEM          =
       is_keyinfo                     = gs_keyinfo
*     IS_PRINT                       =
*     IS_REPREP_ID                   =
       i_bypassing_buffer             = 'X'
       i_buffer_active                = ' '
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER        =
*     ES_EXIT_CAUSED_BY_USER         =
     TABLES
       t_outtab_header                = headertab
       t_outtab_item                  = itemtab
   EXCEPTIONS
       program_error                  = 1
       OTHERS                         = 2
             .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                    " dis_alv_grid

 

11.jpg

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11377579/viewspace-604983/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-05-11

  • 博文量
    13
  • 访问量
    40541