REUSE_ALV_FIELDCATALOG_MERGE用于生成ALV层次结构列表?

时间:2017-07-05 04:49:28

标签: grid report sap abap

执行此代码时会发生一些错误。可以使用REUSE_ALV_FIELDCATALOG_MERGE功能模块在ABAP中生成alv层次结构报告吗?最简单的fieldcatalog合并是否有任何提示?

REPORT ZSAMPLE_ALV_HIERACHIAL.

DATA : IT_VBAK LIKE TABLE OF VBAK,
       WA_VBAK LIKE VBAK,

       IT_VBAP LIKE TABLE OF VBAP,
       WA_VBAP LIKE VBAP,

       IT_MARA LIKE TABLE OF MARA,
       WA_MARA LIKE MARA,

       IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
       WA_FCAT TYPE SLIS_FIELDCAT_ALV,

       IT_FCAT1 TYPE SLIS_T_FIELDCAT_ALV,
       WA_FCAT1 TYPE SLIS_FIELDCAT_ALV,

       IT_EVENT TYPE SLIS_T_EVENT,
       WA_EVENT TYPE SLIS_ALV_EVENT,

       V_VBELN TYPE VBAK-VBELN,

       GS_KEYINFO TYPE SLIS_KEYINFO_ALV,

       WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
       WA_LAYOUT1 TYPE SLIS_LAYOUT_ALV.

WA_LAYOUT-ZEBRA = 'X'.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'C510'.

WA_LAYOUT-ZEBRA = 'X'.
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'C510'.

SELECT-OPTIONS S_VBELN FOR V_VBELN.

START-OF-SELECTION.
  PERFORM READ_DATA.
  PERFORM KEY_INFO.
  PERFORM FILL_FIELD_CATALOG USING 'IT_VBAK' 'VBAK'.
  PERFORM FILL_FIELD_CATALOG USING 'IT_VBAP' 'VBAP'.
  PERFORM DISPLAY_HIERACIAL_ALV.

*&---------------------------------------------------------------------*
*&      Form  READ_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM READ_DATA .

  SELECT * FROM VBAK INTO TABLE IT_VBAK WHERE VBELN IN S_VBELN.

  IF NOT IT_VBAK IS INITIAL .

    SELECT * FROM VBAP INTO TABLE IT_VBAP FOR ALL ENTRIES IN IT_VBAK WHERE VBELN = IT_VBAK-VBELN.

  ENDIF.

ENDFORM.                    "READ_DATA

*&---------------------------------------------------------------------*
*&      Form  KEY_INFO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM KEY_INFO .

  CLEAR GS_KEYINFO.
  GS_KEYINFO-HEADER01 = 'VBELN'.
  GS_KEYINFO-ITEM01 = 'VBELN'.
  GS_KEYINFO-HEADER02 = SPACE.
  GS_KEYINFO-ITEM02 = 'VBELP'.

ENDFORM.                    "KEY_INFO

*&---------------------------------------------------------------------*
*&      Form  FILL_FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->TNAM       text
*      -->C          text
*----------------------------------------------------------------------*
FORM FILL_FIELD_CATALOG  USING    TNAM TYPE C STRUCTURE TYPE C.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME     = SY-REPID
      I_INTERNAL_TABNAME = TNAM
      I_STRUCTURE_NAME   = STRUCTURE
    CHANGING
      CT_FIELDCAT        = IT_FCAT.
ENDFORM.                    "FILL_FIELD_CATALOG

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_HIERACIAL_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM DISPLAY_HIERACIAL_ALV .

  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM      = SY-CPROG
      IS_LAYOUT               = WA_LAYOUT
      IT_FIELDCAT             = IT_FCAT
      I_TABNAME_HEADER        = 'IT_VBAK'
      I_TABNAME_ITEM          = 'IT_VBAP'
*     I_STRUCTURE_NAME_HEADER = 'VBAK'
*     I_STRUCTURE_NAME_ITEM   = 'VBAP'
      IS_KEYINFO              = GS_KEYINFO
    TABLES
      T_OUTTAB_HEADER         = IT_VBAK
      T_OUTTAB_ITEM           = IT_VBAP.

ENDFORM.

1 个答案:

答案 0 :(得分:1)

您绝对可以将它用于分层报告!但你应该声明你的另一种方式来达到这个目的。

注意事项:在下面的声明中,您应该在 read_data 表单中检查it_vbak[],而不是it_vbak,否则您的it_vbap itab将始终为空。此外,您应该仅通过REUSE_ALV_FIELDCATALOG_MERGE参数(如果是内部表格)将其传递给i_internal_tabnam

最后,您的代码应该看起来像这样:

DATA: BEGIN OF it_vbak OCCURS 0,
        vbeln LIKE vbak-vbeln,
        expand,
      END OF it_vbak.
DATA: BEGIN OF it_vbap OCCURS 0,
        vbeln LIKE vbap-vbeln,
        posnr LIKE vbap-posnr,
        matnr LIKE vbap-matnr,
        netpr LIKE vbap-netpr,
      END OF it_vbap,

v_vbeln TYPE vbak-vbeln,
it_fcat TYPE slis_t_fieldcat_alv,
gs_keyinfo TYPE slis_keyinfo_alv,
wa_layout  TYPE slis_layout_alv.

SELECT-OPTIONS s_vbeln FOR v_vbeln.

START-OF-SELECTION.
  PERFORM read_data.
  PERFORM key_info.
  PERFORM fill_field_catalog USING 'IT_VBAK'.
  PERFORM fill_field_catalog USING 'IT_VBAP'.
  PERFORM display_hieracial_alv.
*&---------------------------------------------------------------------*
*&      Form  READ_DATA
*&---------------------------------------------------------------------*
FORM read_data .
  SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE it_vbak WHERE
  vbeln IN s_vbeln.
  IF NOT it_vbak[] IS INITIAL.
    SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE it_vbap FOR
ALL ENTRIES IN it_vbak
    WHERE vbeln = it_vbak-vbeln.
  ENDIF.
ENDFORM.                    "READ_DATA
*&---------------------------------------------------------------------*
*&      Form  KEY_INFO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM key_info .
  CLEAR gs_keyinfo.
  gs_keyinfo-header01 = 'VBELN'.
  gs_keyinfo-item01 = 'VBELN'.
ENDFORM.                    "KEY_INFO
*&---------------------------------------------------------------------*
*&      Form  FILL_FIELD_CATALOG
*&---------------------------------------------------------------------*
FORM fill_field_catalog  USING tnam TYPE c.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name     = sy-repid
      i_internal_tabname = tnam
      i_inclname         = sy-repid
    CHANGING
      ct_fieldcat        = it_fcat.
ENDFORM.                    "FILL_FIELD_CATALOG
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_HIERACIAL_ALV
*&---------------------------------------------------------------------*
FORM display_hieracial_alv.
  wa_layout-zebra = 'X'.
  wa_layout-subtotals_text = 'SUBTOTAL TEXT'.
  wa_layout-key_hotspot = 'X'.
  wa_layout-expand_fieldname = 'EXPAND'.
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    EXPORTING
      i_callback_program      = sy-cprog
      is_layout               = wa_layout
      it_fieldcat             = it_fcat
      i_tabname_header        = 'IT_VBAK'
      i_tabname_item          = 'IT_VBAP'
      is_keyinfo              = gs_keyinfo
    TABLES
      t_outtab_header         = it_vbak
      t_outtab_item           = it_vbap.
ENDFORM.