sap 采购申请me51n/me52n/me53n抬头字段增强

可以参考博客https://blogs.sap.com/2017/01/11/add-a-custom-screen-on-purchase-requisition-header-by-replacing-standard-gui-status  效果不同,但是思想都一样

效果

 

Step1.增强标准表

 

 

Step2.增强屏幕

 

 

 

Step3.增强程序,函数组SAPLMEGUI

 1.      PBO控制

1.1  程序屏幕控制

程序LMEGUICJW,METHOD build_dynpro_fields.设置metafield参数,用来控制屏幕是否可输入。

这里用标准的mmmfd_header_userexit.

 

我们这里调用标准的modify_screen,即创建/修改时可编辑,显示时不可编辑。也可以不用标准的,在下方增强loop at screen。

 

 

1.2    PBO数据显示

程序LMEREQF08,METHOD init_from_item,控制初始化屏幕。

将从EBAN里取到的数据(没有研究哪一步取数),放进me->my_state->header,即可将数据显示出来

 

 

2.      PAI控制

新增字段的PAI控制,可以参考标准字段描述的控制(有些系统版本没有这个字段)

 

写在了程序LMEREQF07本地类lcl_req_header-> prepare_ueban_for_descriptiond( ).

    IF zcl_enh_mereq=>get_active_for_spcode( ) = abap_true.

        LOOP AT ct_ueban ASSIGNING <ls_ueban>.
          <ls_ueban>-spcode = my_state->header-spcode.
        ENDLOOP.

        IF me->my_state->headerx-spcode EQ mmpur_yes.
          " Loop at all items and see if there are any that needs to be updated
          LOOP AT me->my_state->items INTO l_item.
            IF l_item->my_persistent_eban IS NOT INITIAL.
              ls_ueban = CORRESPONDING UEBAN( l_item->my_persistent_eban ).
              ls_ueban-mandt = sy-mandt.
              ls_ueban-banfn = my_state->header-banfn.
              ls_ueban-kz = 'U'.
              ls_ueban-t001waers = ls_ueban-waers.
              ls_ueban-spcode = my_state->header-spcode.
              IF NOT line_exists( ct_ueban[ banfn = ls_ueban-banfn bnfpo = ls_ueban-bnfpo ] ).
                APPEND ls_ueban TO ct_ueban.
              ENDIF.
            ENDIF.
            CLEAR ls_ueban.
          ENDLOOP.
        ENDIF.
    ENDIF.

 

 

 

如果没有prepare_ueban_for_descriptiond这个方法,也可以写在lcl_req_header-> prepare_post( )里,合适的地方更改更新lt_ueban。

 

 3.      下拉框设置

和上面PBO屏幕控制在一起,程序LMEGUICJW下面lcl_req_topline_view –>modify_screen( ).

 

 4.      必输设置

lcl_r_hd_custr_data_check-> is_valid( ).写在出口EXIT_SAPLMEREQ_010(这里获取的EBAN得不到增强字段)的下面,创建隐性增强

 

 

5.     BAPI赋值

BAPI_PR_CREATE创建PR,需要先赋值zcl_enh_mereq=>mv_spcode,会走上面4.必输设置的增强点

 

class ZCL_ENH_MEREQ definition
  public
  final
  create public .

public section.

  class-data MV_SPCODE type ZE_SPCODE .

  class-methods GET_ACTIVE_FOR_SPCODE
    returning
      value(RV_ACTIVE) type ABAP_BOOL .
  class-methods MEREQ_HEADER_EXIT
    exporting
      !EX_MESSAGES type MEREQ_T_BAPIRET2
    changing
      !CS_HEADER type MEREQ_HEADER .
  class-methods SET_SPCODE
    changing
      !CS_HEADER type MEREQ_HEADER .
  class-methods CHECK_MEREQ_HEADER
    importing
      !IS_HEADER type MEREQ_HEADER
    exporting
      !EX_MESSAGES type MEREQ_T_BAPIRET2 .
protected section.
private section.
ENDCLASS.



CLASS ZCL_ENH_MEREQ IMPLEMENTATION.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_ENH_MEREQ=>CHECK_MEREQ_HEADER
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_HEADER                      TYPE        MEREQ_HEADER
* | [<---] EX_MESSAGES                    TYPE        MEREQ_T_BAPIRET2
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD check_mereq_header.

    DATA:ls_message TYPE bapiret2.

    MESSAGE e025(zmm01) INTO DATA(dummy).

    "审批code  bapi时报错必输,解决方法 zcl_enh_mereq=>mv_spcode = ''.
    IF is_header-estkz = 'R' AND is_header-spcode IS INITIAL.
      ls_message-type = 'E'.
      ls_message-id = 'ZMM01'.
      ls_message-number = '025'.
*    ls_message-row    = ls_eban-bnfpo.
      APPEND ls_message TO ex_messages.
    ENDIF.

  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_ENH_MEREQ=>GET_ACTIVE_FOR_SPCODE
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RV_ACTIVE                      TYPE        ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD GET_ACTIVE_FOR_SPCODE.
    rv_active = abap_true.
  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_ENH_MEREQ=>MEREQ_HEADER_EXIT
* +-------------------------------------------------------------------------------------------------+
* | [<---] EX_MESSAGES                    TYPE        MEREQ_T_BAPIRET2
* | [<-->] CS_HEADER                      TYPE        MEREQ_HEADER
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD mereq_header_exit.

    set_spcode( CHANGING cs_header = cs_header ).

    check_mereq_header( EXPORTING is_header   = cs_header
                        IMPORTING ex_messages = ex_messages ).


  ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_ENH_MEREQ=>SET_SPCODE
* +-------------------------------------------------------------------------------------------------+
* | [<-->] CS_HEADER                      TYPE        MEREQ_HEADER
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD set_spcode.

    IF mv_spcode IS NOT INITIAL.
      cs_header-spcode = mv_spcode.
      CLEAR mv_spcode.
    ENDIF.

  ENDMETHOD.
ENDCLASS.

 

posted @ 2023-08-03 17:26  yangliu11223  阅读(1021)  评论(5编辑  收藏  举报