如何编写多client多公司的增强

  在 sap的使用中,存在多个多个开发团队为不同 client进行开发维护,为了避免增强的影响,我们可以如下框架去编写增强

1)参照MV45AFZA创建一个程序为Y+XXXX+XX_MV45AFZA
XXXX=〉公司代码
XX=〉Modlue abbreviation

2) add Y+XXXX+XX before all form names to avoid form name conflict
For example
*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_KOMKD                             *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the        *
*       communication workarea for product substitution.              *
*                                                                     *
*       This form is called from form KOMKD_KOMPD_FUELLEN.            *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_KOMKD.
*  KOMKD-zzfield = xxxx-zzfield2.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_KOMKG                             *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the        *
*       communication workarea for product listing or exclusion.      *
*                                                                     *
*       This form is called from form KOMKG_KOMPG_FUELLEN.            *
*                                                                     *
*---------------------------------------------------------------------*
form y0029sd_move_field_to_komkg.
*  KOMKG-zzfield = xxxx-zzfield2.
endform.

3)add include statement into MV45AFZA
include y0000sd_mv45afza.  " 
include y0077sd_mv45afza.  "
include y0076sd_mv45afza.  "
include y0029sd_mv45afza.  " 
include y0031sd_mv45afza.  " 
*}   INSERT*
************************************************************************
*                                                                      *
* This include is reserved for user modifications                      *
*                                                                      *
* Forms for sales document processing                                  *
*                                                                      *
* The name of modification modules should begin with 'ZZ'.             *
*                                                                      *
************************************************************************

*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_KOMKD                             *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the        *
*       communication workarea for product substitution.              *
*                                                                     *
*       This form is called from form KOMKD_KOMPD_FUELLEN.            *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_KOMKD.

*  KOMKD-zzfield = xxxx-zzfield2.
ENDFORM.

4) add code depent company or client into  Y+XXXX+XX_MV45AFZA
*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_KOMKD                             *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the        *
*       communication workarea for product substitution.              *
*                                                                     *
*       This form is called from form KOMKD_KOMPD_FUELLEN.            *
*                                                                     *
*---------------------------------------------------------------------*
form y0029sd_move_field_to_komkd.
  perform xvbpa_lesen(sapfv45k) using 'ZH' vbap-posnr sy-tabix.
  move xvbpa-kunnr to komkd-yyheadq.
DATA: BEGIN OF yhpath OCCURS 10.
          INCLUDE STRUCTURE vbpavb.
  DATA: END OF yhpath.
  CLEAR:   yhpath.
  REFRESH: yhpath.
  CALL FUNCTION 'SD_CUSTOMER_HIERARCHY_PATH'
    EXPORTING
      customer        = vbak-kunnr  "sold-to party
      date            = sy-datum    "todays date
      htype           = 'A'         "Customer hierarchy A
      sales_channel   = vbak-vtweg  "distr. channel
      sales_division  = vbak-spart  "division
      sales_org       = vbak-vkorg  "sales org.
    TABLES
      hpath           = yhpath
    EXCEPTIONS
      hityp_not_exist = 1
      node_not_exist  = 2
      parvw_not_exist = 3
      OTHERS          = 4.
  IF sy-subrc = 0.
    LOOP AT yhpath.
      CASE sy-tabix.
        WHEN 1.
          komkd-yy0000sd_hienr01 = yhpath-kunnr.
        WHEN 2.
          komkd-yy0000sd_hienr02 = yhpath-kunnr.
        WHEN 3.
          komkd-yy0000sd_hienr03 = yhpath-kunnr.
        WHEN 4.
          komkd-yy0000sd_hienr04 = yhpath-kunnr.

      ENDCASE.
    ENDLOOP.
  ENDIF.
endform.

5) modify MV45AFZA source form code to check whether different company or client enhancement  is active, If it is active, it is will be called
*---------------------------------------------------------------------*
*       FORM USEREXIT_MOVE_FIELD_TO_KOMKD                             *
*---------------------------------------------------------------------*
*       This userexit can be used to move some fields into the        *
*       communication workarea for product substitution.              *
*                                                                     *
*       This form is called from form KOMKD_KOMPD_FUELLEN.            *
*                                                                     *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_KOMKD.
*  KOMKD-zzfield = xxxx-zzfield2.
*{   INSERT         TASK900030                                        1
*{   INSERT         TE1K900020                                        1
*** functionality: determine customer number of partner ZH (headquarter)
data: c_programm like y0000ca_userexit-yprogramm value 'MV45AFZA'.
data: c_funcname like y0000ca_userexit-yfuncname value
  'USEREXIT_MOVE_FIELD_TO_KOMKD'.
data: w_programm like y0000ca_userexit-yprogramm.
data: w_funcname like y0000ca_userexit-yfuncname.
data: w_active   like y0000ca_userexit-yactive.
data: w_subrc    like sy-subrc.
data: w_mandt    like sy-mandt.
*** check whether the user exit is activated for this client:
call function 'Y_0000CA_CHECK_USEREXIT'
  exporting
    pi_programm       = c_programm
    pi_funcname       = c_funcname
  importing
    pe_programm       = w_programm
    pe_funcname       = w_funcname
    pe_active         = w_active
    pe_subrc          = w_subrc.
*** if userexit is active execute it.
if sy-subrc = 0.
  if ( w_active <> ' ' ) and ( w_subrc = 0 ).
    w_mandt = sy-mandt. w_mandt+2(1) = '0'.
    case w_mandt.
      when '900' . 
        perform y0000sd_move_field_to_komkd.
*      when '400' .
*        perform y0077sd_move_field_to_komkd.
       when '410' . 
         perform y0076sd_move_field_to_komkd.
       when '440' . 
         perform y0031sd_move_field_to_komkd.
      when others.
    endcase.
  endif.
endif.
*}   INSERT
*}   INSERT
ENDFORM.
*eject

6) 建立一个自定义表维护哪些增强已经激活
 
 

7)建立检查激活函数
FUNCTION y_0000ca_check_userexit.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(PI_PROGRAMM) LIKE  Y0000CA_USEREXIT-YPROGRAMM
*"     REFERENCE(PI_FUNCNAME) LIKE  Y0000CA_USEREXIT-YFUNCNAME
*"  EXPORTING
*"     REFERENCE(PE_PROGRAMM) LIKE  Y0000CA_USEREXIT-YPROGRAMM
*"     REFERENCE(PE_FUNCNAME) LIKE  Y0000CA_USEREXIT-YFUNCNAME
*"     REFERENCE(PE_ACTIVE) LIKE  Y0000CA_USEREXIT-YACTIVE
*"     REFERENCE(PE_SUBRC) LIKE  SY-SUBRC
*"----------------------------------------------------------------------

  TABLES: y0000ca_userexit.
  DATA:   w_client   LIKE y0000ca_userexit-ymandt.
*** first check whether the user exit is active in the current client:
  w_client = sy-mandt.
  SELECT SINGLE * FROM y0000ca_userexit CLIENT SPECIFIED
    WHERE yprogramm = pi_programm
      AND yfuncname = pi_funcname
      AND ymandt    = w_client.
*** if first check not successful check again with client xx0:
*** this client xx0 should exist in .
  IF sy-subrc NE 0.
    w_client+2(1) = '0'.
    SELECT SINGLE * FROM y0000ca_userexit CLIENT SPECIFIED
      WHERE yprogramm = pi_programm
        AND yfuncname = pi_funcname
        AND ymandt    = w_client.
  ENDIF.
*** if something was found return the values else only the return code:
  pe_subrc = sy-subrc.
  IF sy-subrc EQ 0.
    pe_active = y0000ca_userexit-yactive.
    pe_programm = y0000ca_userexit-yprogramm_exec.
    pe_funcname = y0000ca_userexit-yfuncname_exec.
  ELSE.
    CLEAR: pe_active.
    CLEAR: pe_programm.
    CLEAR: pe_funcname.
  ENDIF.
ENDFUNCTION.

你可能感兴趣的:(16,SAP,Enhancement,reference,include,hierarchy,insert,function,structure)