其他分享
首页 > 其他分享> > MB52增强

MB52增强

作者:互联网

一、在MB52报表中新增字段

实现如图效果

 

二、增强实现

MB52程序为RM07MLBS,在程序中找到定义的内表结构bestand,在最后创建隐式增强,加入增强字段,该内表为将来展示的ALV数据

DATA: BEGIN OF bestand OCCURS 0,
*        Key fields
        matnr    LIKE mara-matnr,
        werks    LIKE t001w-werks,
        ......
        ......
ENHANCEMENT-POINT ehp604_rm07mlbs_03 SPOTS es_rm07mlbs STATIC .
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Struktur BESTAND, Ende                                                                                                                            S
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1  ZNHES_MB52.    "active version
DATA:ZKHMC TYPE KNA1-NAME1,"客户名称
     POST1 TYPE PRPS-POST1,"WBS名称
     PSPHI TYPE PRPS-PSPHI,"项目号
     ZXMMC TYPE PROJ-POST1,"项目名称
ENDENHANCEMENT.
*$*$-End:   (1)---------------------------------------------------------------------------------$*$*
DATA:  END OF bestand.

设置ALV列,在子例程最后创建隐式增强,加入列字段,在子例程fieldcatalog和f0300_fieldcat_flat中都添加

"-----------------------------fieldcatalog-------------------------------
ENHANCEMENT 2  ZMB52.    "active version
  CLEAR fieldcat.
  fieldcat-fieldname     = 'ZKHMC'.
  fieldcat-seltext_l = fieldcat-seltext_s     =  fieldcat-seltext_m     = '客户名称'.
  APPEND fieldcat.

    CLEAR fieldcat.
  fieldcat-fieldname     = 'POST1'.
  fieldcat-seltext_l = fieldcat-seltext_s     =  fieldcat-seltext_m     = 'WBS名称'.
  APPEND fieldcat.

    CLEAR fieldcat.
  fieldcat-fieldname     = 'PSPHI'.
  fieldcat-seltext_l = fieldcat-seltext_s     =  fieldcat-seltext_m     = '项目号'.
  APPEND fieldcat.

    CLEAR fieldcat.
  fieldcat-fieldname     = 'ZXMMC'.
  fieldcat-seltext_l = fieldcat-seltext_s     =  fieldcat-seltext_m     = '项目名称'.
  APPEND fieldcat.

ENDENHANCEMENT.

"-----------------------------f0300_fieldcat_flat-----------------------
fieldcat-seltext_l     = '客户名称'.
        macro_fill_fieldcat 'ZKHMC'  ''   c_out.
        fieldcat-seltext_l     = 'WBS名称'.
        macro_fill_fieldcat 'POST1'  ''   c_out.
        fieldcat-seltext_l     = '项目号'.
        macro_fill_fieldcat 'PSPHI'  ''   c_out.
        fieldcat-seltext_l     = '项目名称'.
        macro_fill_fieldcat 'ZXMMC'  ''   c_out.

 

获取数据,在子例程list_output中加入隐式增强,查询字段的数据

FORM list_output.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(3) Form LIST_OUTPUT, Anfang                                                                                                                          A
*$*$-Start: (3)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 3  ZMB52.    "active version
  data:l_index type i.
  DATA:LT_CHAR TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR WITH HEADER LINE.
  IF bestand[] IS NOT INITIAL.
    SELECT
      KUNNR,
      NAME1
    FROM KNA1
    INTO TABLE @DATA(LT_KNA1)
    FOR ALL ENTRIES IN @bestand
    WHERE KUNNR = @bestand-KUNNR.

    SELECT
      PRPS~PSPNR,
      PRPS~POST1,"WBS名称
      PRPS~PSPHI,"项目号
      PROJ~POST1 AS ZXMMC"项目名称
    FROM PRPS
    INNER JOIN PROJ ON PRPS~PSPHI = PROJ~PSPNR
    INTO TABLE @DATA(LT_PRPS)
    FOR ALL ENTRIES IN @bestand
    WHERE PRPS~PSPNR = @bestand-PSPNR.
  ENDIF.

  LOOP AT bestand  .
    l_index = sy-tabix.
    
    "客户名称
    READ TABLE lt_kna1 INTO DATA(ls_kna1) WITH KEY kunnr = bestand-kunnr.
    IF sy-subrc EQ 0.
      bestand-zkhmc = ls_kna1-name1.
    ENDIF.

    READ TABLE LT_PRPS INTO DATA(LS_PRPS) WITH KEY PSPNR = bestand-PSPNR.
    IF SY-SUBRC EQ 0.
      bestand-POST1 = LS_PRPS-POST1.
      bestand-PSPHI = LS_PRPS-PSPHI.
      bestand-ZXMMC = LS_PRPS-ZXMMC.
    ENDIF.

    MODIFY bestand INDEX l_index.
  ENDLOOP.
ENDENHANCEMENT.

 

标签:增强,PSPHI,fieldcat,bestand,POST1,seltext,PRPS,MB52
来源: https://www.cnblogs.com/BinGeneral/p/15459189.html