前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >matinal:SAP ABAP ALV 层次报表的实现程序例子

matinal:SAP ABAP ALV 层次报表的实现程序例子

作者头像
matinal
发布2023-10-14 15:10:10
2700
发布2023-10-14 15:10:10
举报
文章被收录于专栏:SAP Technical
代码语言:javascript
复制
*&---------------------------------------------------------------------*
*& Report Y4_B4_TEST20
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT y4_b4_test20.
TABLES: ekko,ekpo.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.

*1、在程序里包含SLIS
TYPE-POOLS:slis.

*2、声明主表和明细表
DATA: BEGIN OF headertab OCCURS 0,
        ebeln LIKE ekko-ebeln,
        bstyp LIKE ekko-bstyp,
        bsart LIKE ekko-bsart,
        statu LIKE ekko-statu,
      END OF headertab.

DATA: BEGIN OF itemtab OCCURS 0,
        ebeln LIKE ekpo-ebeln,
        ebelp LIKE ekpo-ebelp,
        matnr LIKE ekpo-matnr,
        werks LIKE ekpo-werks,
        menge LIKE ekpo-menge,
        netpr LIKE ekpo-netpr,
        peinh LIKE ekpo-peinh,
        netwr LIKE ekpo-netwr,
      END OF itemtab.

DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: v_repid LIKE sy-repid."当前程序名

*3、申明主表和明细表的名称变量
DATA: g_tabname_header TYPE slis_tabname,
      g_tabname_item   TYPE slis_tabname.

*4、声明主表和明细表连接关键字变量
DATA: gs_keyinfo TYPE slis_keyinfo_alv.

INITIALIZATION.
  v_repid = sy-repid.

START-OF-SELECTION.

  PERFORM get_data.

END-OF-SELECTION.

*5、获取头表输出表头字段名称
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = v_repid "当前程序名
      i_internal_tabname     = 'HEADERTAB' "主表名
      i_inclname             = v_repid "当前程序名
      i_bypassing_buffer     = 'X'
      i_buffer_active        = ''
    CHANGING
      ct_fieldcat            = i_fieldcat "ALV输出的主表标题
    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.

*6、获取从表输出表头字段名称
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = sy-repid
      i_internal_tabname     = 'ITEMTAB'
      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.

*7、设置主从表的关联字段,最多可以设置五个字段关联。
  gs_keyinfo-header01 = 'EBELN'.
  gs_keyinfo-item01 = 'EBELN'.

*8、设置主表和明细表变量对应的内表名称
  g_tabname_header = 'HEADERTAB'."主表
  g_tabname_item = 'ITEMTAB'."明细表

*9、调用层次ALV输出函数
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    EXPORTING
      i_callback_program = v_repid
      it_fieldcat        = i_fieldcat
      i_save             = 'A'
      i_tabname_header   = g_tabname_header
      i_tabname_item     = g_tabname_item
      is_keyinfo         = gs_keyinfo
      i_bypassing_buffer = 'X'
      i_buffer_active    = ' '
    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.

FORM get_data.

  SELECT ebeln bstyp bsart statu
  INTO TABLE headertab
  FROM ekko
  WHERE ebeln IN s_ebeln.

  IF NOT headertab[] IS INITIAL.
    SELECT ebeln ebelp matnr werks menge netpr peinh netwr
    INTO TABLE itemtab
    FROM ekpo
    FOR ALL ENTRIES IN headertab
    WHERE ebeln = headertab-ebeln.
  ENDIF.

ENDFORM.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档