1、实现效果

根据客制化需求,要在采购订单中新增大量字段,所以要在界面上添加一个单独的页签。效果如下:

ME21N 采购订单新增页签增强 _ME21N

2、增强实现

2.1、增强结构

因为是在抬头上边添加,所以增强CI_EKKODB结构

ME21N 采购订单新增页签增强 _增强_02

2.2、函数组

仿照Function Group MEPOBADIEX建一个Function Group

ME21N 采购订单新增页签增强 _增强_03

ME21N 采购订单新增页签增强 _ME21N_04

ME21N 采购订单新增页签增强 _增强_05

函数组:

ME21N 采购订单新增页签增强 _增强_06

ME21N 采购订单新增页签增强 _ME21N_07

2.3、增强实施

2.3.1、BADI:ME_GUI_PO_CUST

方法:SUBSCRIBE

"--------------------@斌将军--------------------
method IF_EX_ME_GUI_PO_CUST~SUBSCRIBE.
  DATA: LS_SUBSCRIBERS TYPE MEPO_SUBSCRIBERS.
*1 抬头
  IF IM_APPLICATION = 'PO' AND IM_ELEMENT = 'HEADER'.
    CLEAR RE_SUBSCRIBERS[] .
    CLEAR LS_SUBSCRIBERS.
    LS_SUBSCRIBERS-NAME        = SUBSCREEN_H."屏幕名称
    LS_SUBSCRIBERS-DYNPRO      = '9001'."函数组的屏幕编号
    LS_SUBSCRIBERS-PROGRAM     = 'SAPLZMMPO001'."调用的函数组
    LS_SUBSCRIBERS-STRUCT_NAME = 'CI_EKKODB'."增强的结构
    LS_SUBSCRIBERS-LABEL       = '其他数据'."页签名称
    LS_SUBSCRIBERS-POSITION    = 30."页签处于的位置
    LS_SUBSCRIBERS-HEIGHT      = 7."页签高度
    APPEND LS_SUBSCRIBERS TO RE_SUBSCRIBERS.
  ENDIF.
*2 
*  IF IM_APPLICATION = 'PO' AND IM_ELEMENT = 'ITEM'.
*    CLEAR RE_SUBSCRIBERS[] .
*    CLEAR LS_SUBSCRIBERS.
*    LS_SUBSCRIBERS-NAME        = SUBSCREEN_I.
*    LS_SUBSCRIBERS-DYNPRO      = '9100'.
*    LS_SUBSCRIBERS-PROGRAM     = 'SAPLZMM003'.
*    LS_SUBSCRIBERS-STRUCT_NAME = 'CI_EKPODB'.
*    LS_SUBSCRIBERS-LABEL       = 'Badi增强行项目屏幕'.
*    LS_SUBSCRIBERS-POSITION    = 24.   "页签处于的位置
*    LS_SUBSCRIBERS-HEIGHT      = 4.
*    APPEND LS_SUBSCRIBERS TO RE_SUBSCRIBERS.
*  ENDIF.
  endmethod.
"--------------------@斌将军--------------------

定义相关属性

ME21N 采购订单新增页签增强 _ME21N_08

方法:MAP_DYNPRO_FIELDS

"--------------------@斌将军--------------------
method IF_EX_ME_GUI_PO_CUST~MAP_DYNPRO_FIELDS.
  FIELD-SYMBOLS: <mapping> LIKE LINE OF ch_mapping.

  LOOP AT ch_mapping ASSIGNING <mapping>.
    CASE <mapping>-fieldname.
    WHEN 'ZEJFL'. <mapping>-metafield = mmmfd_cust_01.  "抬头
*    WHEN 'ZHEAD02'. <mapping>-metafield = mmmfd_cust_02.
*    WHEN 'ZZ001'.   <mapping>-metafield = mmmfd_cust_03.  "明细
*    WHEN 'ZZ005'.   <mapping>-metafield = mmmfd_cust_04.
*      "自定义字段
*    WHEN 'ZFIELD3'.<mapping>-metafield = mmmfd_cust_05.
    ENDCASE.
  ENDLOOP.
  endmethod.
"--------------------@斌将军--------------------

方法:TRANSPORT_FROM_MODEL

"--------------------@斌将军--------------------
method IF_EX_ME_GUI_PO_CUST~TRANSPORT_FROM_MODEL.
  DATA: ls_header     TYPE REF TO if_purchase_order_mm,
        ls_mepoheader TYPE mepoheader,
        ls_item       TYPE REF TO if_purchase_order_item_mm,
        ls_mepoitem   TYPE mepoitem.
*1 抬头
  IF im_name = subscreen_h.
    mmpur_dynamic_cast ls_header im_model.
    IF ls_header IS NOT INITIAL.
      ls_mepoheader = ls_header->get_data( ).
      MOVE-CORRESPONDING ls_mepoheader TO dynp_data_pbo_h.
    ENDIF.
  ENDIF.
*2 明细
*  IF im_name = subscreen_i.
*    mmpur_dynamic_cast ls_item im_model.
*    IF ls_item IS NOT INITIAL.
*      ls_mepoitem = ls_item->get_data( ).
*      MOVE-CORRESPONDING ls_mepoitem TO dynp_data_pbo_i.
*    ENDIF.
*  ENDIF.
  endmethod.
"--------------------@斌将军--------------------

方法:TRANSPORT_TO_DYNP

"--------------------@斌将军--------------------
METHOD IF_EX_ME_GUI_PO_CUST~TRANSPORT_TO_DYNP.
    CASE IM_NAME.
*1 抬头
      WHEN SUBSCREEN_H.
        call function 'ZMMPO001_PUSH'
          EXPORTING
            IM_DYNP_DATA = DYNP_DATA_PBO_H.
*2 明细
*  WHEN subscreen_i.
*    CALL FUNCTION 'ZMMPO002_PUSH'
*    EXPORTING
*      im_dynp_data = dynp_data_pbo_i.
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.
"--------------------@斌将军--------------------

方法:TRANSPORT_FROM_DYNP

"--------------------@斌将军--------------------
METHOD IF_EX_ME_GUI_PO_CUST~TRANSPORT_FROM_DYNP.
    CASE IM_NAME.
*1 抬头
      WHEN SUBSCREEN_H.
        call function 'ZMMPO001_POP'
          IMPORTING
            EX_DYNP_DATA = DYNP_DATA_PAI_H.
        IF DYNP_DATA_PAI_H <> DYNP_DATA_PBO_H.
          RE_CHANGED = MMPUR_YES.
        ENDIF.
*2 明细
*  WHEN subscreen_i.
*    CALL FUNCTION 'ZMMPO002_POP'
*    IMPORTING
*      ex_dynp_data = dynp_data_pai_i.
*    IF dynp_data_pai_i <> dynp_data_pbo_i.
*      re_changed = mmpur_yes.
*    ENDIF.
      WHEN OTHERS.
    ENDCASE.
  ENDMETHOD.
"--------------------@斌将军--------------------

方法:TRANSPORT_TO_MODEL

"--------------------@斌将军--------------------
method IF_EX_ME_GUI_PO_CUST~TRANSPORT_TO_MODEL.
  DATA: ls_header           TYPE REF TO if_purchase_order_mm,
        ls_mepoheader       TYPE mepoheader,
        ls_po_head_customer TYPE ci_ekkodb,
        ls_po_header_handle TYPE REF TO cl_po_header_handle_mm,
        ls_item             TYPE REF TO if_purchase_order_item_mm,
        ls_mepoitem         TYPE mepoitem,
        ls_po_item_customer TYPE ci_ekpodb,
        ls_po_item_handle   TYPE REF TO cl_po_item_handle_mm.

  CASE im_name.
*1 抬头
  WHEN subscreen_h.
    mmpur_dynamic_cast ls_header im_model.
    IF ls_header IS NOT INITIAL.
      ls_mepoheader = ls_header->get_data( ).
      IF  dynp_data_pbo_h-ZEJFL <> dynp_data_pai_h-ZEJFL.
*      OR dynp_data_pbo_h-zhead02 <> dynp_data_pai_h-zhead02.
        ls_mepoheader-ZEJFL = dynp_data_pai_h-ZEJFL.
*        ls_mepoheader-zhead02 = dynp_data_pai_h-zhead02.
        CALL METHOD ls_header->set_data
        EXPORTING
          im_data = ls_mepoheader.
      ENDIF.
    ENDIF.
*2 明细
*  WHEN subscreen_i.
*    mmpur_dynamic_cast ls_item im_model.
*    IF ls_item IS NOT INITIAL.
*      ls_mepoitem = ls_item->get_data( ).
*      IF  dynp_data_pbo_i-zz001 <> dynp_data_pai_i-zz001
*      OR dynp_data_pbo_i-zz005 <> dynp_data_pai_i-zz005.
*
*        ls_mepoitem-zz001 = dynp_data_pai_i-zz001.
*        ls_mepoitem-zz005 = dynp_data_pai_i-zz005.
*
*        CALL METHOD ls_item->set_data
*        EXPORTING
*          im_data = ls_mepoitem.
*      ENDIF.
*    ENDIF.
  WHEN OTHERS.
  ENDCASE.
  endmethod.
"--------------------@斌将军--------------------

2.3.2、BADI:ME_PROCESS_PO_CUST

到此处,ME23N就可以看到新增的页签,但是ME21N和ME22N看不到,还需要实现一个BADI:ME_PROCESS_PO_CUST的FIELDSELECTION_HEADER方法。

该BADI只能创建一个实施,如果已经有多个实施,必须将其他实施停用,否则将达不到效果。

"--------------------@斌将军--------------------
method IF_EX_ME_PROCESS_PO_CUST~FIELDSELECTION_HEADER.
DATA:ex_data TYPE mepoheader.
  DATA: LV_PERSISTENT TYPE MMPUR_BOOL.
  FIELD-SYMBOLS: <FS> LIKE LINE OF CH_FIELDSELECTION.

  DEFINE SET_INPUT.
    READ TABLE ch_fieldselection ASSIGNING <fs> WITH TABLE KEY metafield = &1.
    IF sy-subrc = 0.
      IF im_header->is_changeable( ) = mmpur_yes.
        <fs>-fieldstatus = '+'."'-'代表hidden, '+'或'.'表示editable, '*'代表display
      ELSE.
        <fs>-fieldstatus = '*'.
      ENDIF.
    ENDIF.
  END-OF-DEFINITION.

  LV_PERSISTENT = IM_HEADER->IS_PERSISTENT( ).

  SET_INPUT MMMFD_CUST_01.
    "获取订单数据
    CLEAR:ex_data.
*   ex_data = im_header->get_data( ).
*  SET_INPUT MMMFD_CUST_02.
endmethod.
"--------------------@斌将军--------------------

对抬头和行项目输入数据的检查可放在方法:PROCESS_HEADER和PROCESS_ITEM中,激活后就成功了。

定期更文,欢迎关注

ME21N 采购订单新增页签增强 _ME21N_09