***INCLUDE MV45AFZZ .

 *---------------------------------------------------------------------*
 *       FORM ZZEXAMPLE                                                *
 *---------------------------------------------------------------------*
 *       text......................................                    *
 *---------------------------------------------------------------------*
 *FORM ZZEXAMPLE.

*  ...

*ENDFORM.

*eject
 *---------------------------------------------------------------------*
 *       FORM USEREXIT_DELETE_DOCUMENT                                 *
 *---------------------------------------------------------------------*
 *       This userexit can be used to delete data in additional tables *
 *       when a sales document is deleted.                             *
 *                                                                     *
 *      This form is called in dialog at the end of form BELEG_LOESCHEN*
 *      just before form BELEG_SICHERN is performed to delete the      *
 *      datas on the database.                                         *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_delete_document.

ENDFORM.                    "USEREXIT_DELETE_DOCUMENT
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_FIELD_MODIFICATION                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to modify the attributes of         *
 *       screen fields.                                                *
 *       This form is processed for each field in the screen.          *
 *                                                                     *
 *       The use of the fields screen-group1 to screen-group4 is:      *
 *                                                                     *
 *       Screen-group1: Automatic modification contolles by transaction*
 *                      MFAW.                                          *
 *       Screen-group2: Contents 'LOO' for steploop-fields.            *
 *       Screen-group3: Used for modififaction, which are dependent on *
 *                      control tables or other fix information.       *
 *       Screen-group4: Unused                                         *
 *                                                                     *
 *       For field mofifications, which are dependent on the document  *
 *       status, you can use the status field in the workareas         *
 *       XVBAP for item status and XVBUK for header status.            *
 *                                                                     *
 *       This form is called from module FELDAUSWAHL.                  *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_field_modification.

* CASE SCREEN-GROUP3.
 *   WHEN '.
 *     IF VBAK-VBTYP NE 'A'.
 *       .
 *     ENDIF.
 * ENDCASE.
 *  CASE screen-group2.
 *    WHEN 'LOO'.
 *      '.
 *       '.
 *      ENDIF.
 *  ENDCASE.
 * CASE SCREEN-NAME.
 *   WHEN 'VBAK-VBELN'.
 *     .
 * ENDCASE.
 **    Begin v1.
 ** 以下是免费样品订单(ZFD)对售达方的类型判断,限制售达方只能是内部办事处:账户组为: Susan
   IF sy-tcode = 'VA01'  OR sy-tcode = 'VA02' .
     DATA:zktokd LIKE kna1-ktokd,kunnr LIKE vbak-kunnr.
     IF xvbak-auart = 'ZFD' AND xvbak-kunnr  IS NOT INITIAL.
 *         zktokd = kna1-ktokd while kunnr = xvbak-annr.
       SELECT SINGLE ktokd FROM kna1
         INTO zktokd
         WHERE kunnr = xvbak-kunnr.
       '.
         ) WITH '免费样品订单售达方必须是内部销售办事处'.
         EXIT.
       ENDIF.
     ENDIF.
   ENDIF.
 **   End v1.
   IF sy-tcode = 'VA01'  .

     DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
     DATA:matnr LIKE mara-matnr.
     LOOP AT xvbap WHERE matnr IS NOT INITIAL .
       CLEAR jhzq.
       SELECT SINGLE jhzq FROM ymara_sd
       INTO jhzq
       WHERE matnr = xvbap-matnr.
       IF jhzqmax < jhzq.
         jhzqmax = jhzq.
         matnr = xvbap-matnr.
       ENDIF.

    ENDLOOP.
     DATA:dat LIKE sy-datum.
     IF   matnr  IS NOT INITIAL AND jhzqmax IS NOT INITIAL.
       .
       dat = sy-datum .
       WHILE i <= jhzqmax.
         i = i +  .
         dat =   dat  +  .
 *--------------工厂日历的日期---------------------
        CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
           EXPORTING
             date                = dat
             factory_calendar_id = 'CN'
           IMPORTING
             date                = dat.
       ENDWHILE.
 *------------------end ----------------------------
       vbak-vdatu  =  dat  .
       xvbep-edatu =  dat .
       MODIFY xvbep TRANSPORTING  edatu    WHERE   posnr IS NOT INITIAL .

      ) WITH '该订单最长交货物料为' matnr '天数为:' jhzqmax.
     ENDIF.
   ENDIF.
 ENDFORM.                    "USEREXIT_FIELD_MODIFICATION
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBAK                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument header workaerea VBAK.                               *
 *                                                                     *
 *       SVBAK-TABIX = :  Create header                               *
 *       SVBAK-TABIX > :  Change header                               *
 *                                                                     *
 *       This form is called at the end of form VBAK_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbak.
 *DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
 *
 *  LOOP AT xvbap WHERE matnr IS NOT INITIAL .
 *    CLEAR jhzq.
 *    select single jhzq FROM ymara_sd
 *    INTO jhzq
 *    where matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 *    xvbep-edatu = sy-datum -  jhzq .
 *    xvbep-bddat = sy-datum -  jhzq .
 *    xvbep-tddat = sy-datum -  jhzq .
 *    xvbep-mbdat = sy-datum -  jhzq .
 *    xvbep-lddat = sy-datum -  jhzq .
 *    xvbep-wadat = sy-datum -  jhzq .
 *    MODIFY xvbep TRANSPORTING
 *    edatu
 *    bddat
 *    tddat
 *    mbdat
 *    lddat
 *    wadat
 *    WHERE   posnr = xvbap-posnr. .
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .

ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBAK
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBAP                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument item workaerea VBAP                                  *
 *                                                                     *
 *       SVBAP-TABIX = :  Create item                                 *
 *       SVBAP-TABIX > :  Change item                                 *
 *                                                                     *
 *       This form is called at the end of form VBAP_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbap.
 *
 *  DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
 *
 *  LOOP AT xvbap WHERE matnr IS NOT INITIAL .
 *    CLEAR jhzq.
 *    select single jhzq FROM ymara_sd
 *    INTO jhzq
 *    where matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 **    xvbep-edatu = sy-datum -  jhzq .
 **    xvbep-bddat = sy-datum -  jhzq .
 **    xvbep-tddat = sy-datum -  jhzq .
 **    xvbep-mbdat = sy-datum -  jhzq .
 **    xvbep-lddat = sy-datum -  jhzq .
 **    xvbep-wadat = sy-datum -  jhzq .
 **    MODIFY xvbep TRANSPORTING
 **    edatu
 **    bddat
 **    tddat
 **    mbdat
 **    lddat
 **    wadat
 **    WHERE   posnr = xvbap-posnr. .
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .
 *
 ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBAP
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBEP                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument schedule line workaerea VBEP                         *
 *                                                                     *
 *       SVBEP-TABIX = :  Create schedule line                        *
 *       SVBEP-TABIX > :  Change schedule line                        *
 *                                                                     *
 *       This form is called at the end of form VBEP_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbep.
   DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
   CLEAR jhzq.
 *
 *  LOOP AT xvbep  .
 *
 **    CLEAR jhzq.
 *    READ TABLE xvbap WITH KEY vbeln = xvbep-vbeln posnr = xvbep-posnr.
 *    SELECT SINGLE jhzq FROM ymara_sd
 *    INTO jhzq
 *    WHERE matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 *    xvbep-edatu = sy-datum -  jhzq .
 *    xvbep-bddat = sy-datum -  jhzq .
 *    xvbep-tddat = sy-datum -  jhzq .
 *    xvbep-mbdat = sy-datum -  jhzq .
 *    xvbep-lddat = sy-datum -  jhzq .
 *    xvbep-wadat = sy-datum -  jhzq .
 *    MODIFY xvbep  .
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .
 *  rv45a-etdat = sy-datum -  jhzqmax .
 ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBEP
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_MOVE_FIELD_TO_VBKD                              *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move some fields into the sales  *
 *       dokument business data workaerea VBKD                         *
 *                                                                     *
 *       SVBKD-TABIX = :  Create data                                 *
 *       SVBKD-TABIX > :  Change data                                 *
 *                                                                     *
 *       This form is called at the end of form VBKD_FUELLEN.          *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_move_field_to_vbkd.

*
 *  VBKD-zzfield = xxxx-zzfield2.

ENDFORM.                    "USEREXIT_MOVE_FIELD_TO_VBKD
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_NUMBER_RANGE                                    *
 *---------------------------------------------------------------------*
 *       This userexit can be used to determine the numberranges for   *
 *       the internal document number.                                 *
 *                                                                     *
 *       US_RANGE_INTERN - internal number range                       *
 *                                                                     *
 *       This form is called from form BELEG_SICHERN                   *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_number_range USING us_range_intern.

* Example: Numer range from TVAK like in standard
 * US_RANGE_INTERN = TVAK-NUMKI.
 ENDFORM.                    "USEREXIT_NUMBER_RANGE
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_PRICING_PREPARE_TKOMK                           *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move additional fields into the  *
 *       communication table which is used for pricing:                *
 *                                                                     *
 *       TKOMK for header fields                                       *
 *                                                                     *
 *       This form is called from form PREISFINDUNG_VORBEREITEN.       *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_pricing_prepare_tkomk.
   CLEAR tkomk-vrtnr.
   PERFORM xvbpa_lesen(sapfv45k) USING 'VE'
                                       vbap-posnr
                                       sy-tabix.
   IF xvbpa-updkz <> 'D'.
     tkomk-vrtnr = xvbpa-pernr.
   ENDIF.

*  TKOMK-zzfield = xxxx-zzfield2.

ENDFORM.                    "USEREXIT_PRICING_PREPARE_TKOMK
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_PRICING_PREPARE_TKOMP                           *
 *---------------------------------------------------------------------*
 *       This userexit can be used to move additional fields into the  *
 *       communication table which is used for pricing:                *
 *                                                                     *
 *       TKOMP for item fields                                         *
 *                                                                     *
 *       This form is called from form PREISFINDUNG_VORBEREITEN.       *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_pricing_prepare_tkomp.

*  TKOMP-zzfield = xxxx-zzfield2.

ENDFORM.                    "USEREXIT_PRICING_PREPARE_TKOMP
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_READ_DOCUMENT                                   *
 *---------------------------------------------------------------------*
 *       This userexit can be used to read data in additional tables   *
 *       when the program reads a sales document.                      *
 *                                                                     *
 *       This form is called at the end of form BELEG_LESEN.           *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_read_document.

ENDFORM.                    "USEREXIT_READ_DOCUMENT
 *eject

*---------------------------------------------------------------------*
 *       FORM USEREXIT_SAVE_DOCUMENT                                   *
 *---------------------------------------------------------------------*
 *       This userexit can be used to save data in additional tables   *
 *       when a document is saved.                                     *
 *                                                                     *
 *       If field T180-TRTYP contents 'H', the document will be        *
 *       created, else it will be changed.                             *
 *                                                                     *
 *       This form is called at from form BELEG_SICHERN, before COMMIT *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_save_document.

* Example:
 * CALL FUNCTION 'ZZ_EXAMPLE'
 *      IN UPDATE TASK
 *      EXPORTING
 *           ZZTAB = ZZTAB.
 *DATA:jhzq LIKE ymara_sd-jhzq,jhzqmax LIKE ymara_sd-jhzq.
 *  LOOP AT xvbap WHERE matnr IS NOT INITIAL.
 *    CLEAR jhzq.
 *    SELECT SINGLE jhzq FROM ymara_sd
 *    INTO jhzq
 *    WHERE matnr = xvbap-matnr.
 *    IF jhzqmax < jhzq.
 *      jhzqmax = jhzq.
 *    ENDIF.
 *
 *
 *  ENDLOOP.
 *  vbak-vdatu  = sy-datum -  jhzqmax .
 *  rv45a-etdat = sy-datum -  jhzqmax .
 ENDFORM.                    "USEREXIT_SAVE_DOCUMENT
 *eject

*&---------------------------------------------------------------------*
 *&      Form  zcheck_ggdd
 *&---------------------------------------------------------------------*
 *       text 广告物料订单判断
*----------------------------------------------------------------------*
 *      -->EXITFLAG   text 检验是否通过
*----------------------------------------------------------------------*
FORM  zcheck_ggdd USING exitflag.
 * RETURN.
   exitflag = .
   IF sy-tcode <> 'VA01' AND sy-tcode <> 'VA02'.
     RETURN.
   ENDIF.

**  销售凭证订单原因 306 促销赠品 307  广告物料 V1.0 ZHOUXU
   LOOP AT xvbap.
 **  销售凭证类型广告物料凭着
    IF xvbak-auart = 'ZGOR'.
       IF  xvbap-pstyv = 'Z002' ."促销品
*          MESSAGE    '订单原因促销赠品项目类别只能为促销品' TYPE 'E'.
         '.
 **       begin V1.1暂时取消促销品的增强
*          MESSAGE e005(ymess) WITH  '项目类别促销品订单原因只能为促销赠品!'  .
 *          exitflag =  .
 *          RETURN.
 **       end V1.
         ENDIF.
       ENDIF.
       IF  xvbap-pstyv = 'ZGAN' OR  xvbap-pstyv = 'Z001'." ZGAN 宣传品,展示品
        '.
 *          MESSAGE    '订单原因为"广告物料"项目类别只能为宣传品或展示品!' TYPE 'E'.
           MESSAGE e005(ymess) WITH '项目类别宣传品或展示品订单原因只能为广告物料!'.
           exitflag =  .
           RETURN.
         ENDIF.
       ENDIF.
     ENDIF.
 **    Z001 V1. ZHOUXU
     IF xvbak-auart = 'Z001'.
       IF  xvbap-pstyv = 'Z003' OR  xvbap-pstyv = 'Z004'.
         ) <> '.
 *          MESSAGE    '订单原因为"广告物料"项目类别只能为宣传品或展示品!' TYPE 'E'.
           MESSAGE e005(ymess) WITH '项目类型为办公用品或样品领用时不能选此订单原因 !'.
           exitflag =  .
           RETURN.
         ENDIF.

      ENDIF.
     ENDIF .
   ENDLOOP.

ENDFORM.                    "zcheck_ggdd
 *---------------------------------------------------------------------*
 *       FORM USEREXIT_SAVE_DOCUMENT_PREPARE                           *
 *---------------------------------------------------------------------*
 *       This userexit can be used for changes or checks, before a     *
 *       document is saved.                                            *
 *                                                                     *
 *       If field T180-TRTYP contents 'H', the document will be        *
 *       created, else it will be changed.                             *
 *                                                                     *
 *       This form is called at the beginning of form BELEG_SICHERN    *
 *                                                                     *
 *---------------------------------------------------------------------*
 FORM userexit_save_document_prepare.

  IF sy-tcode = 'CO06'.
     EXIT.
   ENDIF.
   DATA:exitflag TYPE i.
 *-----------------V1. ZHOUXU 广告订单判断---------------------------
  PERFORM zcheck_ggdd USING exitflag.
    .
     EXIT.
   ENDIF.
   DATA: lx_vbak LIKE vbak.
   DATA: zkbetr LIKE xkomv-kbetr.
    DECIMALS  VALUE '150.00',
         zprice2  DECIMALS  VALUE '50.00'.
   SELECT SINGLE * INTO lx_vbak
     FROM vbak WHERE vbeln = xvbak-vbeln.
   IF vbak-kvgr1 <> lx_vbak-kvgr1.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr1 = lx_vbak-kvgr1.
       vbak-kvgr1 = lx_vbak-kvgr1.
     ENDIF.
   ENDIF.
   IF vbak-kvgr2 <> lx_vbak-kvgr2.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr2 = lx_vbak-kvgr2.
       vbak-kvgr2 = lx_vbak-kvgr2.
     ENDIF.
   ENDIF.
   IF vbak-kvgr3 <> lx_vbak-kvgr3.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr3 = lx_vbak-kvgr3.
       vbak-kvgr3 = lx_vbak-kvgr3.
     ENDIF.
   ENDIF.
   IF vbak-kvgr4 <> lx_vbak-kvgr4.
     AUTHORITY-CHECK OBJECT 'ZHLSDPR'
      '.
     .
       ) WITH '你没有权限审批价格!'.
       xvbak-kvgr4 = lx_vbak-kvgr4.
       vbak-kvgr4 = lx_vbak-kvgr4.
     ENDIF.
   ENDIF.
   LOOP AT xkomv.
     CASE xkomv-kschl.
       WHEN 'ZK04'.
         IF vbak-kvgr5 IS INITIAL.
           CASE   xvbak-auart.
             WHEN 'OR' OR 'ZTOR' OR 'ZYOR' OR 'ZDOR'.
               MESSAGE e005(ymess) WITH '已维护ZK04和ZK07的折扣,请选择折扣性质!'.
           ENDCASE.
         ENDIF.

        .
           zkbetr = ABS( xkomv-kbetr ).
           IF zkbetr GT zprice1.
             '.
               xvbak-kvgr3 = '.
               vbak-kvgr3 = '.
               ) WITH '订单折扣率高于15%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.

            EXIT.
           ELSEIF zkbetr GT zprice2.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.

          ELSE.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             xvbak-kvgr2 = ' '.
             vbak-kvgr2 = ' '.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣率产生,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.
           ENDIF.
         ENDIF.
 *----------------------------------------------------20081010ZK07增加
      WHEN 'ZK07'.
         IF vbak-kvgr5 IS INITIAL.
           CASE   xvbak-auart.
             WHEN 'OR' OR 'ZTOR' OR 'ZYOR' OR 'ZDOR'.
               MESSAGE e005(ymess) WITH '已维护ZK04和ZK07的折扣!请选择折扣性质!'.
           ENDCASE.
         ENDIF.

        .
           zkbetr = ABS( xkomv-kbetr ).
           IF zkbetr GT zprice1.
             '.
               xvbak-kvgr3 = '.
               vbak-kvgr3 = '.
               ) WITH '订单折扣率高于15%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.

            EXIT.
           ELSEIF zkbetr GT zprice2.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             '.
               xvbak-kvgr2 = '.
               vbak-kvgr2 = '.
               ) WITH '订单折扣率高于5%,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.

          ELSE.
             xvbak-kvgr3 = ' '.
             vbak-kvgr3 = ' '.
             xvbak-kvgr2 = ' '.
             vbak-kvgr2 = ' '.
             '.
               xvbak-kvgr1 = '.
               vbak-kvgr1 = '.
               ) WITH '订单折扣率产生,需要审批 '.
               xvbak-lifsk = '.
               vbak-lifsk = '.
             ENDIF.
             EXIT.
           ENDIF.
         ENDIF.

    ENDCASE.
   ENDLOOP.
 *----------------------------------------------------20081009增加修改订单冻结判断.
   DATA: lx_vbap LIKE vbap.
   DATA  l_vbap LIKE vbap .
   DATA  l_vbap2 LIKE vbap .
   DATA  t_vbap TYPE TABLE OF vbap.
   DATA  t_vbap2 TYPE TABLE OF vbap.
   DATA: lx_vbep LIKE vbep.
   DATA: lx_konv LIKE konv.
   DATA: lx_konv1 LIKE konv.
   DATA: zkbetr1 LIKE xkomv-kbetr.

  DATA: lx_jsto LIKE jsto.
   DATA: lx_tj30 LIKE tj30.
   DATA: lx_jest LIKE jest.

  CLEAR zkbetr1.
   IF sy-tcode = 'VA02'.

    '.
       LOOP AT xvbap.
         SELECT SINGLE *
         INTO lx_vbap
         FROM vbap
         WHERE vbeln = xvbap-vbeln AND posnr = xvbap-posnr.
         .
           xvbak-kvgr4 = '.
           vbak-kvgr4 = '.
           ) WITH '订单折扣率已经审批,修改后需要再次审批 '.
           xvbak-lifsk = '.
           vbak-lifsk = '.
           EXIT.
         ENDIF.
         SELECT SINGLE *
         INTO lx_konv
         FROM konv
         WHERE knumv = xvbak-knumv  AND kposn = xvbap-posnr AND kschl = 'ZK04'.
         SELECT SINGLE *
         INTO lx_konv1
         FROM konv
         WHERE knumv = xvbak-knumv  AND kposn = xvbap-posnr AND kschl = 'ZK07'.
         IF lx_konv-kbetr NE space .
           zkbetr1 = ABS( lx_konv-kbetr ).
           IF xvbap-matnr NE lx_vbap-matnr OR
              xvbap-kwmeng GT lx_vbap-kwmeng OR
              zkbetr GT zkbetr1.
             xvbak-kvgr4 = '.
             vbak-kvgr4 = '.
             ) WITH '订单折扣率已经审批,修改后需要再次审批 '.
             xvbak-lifsk = '.
             vbak-lifsk = '.

            EXIT.
           ENDIF.
         ENDIF.
         IF lx_konv1-kbetr NE space .
           zkbetr1 = ABS( lx_konv1-kbetr ).
           IF xvbap-matnr NE lx_vbap-matnr OR
            xvbap-kwmeng GT lx_vbap-kwmeng OR
            zkbetr GT zkbetr1.
             xvbak-kvgr4 = '.
             vbak-kvgr4 = '.
             ) WITH '订单折扣率已经审批,修改后需要再次审批 '.
             xvbak-lifsk = '.
             vbak-lifsk = '.

            EXIT.
           ENDIF.
         ENDIF.

      ENDLOOP.
     ENDIF.

****增加有条件未审批时,不允许修改订单交货状态 add by LKJ 2009/02/25
     ' ).

      AUTHORITY-CHECK OBJECT 'ZHLSDPR'
          '.
       .
         ) WITH '订单价格、折扣未审批,无权修改状态!'.
         xvbak-lifsk = '.
         vbak-lifsk = '.
       ENDIF.

    ENDIF.
 ***** add end

 **** 订单的对象状态审核
**** 如果未审核,可以修改数据,如果已审核,不能做任何更改 *****
     IF lx_vbak-objnr NE space." AND ( sy-uname = 'E464503' or sy-uname = 'E422038' or sy-uname = 'E422083' or sy-uname = 'E423726').

      DATA role TYPE c VALUE 'Y'.

      SELECT SINGLE * INTO lx_jest
           FROM jest WHERE objnr EQ lx_vbak-objnr AND inact EQ 'X'.

      IF lx_jest-stat EQ 'E0001'.
         AUTHORITY-CHECK OBJECT 'B_USERSTAT'
             ID 'BERSL' FIELD 'ZSDAU001'.

        ."无审核权限,检查已修改的数据条件(刷可用量)
           role = 'N'.
 *        ) WITH '订单对象状态审批通过,无反审核权限!'.
 *        LEAVE TO CURRENT TRANSACTION.
         ELSE.
           role = 'Y'.
         ENDIF.
         DATA:netwr LIKE vbap-netwr .
         DATA:temp TYPE string.
         LOOP AT xvbap INTO l_vbap.

          APPEND l_vbap TO t_vbap2.
           SELECT SINGLE *
              INTO l_vbap2
           FROM vbap
           WHERE vbeln = l_vbap-vbeln AND posnr = l_vbap-posnr.

*      l_vbap2-aedat = sy-datum."del v1.6
           l_vbap2-aedat = l_vbap-aedat.                     "add v1.6
           l_vbap2-klmeng = l_vbap-klmeng.
           l_vbap2-kbmeng = l_vbap-kbmeng.
           l_vbap2-abgru = l_vbap-abgru.
 **
           CLEAR netwr.
           netwr = l_vbap-netwr - l_vbap2-netwr.
           netwr = ABS( netwr ).
           temp =  netwr.
           CONDENSE temp.
           ' .
             l_vbap2-netwr = l_vbap-netwr.
           ENDIF.
 **end v1.
 **begin v1.
           CLEAR netwr.
           netwr = l_vbap-mwsbp - l_vbap2-mwsbp.
           netwr = ABS( netwr ).
           temp =  netwr.
           CONDENSE temp.
           ' .
             l_vbap2-mwsbp = l_vbap-mwsbp.
           ENDIF.

**end v1.5
 **begin v1..
           CLEAR netwr.
           netwr = l_vbap-netpr - l_vbap2-netpr.
           netwr = ABS( netwr ).
           temp =  netwr.
           CONDENSE temp.
           ' .
             l_vbap2-netpr = l_vbap-netpr.
           ENDIF.
 **end v1.
 **    Begin v1.
 **以下是免费样品订单(ZFD),广告物料订单(ZGOR)审核后不允许修改的字段内容:
 **
 **,订单抬头:售达方,送达方,成本中心;
 **,订单明细:物料编码,数量,增删行项目.
           IF xvbak-auart = 'ZGOR' OR  xvbak-auart = 'ZFD'.
             l_vbap2-netwr = l_vbap-netwr.
             l_vbap2-mwsbp = l_vbap-mwsbp.
             l_vbap2-netpr = l_vbap-netpr.
           ENDIF.

**   End v1.8
 **    Begin v1.
 ** 以下是免费样品订单(ZFD)对售达方的类型判断,限制售达方只能是内部办事处:账户组为: Susan 

          DATA:zktokd LIKE kna1-ktokd,kunnr LIKE vbak-kunnr.
           IF xvbak-auart = 'ZFD'.
 *         zktokd = kna1-ktokd while kunnr = xvbak-annr.
             SELECT SINGLE ktokd FROM kna1
               INTO zktokd
               WHERE kunnr = xvbak-kunnr.
             '.
               MESSAGE e005(ymess)  WITH '免费样品订单售达方必须是内部销售办事处'.
               EXIT.
             ENDIF.
           ENDIF.

**   End v1.9
           APPEND l_vbap2 TO t_vbap.

          CLEAR: l_vbap,l_vbap2.

        ENDLOOP.

        lx_vbak-faksk = vbak-faksk .
         xvbak-faksk = vbak-faksk .

**Begin v1.2

        lx_vbak-kvgr1 = vbak-kvgr1.
         lx_vbak-kvgr2 = vbak-kvgr2.
         lx_vbak-kvgr3 = vbak-kvgr3.
         lx_vbak-kvgr4 = vbak-kvgr4.
         lx_vbak-kvgr5 = vbak-kvgr5.
         lx_vbak-lifsk = vbak-lifsk.
 **End v1.

**Begin v1.6
         lx_vbak-aedat = vbak-aedat.
 **End v1.
 **
 *    DATA:netwr LIKE vbak-netwr .
         CLEAR netwr.
         netwr = lx_vbak-netwr - vbak-netwr.
         netwr = ABS( netwr ).
         temp =  netwr.
         CONDENSE temp.
         ' .
           lx_vbak-netwr = vbak-netwr.
         ENDIF.
 **
 **    Begin v1.
 **以下是免费样品订单(ZFD),广告物料订单(ZGOR)审核后不允许修改的字段内容:
 **
 **,订单抬头:售达方,送达方,成本中心;
 **,订单明细:物料编码,数量,增删行项目.
         IF xvbak-auart = 'ZGOR' OR  xvbak-auart = 'ZFD'.
           lx_vbak-netwr = vbak-netwr.
         ENDIF.

**   End v1.8
 *      LOOP AT xvbep.
 *        SELECT SINGLE *
 *        INTO lx_vbep
 *        FROM vbep
 *        WHERE vbeln = xvbep-vbeln AND posnr = xvbep-posnr AND bmeng = xvbep-bmeng AND edatu = sy-datum.
 *      ENDLOOP.

        IF xvbak EQ lx_vbak OR vbak EQ lx_vbak . "如果订单抬头被更改
          IF t_vbap2 EQ t_vbap.
 *               if role = 'N'.
 *                  ) WITH '订单对象状态审批通过,无反审核权限!'.
 *                  LEAVE TO CURRENT TRANSACTION.
 *               else.
 *                 exit.
 *              endif.
             EXIT.
           ELSE.
             ) WITH '订单对象状态审批通过,不允许修改订单行项目数据!'.
             LEAVE TO CURRENT TRANSACTION.
           ENDIF.
           EXIT.
         ELSE.
           ) WITH '订单对象状态审批通过,不允许修改抬头订单数据!'.
           LEAVE TO CURRENT TRANSACTION.
         ENDIF.
         EXIT.
       ENDIF.
     ENDIF.

   ENDIF.
 ENDFORM.                    "USEREXIT_SAVE_DOCUMENT_PREPARE *eject

MV45AFZZ 销售订单的增强的更多相关文章

  1. 销售订单增强字段 bapi更新

    如果增强字段在销售订单抬头(vbak)上,则要将增强字段一并append到如下四个表/结构中: VBAKKOZ VBAKKOZX BAPE_VBAK BAPE_VBAKX 在行项目(vbap)上: V ...

  2. 【ABAP系列】SAP 销售订单的行项目里条件的增强

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 销售订单的行项目里条件的 ...

  3. SAP四代增强实现:销售订单复制项目文本时不需要显示文本框和回车

    最近接收到一个业务需求,在SAP依据销售订单复制时,如果订单里面的项目有多个文本,系统就会显示复制的文本框处理,让用户选择是否复制,这个就让销售很不舒服,如果有几十个项目,每个项目有几个文本,那就就要 ...

  4. [SAP ABAP开发技术总结]SD销售订单定价过程

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. 为什么S/4HANA的销售订单创建会触发生产订单的创建

    调用S/4HANA销售订单创建函数SD_SALES_DOCU_MAINTAIN创建一个销售订单时,会触发生产订单的创建. 销售订单的每个行项目对应一个独立的生产订单,SD_SALES_DOCU_MAI ...

  6. 基于SAP Kyma的订单编排增强介绍

    尽管有一万个舍不得,2018年还是无可挽回地离我们远去了. 唯有SAP成都研究院的同事和我去年在网络上留下的这些痕迹,能证明2018年我们曾经很认真地去度过每一天: SAP成都研究院2018年总共87 ...

  7. sap 中怎样把非限制库存转为销售订单库存?

    把非限制库存转为销售订单库存: MB1B 移动类型413 把销售订单库存转为非限制库存: MB1B移动类型411 E 切记!

  8. Netsharp快速入门(之11) 销售管理(开发销售订单工作区)

    作者:秋时 杨昶   时间:2014-02-15  转载须说明出处 4.3     销售订单开发 4.3.1  部件工作区设置 1.创建部件工作区,建工作区向导中要注意勾选组合并系部分.具体要建立的部 ...

  9. Netsharp快速入门(之13) 销售管理(单据流转 销售订单生成发货单)

    作者:秋时 杨昶   转载须说明出处 4.5     单据流转 4.5.1  单据流转的目的 单据流转主要为了实现业务关系的流转,并记录相互之间的关系.例如从销售订单生成销货单,两张单据之间有对应的关 ...

随机推荐

  1. 跨浏览器tab页的通信解决方案尝试

    目标 当前页面需要与当前浏览器已打开的的某个tab页通信,完成某些交互.其中,与当前页面待通信的tab页可以是与当前页面同域(相同的协议.域名和端口),也可以是跨域的. 要实现这个特殊的功能,单单使用 ...

  2. CCNP-3.vlan间路由及三层交换机的配置

  3. 【集美大学1411_助教博客】个人作业2——英语学习APP案例分析 成绩

    个人作业2--英语学习APP案例分析,截止发稿时间全班31人,提交31,未提交0人.有一名同学已经写了作业但忘记提交了,这次给分了,但下不为例.由于助教这周有点忙,所以点评得非常不及时,请同学们见谅. ...

  4. 201521123090《JAVA程序设计》第二周学习总结

    1. 本章学习总结 java基本数据类型 String类对象使用 枚举类型及switch分支 容器的概念 2. 书面作业 Q1.使用Eclipse关联jdk源代码(截图),并查看String对象的源代 ...

  5. 201521123098 《Java程序设计》第12周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 1. Input Stream -- 数据提供者可从其中读数据输出流:Output Stream -- 数据接 ...

  6. Java十二周总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...

  7. smarty文件夹,第一个smarty实例总结

    主要是libs里面的smarty类,和init.inc.php配置文件   剩下的是php文件夹.模板文件夹,临时文件夹.缓存文件夹.配置文件夹.插件文件夹   调用main文件夹中的php文件,通过 ...

  8. jQuery常用语法总结笔记

    jQuery 1.入口函数 1          $(document).ready(function(){}); 2          $(function(){}); jQuery入口函数与js入 ...

  9. python数据分析panda库

    panda内有两种数据结构,Series()和DataFrame() >>> a=pd.Series([1,2],index=['a','b']) >>> a a ...

  10. JDBC第二篇--【PreparedStatment、批处理、处理二进制、自动主键、调用存储过程、函数】

    这是我JDBC的第一篇 http://blog.csdn.net/hon_3y/article/details/53535798 1.PreparedStatement对象 PreparedState ...