其他分享
首页 > 其他分享> > ZWMP165_9001

ZWMP165_9001

作者:互联网

*&---------------------------------------------------------------------*
*&  包含                ZWMP165_9001
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
  SET TITLEBAR 'TIT9001'.
  SET PF-STATUS 'STANDARD'.
  IF g_fld IS INITIAL.
    SET CURSOR FIELD 'WA_9001-VBELN'.
  ELSE.
    SET CURSOR FIELD 'WA_9001-S_ID'.
  ENDIF.

  DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
  IF wa_9001-down_ye = '0' .
    wa_9001-down_ye = ''.
  ENDIF.

ENDMODULE.                 " STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.

  save_code = ok_code.
  CLEAR ok_code.
  CASE save_code.

    WHEN 'EXIT_9001'.
      LEAVE PROGRAM.
    WHEN 'QUE_9001'.
      IF it_9001 IS INITIAL.
*        lg_mes = '没有有效数据,请从新扫描!'.
        lg_mes = text-004 .
        EXIT.
      ELSEIF lg_mes IS  INITIAL.
        CLEAR txt.
        PERFORM frm_set_9002_data.
        PERFORM check_menge.
        LEAVE TO SCREEN 9002.
      ENDIF.
    WHEN 'ENTER'.
      GET CURSOR FIELD g_fld .

**** BEGIN OF ADD EC3K907363***
      IF gv_charg = 'X'.
        CLEAR:wa_9001-s_id.
      ELSE.
**** END   OF ADD EC3K907363***

        IF wa_9001-s_id IS NOT INITIAL.
          wa_9001-id =  wa_9001-s_id .
        ENDIF.
        CLEAR:wa_9001-s_id.
**** BEGIN OF ADD EC3K907363***
      ENDIF.
**** END   OF ADD EC3K907363***

    WHEN 'DEL_9001'.
      IF it_9001 IS INITIAL.
        CLEAR: wa_9001.
      ELSE.

**** BEGIN OF MOD EC3K907363***
*        LOOP AT it_9001 INTO wa_9001.
*          wa_9001-tabix =  sy-tabix.
*          wa_9001-up_ye =  sy-tabix.
*          MODIFY it_9001 FROM wa_9001.
*        ENDLOOP.
*        READ TABLE it_9001 INTO wa_9001 INDEX wa_9001-tabix. "删除后显示最后一页

        "MOD
        PERFORM frm_delete_it_9001.
        PERFORM frm_set_new_page.
**** END   OF MOD EC3K907363***
      ENDIF.

**** BEGIN OF DEL EC3K907363***
*      CLEAR: wa_9001.
**** END   OF DEL EC3K907363***
      CLEAR: lg_mes.

    WHEN 'UP_9001'.
      DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
      IF wa_9001-tabix = 1.
        READ TABLE it_9001 INTO wa_9001 INDEX wa_9001-down_ye.
      ELSE.
        READ TABLE it_9001 INTO wa_9001 INDEX wa_9001-tabix - 1.
        wa_9001-up_ye = wa_9001-tabix.
      ENDIF.

    WHEN 'DOWN_9001'.
      DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
      IF wa_9001-tabix = wa_9001-down_ye.
        READ TABLE it_9001 INTO wa_9001 INDEX 1.
      ELSE.
        READ TABLE it_9001 INTO wa_9001 INDEX wa_9001-tabix + 1.
        wa_9001-up_ye = wa_9001-tabix.
      ENDIF.

    WHEN OTHERS.
  ENDCASE.
  CLEAR:save_code.

ENDMODULE.                 " USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*&      Module  CHECK_REQNUM  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE check_reqnum INPUT.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = wa_9001-vbeln
    IMPORTING
      output = wa_9001-vbeln.

  IF wa_9001-vbeln IS NOT INITIAL.
    SELECT * FROM lips INTO TABLE it_lips
      WHERE vbeln = wa_9001-vbeln.
    CLEAR it_lips1.
    CLEAR wa_lips1.
    SELECT lips~vbeln
           lips~posnr
           lips~matnr
           lips~werks
           lips~lgort
           lips~lfimg
           lips~vrkme
           likp~lifnr
           likp~verur
           lips~vgbel
           lips~vgpos
           lips~charg
           vbuk~wbstk
      INTO CORRESPONDING FIELDS OF TABLE it_lips1
      FROM lips
      INNER JOIN likp ON lips~vbeln = likp~vbeln
      INNER JOIN vbuk ON vbuk~vbeln = likp~vbeln
      WHERE lips~vbeln = wa_9001-vbeln.

*    IF it_lips IS INITIAL AND wa_9001-vbeln IS NOT INITIAL .
*      lg_mes = 'DN 输入错误!'.
*      EXIT.
*    ENDIF.
    IF sy-subrc <> 0.
*      lg_mes = '请输入正确的交货单!'.
      lg_mes = text-005 .
      EXIT.
    ELSE.
      READ TABLE it_lips1 INTO wa_lips1 INDEX 1.
      IF wa_lips1-wbstk = 'B' OR wa_lips1-wbstk = 'C' .
*        lg_mes = '该交货单已收货,不允许重复收货'.
        lg_mes = text-006 .
        EXIT.
      ENDIF.
    ENDIF.
  ENDIF.
***BEGIN OF ADD  EC3K915017***
***检查过账失败的话,删除已拆分的行项目
  PERFORM check_post USING wa_9001-vbeln.
***END OD ADD  EC3K915017***
ENDMODULE.                 " CHECK_REQNUM  INPUT
*&---------------------------------------------------------------------*
*&      Module  UPDATE_TABLE  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE update_table INPUT.

***BEGIN OF ADD EC3K913623***
  DATA:lv_zcodi TYPE ztwm0030-zcodi.
***END OD ADD EC3K913623***
**** BEGIN OF MOD  EC3K907363***
  IF gv_charg = 'X'.
    PERFORM frm_get_lot_id.
    PERFORM frm_uptade_table.
***BEGIN OF ADD EC3K911215***
  ELSEIF gv_r_set_no = 'X'.
*根据套号获取lotid
    PERFORM frm_get_lotid_by_set_no.
    PERFORM frm_uptade_table.
***END OF ADD EC3K911215***
  ENDIF.
  "如果没有输入批次就按照原来逻辑
  CHECK gv_charg IS INITIAL.
**** END OF MOD    EC3K907363***
***BEGIN OF ADD EC3K911215***
*如果没有输入批次和套号就按原来的逻辑
  CHECK gv_r_set_no IS INITIAL.
***END OF ADD EC3K911215***
  DATA: wa_9001_id TYPE ty_9001.
  DATA: l_umrez TYPE umrez,
        l_umren TYPE umren.
  DATA: it_lqua TYPE STANDARD TABLE OF lqua,
      wa_lqua TYPE lqua,
      l_lqua  TYPE n.
  DATA: message(40) TYPE c  .
  DATA: l_lgnum TYPE lgnum,
        l_ltkze TYPE mlgn_ltkze,
        e_charg TYPE  charg_d,
        e_message TYPE  char100,
        l_matkl TYPE matkl,
        l_menge TYPE menge_d.

  DATA: it_ztlotid TYPE STANDARD TABLE OF zzlotid,
  wa_ztlotid TYPE zzlotid.
  DATA: i_status TYPE bapiret2-type.

  FREE: it_zwm0003,it_zwm0004,it_zwm0006,it_zpp002,it_zwm0014,it_zwm0015,it_zwm0017.
  CLEAR:l_matkl,wa_zwm0014, wa_zwm0015,wa_zwm0017.

  IF wa_9001-vbeln IS INITIAL.
*    lg_mes = '请先输入DN!'.
    lg_mes = text-007 .
    EXIT.
  ENDIF.

  wa_9001-id = wa_9001-s_id.
  CLEAR: wa_9001-s_id.

**** BEGIN OF DEL EC3K907363***
  "上一页的仓位自动带到下一页。
*  CLEAR:wa_9001-lgpla.
**** END   OF DEL EC3K907363***

  READ TABLE it_9001 INTO wa_9001_id WITH  KEY id = wa_9001-id.
  IF sy-subrc = 0.
    MOVE-CORRESPONDING wa_9001_id TO wa_9001.
    DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
    wa_9001-up_ye =  wa_9001_id-tabix.
    CLEAR: wa_9001_id.
    EXIT.
  ENDIF.

  SELECT *
    FROM ztwm0017
    INTO TABLE it_zwm0017
    WHERE zlotid = wa_9001-id.
  IF it_zwm0017 IS NOT INITIAL.
    READ TABLE it_zwm0017 INTO wa_zwm0017 WITH KEY zlotid = wa_9001-id.
*    CONCATENATE 'ID在' wa_zwm0017-type '被' wa_zwm0017-uname '锁定' INTO lg_mes.
    CONCATENATE text-008 wa_zwm0017-type text-009 wa_zwm0017-uname text-010 INTO lg_mes.
    EXIT.
  ENDIF.

  FREE: it_ztlotid.
  CLEAR:wa_9001_gz.
  LOOP AT it_9001 INTO wa_9001_gz.
    wa_ztlotid-zlotid = wa_9001_gz-id.
    APPEND wa_ztlotid TO it_ztlotid.
  ENDLOOP.

  CALL FUNCTION 'ZWM_RELATE_LOTID'
    EXPORTING
      zlotid  = wa_9001-id
      ztlotid = it_ztlotid
    IMPORTING
      status  = i_status
      message = message.
  IF message IS NOT INITIAL.
    lg_mes = message.
    EXIT.
  ENDIF.
***BEGIN OF ADD EC3K913623***
***检查是否为入库状态
***BEGIN OF MOD EC3K914568***
***增加判断原材料逻辑

*  SELECT SINGLE zcodi FROM ztwm0030 INTO lv_zcodi
*    WHERE lot_no =  wa_9001-id
*      AND xloek  NE abap_true.
*  IF sy-subrc = 0.
*    IF lv_zcodi NE '03'.
*      lg_mes = text-045.
*      EXIT.
*    ENDIF.
*  ELSE.
*    lg_mes = text-046.
*    EXIT.
*  ENDIF.
  SELECT SINGLE zcodi FROM ztwm0030 INTO lv_zcodi
        WHERE lot_no =  wa_9001-id
          AND xloek  NE abap_true.
  IF sy-subrc <> 0.
    SELECT SINGLE zcodi FROM ztwm0003 INTO lv_zcodi
    WHERE zlotid =  wa_9001-id
      AND xloek  NE abap_true.
  ENDIF.
  IF lv_zcodi IS NOT INITIAL.
    IF lv_zcodi NE '03'.
      lg_mes = text-045.
      EXIT.
    ENDIF.
  ELSE.
    lg_mes = text-046.
    EXIT.
  ENDIF.

***END OD MOD EC3K914568***

***END OD ADD EC3K913623***
  SELECT zlotid
         matnr
         werk
         charg
         zremnum
         zsubmitnum
         meins
         verab
         zreqadate
         zatlverab
         xloek
***BEGIN  OF ADD  EC3K907602***
         lgort
         zoriginalnum"原数量
***END    OF ADD   EC3K907602***
    FROM ztwm0003
    INTO CORRESPONDING FIELDS OF TABLE it_zwm0003
    WHERE zlotid = wa_9001-id.
  IF sy-subrc NE 0 .
    CLEAR it_zwm0030.
    SELECT lot_no"LOTID
           zcodi
           zremnum"剩余数量
           matnr"物料
           werks"工厂
           charg"批次
           xloek"已删除项目
           proslt
           store_name
           group_marking
           set_no
***BEGIN  OF ADD  EC3K907602***
           meins"基本计量单位
           zoriginalnum "原数量
***END    OF ADD   EC3K907602***
      FROM ztwm0030
      INTO  CORRESPONDING FIELDS OF TABLE it_zwm0030
      WHERE lot_no = wa_9001-id..
  ENDIF.
  IF it_zwm0003 IS INITIAL AND it_zwm0030 IS  INITIAL AND wa_9001-id IS NOT INITIAL .
*    lg_mes = '输入ID不正确,请重新输入!'.
    lg_mes = text-011 .
    EXIT.
  ELSE.
    IF it_zwm0003 IS NOT INITIAL.
      READ TABLE it_zwm0003 INTO wa_zwm0003 WITH KEY zlotid = wa_9001-id.
      IF sy-subrc = 0.
        READ TABLE it_lips INTO wa_lips WITH  KEY matnr = wa_zwm0003-matnr
                                                  .
        IF sy-subrc = 0.
***BEGIN OF MOD EC3K915017***
***LIPS库存地点不为空时,检查是否一致
          IF wa_lips-lgort IS NOT INITIAL.
            IF wa_lips-werks NE wa_zwm0003-werk OR wa_lips-lgort NE wa_zwm0003-lgort.
              lg_mes = text-017 .
              EXIT.
            ENDIF.
            wa_9001-posnr = wa_lips-posnr.
            wa_9001-lgort = wa_lips-lgort.
            wa_9001-werks = wa_lips-werks.
          ENDIF.
***END OD MOD EC3K915017***

          IF wa_lips-lgort IS INITIAL.
***BEGIN  OF MOD  EC3K907602***
*            lg_mes = '请先维护DN行项目的库位!'.
*            EXIT.

            "MOD 交货单库位为空,则取第一个标签上的库位
            wa_9001-lgort = wa_zwm0003-lgort.
***BEGIN OF MOD EC3K915017***
            wa_9001-posnr = wa_lips-posnr.    "Add By EC3K915017
***此处不更新LIPS的库位
*            wa_lips-lgort = wa_zwm0003-lgort.
*            MODIFY it_lips FROM wa_lips TRANSPORTING lgort WHERE matnr = wa_zwm0003-matnr.
***END OF MOD EC3K915017***
            READ TABLE it_9001 INTO wa_9001_id WITH  KEY posnr = wa_9001-posnr.
            IF sy-subrc = 0.
              IF wa_9001-lgort <> wa_9001_id-lgort.
*                lg_mes = '扫描ID的库位不一致,请检查'.
                lg_mes = text-012 .
                EXIT.
              ENDIF.
            ENDIF.

***END    OF MOD   EC3K907602***
          ENDIF.

        ELSE.
*          lg_mes = '请手动指定行项目!'.
          lg_mes = text-013 .
          EXIT.
        ENDIF.

        SELECT SINGLE maktx
                 FROM makt
           INTO wa_9001-maktx
          WHERE matnr = wa_zwm0003-matnr
            AND spras = sy-langu.

        wa_9001-matnr = wa_zwm0003-matnr.
        wa_9001-charg = wa_zwm0003-charg.
        wa_9001-menge = wa_zwm0003-zremnum - wa_zwm0003-zsubmitnum.
        IF  wa_9001-menge <= 0 .
          wa_9001-menge = 0.
        ENDIF.
        wa_9001-meins = wa_zwm0003-meins.


        IF wa_zwm0003-verab IS NOT INITIAL AND sy-datum > wa_zwm0003-verab.
*          lg_mes = '超过日期!'.
          lg_mes = text-014 .
          EXIT.
***BEGIN  OF MOD  EC3K907602***
*        ELSEIF wa_zwm0003-zreqadate IS NOT INITIAL  AND sy-datum > wa_zwm0003-zreqadate.
          "MOD
****BEGIN OF MOD EC3K908296****
*        ELSEIF wa_zwm0003-zreqadate <> ''AND sy-datum > wa_zwm0003-zreqadate.
****MOD
        ELSEIF wa_zwm0003-zreqadate <> '00000000'AND sy-datum > wa_zwm0003-zreqadate.
****END OF MOD EC3K908296****
***END    OF MOD   EC3K907602***

*          lg_mes = '超过日期!'.
          lg_mes = text-014 .
          EXIT.
        ELSEIF wa_zwm0003-zatlverab IS NOT INITIAL AND sy-datum > wa_zwm0003-zatlverab.
*          lg_mes = '超过日期!'.
          lg_mes = text-014 .
          EXIT.
        ENDIF.

        IF wa_zwm0003-zremnum = 0.
*          lg_mes = 'ID 剩余数量为0!'.
          lg_mes = text-015 .
          EXIT.
        ELSEIF wa_zwm0003-xloek = 'X'.
*          lg_mes = 'ID 已经删除!'.
          lg_mes = text-016 .
          EXIT.
        ENDIF.

***BEGIN  OF ADD  EC3K907602***
        "扫描LOT ID时,剩余数量(ZREMNUM)不等于原数量,不能出库,报错:LOT ID剩余数量不等于原数量,不允许发已拆包LOT ID;
        IF  wa_zwm0003-zremnum <> wa_zwm0003-zoriginalnum.
          lg_mes = text-001.
          EXIT.
        ENDIF.
***END    OF ADD   EC3K907602***

      ENDIF.
    ELSEIF it_zwm0030 IS NOT INITIAL.
      READ TABLE it_zwm0030 INTO wa_zwm0030 WITH KEY lot_no = wa_9001-id.
      IF sy-subrc = 0.

        READ TABLE it_lips INTO wa_lips WITH  KEY matnr = wa_zwm0030-matnr.          .
        IF sy-subrc = 0.
***BEGIN  OF ADD  EC3K907602***
          IF wa_lips-lgort IS NOT INITIAL.
***END    OF ADD   EC3K907602***
            IF wa_lips-werks NE wa_zwm0030-werks OR wa_lips-lgort NE wa_zwm0030-store_name.
*              lg_mes = 'ID工厂库位与交货单不匹配'.
              lg_mes = text-017 .
              EXIT.
            ENDIF.
            wa_9001-posnr = wa_lips-posnr.
            wa_9001-lgort = wa_lips-lgort.
            wa_9001-werks = wa_lips-werks.
***BEGIN  OF ADD  EC3K907602***
          ENDIF.
***END    OF ADD   EC3K907602***

          IF wa_lips-lgort IS INITIAL.

***BEGIN  OF MOD  EC3K907602***

*            lg_mes = '请先维护DN行项目的库位!'.
*            EXIT.

            "MOD 交货单库位为空,则取第一个标签上的库位
            wa_9001-posnr = wa_lips-posnr.
            wa_9001-werks = wa_lips-werks.
            wa_9001-lgort = wa_zwm0030-store_name.
***BEGIN OF DEL EC3K915017***
***此处不更新LIPS的库位
*            wa_lips-lgort = wa_zwm0030-store_name.
*            MODIFY it_lips FROM wa_lips TRANSPORTING lgort WHERE matnr = wa_zwm0030-matnr.
***END OD DEL EC3K915017***

            READ TABLE it_9001 INTO wa_9001_id WITH  KEY posnr = wa_9001-posnr.
            IF sy-subrc = 0.
              IF wa_9001-lgort <> wa_9001_id-lgort.
*                lg_mes = '扫描ID的库位不一致,请检查'.
                lg_mes = text-012 .
                EXIT.
              ENDIF.
            ENDIF.
***END    OF MOD   EC3K907602***
          ENDIF.
        ELSE.
*          lg_mes = '请手动指定行项目!'.
          lg_mes = text-013 .
          EXIT.
        ENDIF.

        SELECT SINGLE maktx
                  FROM makt
            INTO wa_9001-maktx
           WHERE matnr = wa_zwm0030-matnr
             AND spras = sy-langu.

        wa_9001-matnr = wa_zwm0030-matnr.
        wa_9001-charg = wa_zwm0030-charg.
        wa_9001-menge = wa_zwm0030-zremnum  .
        IF  wa_9001-menge <= 0 .
          wa_9001-menge = 0.
        ENDIF.
        wa_9001-meins = wa_zwm0030-meins.
        IF wa_zwm0030-zremnum = 0.
*          lg_mes = 'ID 剩余数量为0!'.
          lg_mes = text-015 .
          EXIT.
        ELSEIF wa_zwm0030-xloek = 'X'.
*          lg_mes = 'ID 已经删除!'.
          lg_mes = text-016 .
          EXIT.
        ENDIF.
***BEGIN  OF ADD  EC3K907602***
        "扫描LOT ID时,剩余数量(ZREMNUM)不等于原数量,不能出库,报错:LOT ID剩余数量不等于原数量,不允许发已拆包LOT ID;
        IF  wa_zwm0030-zremnum <> wa_zwm0030-zoriginalnum.
          lg_mes = text-001.
          EXIT.
        ENDIF.
***END    OF ADD   EC3K907602***
      ENDIF.
    ENDIF.

    CLEAR:wa_9001_id,wa_9001_gz.
    FREE: it_9001_gz.
    LOOP AT it_9001 INTO wa_9001_id WHERE id <> wa_9001-id..
      READ TABLE it_9001_gz INTO wa_9001_gz WITH  KEY vbeln = wa_9001_id-vbeln
                                                      posnr = wa_9001_id-posnr
                                                      matnr = wa_9001_id-matnr.
      IF sy-subrc = 0.
        wa_9001_gz-menge = wa_9001_gz-menge + wa_9001_id-menge.
        MODIFY  it_9001_gz FROM wa_9001_gz TRANSPORTING menge  WHERE vbeln = wa_9001_id-vbeln
                                                                AND posnr = wa_9001_id-posnr
                                                                AND matnr = wa_9001_id-matnr.
        CLEAR:wa_9001_gz.
      ELSE.
        wa_9001_id-tabix = ''.
        APPEND wa_9001_id TO it_9001_gz.
        CLEAR: wa_9001_id.
      ENDIF.
    ENDLOOP.

    READ TABLE  it_9001_gz INTO wa_9001_gz WITH  KEY vbeln = wa_9001-vbeln
                                                     posnr = wa_9001-posnr
                                                     matnr  = wa_9001-matnr.

    CLEAR: wa_9001-xchar.
    SELECT SINGLE xchar
             INTO wa_9001-xchar
             FROM marc
            WHERE matnr = wa_9001-matnr
              AND werks = wa_9001-werks.
    IF wa_9001-xchar IS INITIAL.
      CLEAR: wa_9001-charg.
    ENDIF.

    CLEAR lw_mtype.
    CLEAR lw_msg  .

    CALL FUNCTION 'ZWM_FIFO'
      EXPORTING
        i_zoccasion = 'B'
        i_matnr     = wa_9001-matnr
        i_werks     = wa_9001-werks
        i_lgort     = wa_9001-lgort
*       I_KUNNR     =
*       I_ZPACKHOUSE          =
        i_charg     = wa_9001-charg
*       I_MENGE     =
        i_menge_all = wa_9001_gz-menge
        i_ztag      = wa_9001-ztag
*       I_MARKING   =
*       I_GROUP_MARKING       =
*       I_MARKING_TYPE        =
      IMPORTING
        e_type      = lw_mtype
        e_message   = lw_msg.
    IF lw_mtype NE 'S'.
      lg_mes = lw_msg.
      EXIT.
    ENDIF.
********* END OF MOD EC3K900177********************


    SELECT SINGLE lgnum
    INTO l_lgnum
    FROM t320
    WHERE werks = wa_9001-werks
     AND  lgort = wa_9001-lgort.

    IF l_lgnum IS NOT INITIAL .

      SELECT SINGLE ltkze
              FROM mlgn
              INTO l_ltkze
             WHERE matnr = wa_9001-matnr
               AND lgnum = l_lgnum.
      SELECT SINGLE lgty0
               INTO wa_9001-lgtyp
               FROM t334t
              WHERE lgnum = l_lgnum
                AND lgtkz = l_ltkze
                AND kzear = 'E'.
      SELECT *
         INTO CORRESPONDING FIELDS OF TABLE it_lqua
         FROM lqua
        WHERE lgnum =  l_lgnum
          AND matnr = wa_9001-matnr
          AND werks = wa_9001-werks
          AND charg = wa_9001-charg
          AND lgtyp = wa_9001-lgtyp
          AND bestq = ''.

      IF it_lqua IS NOT INITIAL.
        DESCRIBE TABLE it_lqua LINES l_lqua.
        IF l_lqua = 1.
          READ TABLE it_lqua INTO wa_lqua WITH  KEY lgnum =  l_lgnum
                                                            matnr = wa_9001-matnr
                                                            werks = wa_9001-werks
                                                            charg = wa_9001-charg
                                                            lgtyp = wa_9001-lgtyp
                                                            bestq = ''.
          IF sy-subrc = 0.
            wa_9001-lgpla =  wa_lqua-lgpla .
          ENDIF.
        ENDIF.

      ENDIF.

****BEGIN OF MOD EC3K911555****
      "IF wa_9001-menge > wa_lips-lfimg.
      IF wa_9001-menge > wa_lips-lgmng.
****END OF MOD  EC3K911555****


*      lg_mes = '扫描数量大于交货单数量!'.
        lg_mes = text-020 .
        g_cwbj = 'X'.
        EXIT.
      ENDIF.
****BEGIN OF MOD EC3K911555****
      "IF wa_9001_gz-menge + wa_9001-menge > wa_lips-lfimg.
      IF wa_9001_gz-menge + wa_9001-menge > wa_lips-lgmng.
****END OF MOD  EC3K911555****
*      lg_mes = '扫描汇总数量大于交货单数量!'.
        lg_mes = text-021 .
        g_cwbj = 'X'.
        EXIT.
      ENDIF.

*    ENDIF.
      CLEAR: l_lqua.
      FREE:it_lqua.

      IF l_lgnum IS NOT INITIAL AND wa_9001-lgpla IS INITIAL AND wa_9001-bsskz <> 'A'.
        IF lg_mes IS INITIAL.
*          lg_mes = '请输入仓位!'.
          lg_mes = text-018 .
          EXIT.
        ENDIF.
      ENDIF.

      SELECT SINGLE ltkze
        FROM mlgn
        INTO l_ltkze
       WHERE matnr = wa_9001-matnr
         AND lgnum = l_lgnum.
      IF sy-subrc <> 0 .
        IF lg_mes IS INITIAL.
*          lg_mes = '请先维护物料主数据!'.
          lg_mes = text-019 .
          EXIT.
        ENDIF.
      ENDIF.
    ENDIF.


    IF wa_9001-id IS NOT INITIAL AND lg_mes IS INITIAL.
      CLEAR:l_lgnum,l_ltkze.
      DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
      wa_9001-tabix = wa_9001-down_ye + 1.
      wa_9001-up_ye = wa_9001-tabix .
      l_menge = l_menge + wa_9001-menge.
      APPEND wa_9001 TO it_9001.
      CLEAR: lg_mes.
    ENDIF.

  ENDIF.

ENDMODULE.                 " UPDATE_TABLE  INPUT
*&---------------------------------------------------------------------*
*&      Module  CHECK_REQPOS  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE check_reqpos INPUT.


ENDMODULE.                 " CHECK_REQPOS  INPUT
*&---------------------------------------------------------------------*
*&      Module  CHECK_LGPLA  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE check_lgpla INPUT.
  DATA: l_lgpla TYPE lgpla.
  DATA: l_linel TYPE sy-tabix.

  SELECT SINGLE lgpla
    INTO l_lgpla
    FROM lagp
    WHERE lgpla = wa_9001-lgpla.
*  BREAK-POINT.
  IF sy-subrc <> 0 AND wa_9001-lgpla IS NOT INITIAL .
*    lg_mes = '仓位输入错误,请重新输入!'.
    lg_mes = text-022 .
  ELSE.
    lg_mes = ''.

    READ TABLE it_9001 INTO wa_9001_gz WITH KEY id = wa_9001-id.
    IF sy-subrc = 0.

      MODIFY it_9001 FROM wa_9001 TRANSPORTING lgpla WHERE id = wa_9001-id.
    ELSE.
**** BEGIN OF ADD EC3K907363***
      IF gv_charg = 'X'.
        PERFORM frm_uptade_table.
      ELSE.
**** END   OF ADD EC3K907363***

        DESCRIBE TABLE it_9001 LINES l_linel.
        wa_9001-tabix = l_linel + 1.
        wa_9001-up_ye = wa_9001-tabix.
        APPEND wa_9001 TO it_9001.
      ENDIF.
**** BEGIN OF ADD EC3K907363***
    ENDIF.
**** END   OF ADD EC3K907363***


  ENDIF.
ENDMODULE.                 " CHECK_LGPLA  INPUT
*&---------------------------------------------------------------------*
*&      Module  UPDATE_MENGE  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE update_menge INPUT.

  DATA: l_line TYPE sy-tabix.
  CLEAR: wa_zwm0003,wa_zwm0030,wa_9001_gz.
  FREE: it_zwm0003, it_zwm0030.
*  BREAK-POINT .
  SELECT zlotid
         matnr
         werk
         charg
         zremnum
         meins
         verab
         zreqadate
         zatlverab
         xloek
         subset
    FROM ztwm0003
    INTO CORRESPONDING FIELDS OF TABLE it_zwm0003
    WHERE zlotid = wa_9001-id.


  READ TABLE it_zwm0003 INTO wa_zwm0003 WITH KEY zlotid = wa_9001-id.
  IF sy-subrc = 0 .
    IF wa_9001-menge > wa_zwm0003-zremnum - wa_zwm0003-zsubmitnum.
*      lg_mes = 'ID 超过了剩余数量!'.
      lg_mes = text-023 .
      g_cwbj = 'X'.
      EXIT.

    ELSEIF wa_9001-menge <= wa_zwm0003-zremnum AND g_cwbj = 'X'.
      CLEAR: lg_mes.
    ENDIF.
  ENDIF.


  CLEAR:wa_9001_id,wa_9001_gz.
  FREE: it_9001_gz.
  LOOP AT it_9001 INTO wa_9001_id WHERE id <> wa_9001-id.
    READ TABLE it_9001_gz INTO wa_9001_gz WITH  KEY vbeln = wa_9001_id-vbeln
                                                    posnr = wa_9001_id-posnr
                                                    matnr = wa_9001_id-matnr.
    IF sy-subrc = 0.
      wa_9001_gz-menge = wa_9001_gz-menge + wa_9001_id-menge.
      MODIFY  it_9001_gz FROM wa_9001_gz TRANSPORTING menge  WHERE vbeln = wa_9001_id-vbeln
                                                              AND posnr = wa_9001_id-posnr
                                                              AND matnr = wa_9001_id-matnr.
      CLEAR:wa_9001_gz.
    ELSE.
      wa_9001_id-tabix = ''.
      APPEND wa_9001_id TO it_9001_gz.
      CLEAR: wa_9001_id.
    ENDIF.
  ENDLOOP.

  READ TABLE  it_9001_gz INTO wa_9001_gz WITH  KEY vbeln = wa_9001-vbeln
                                                   posnr = wa_9001-posnr
                                                   matnr  = wa_9001-matnr.

  CLEAR lw_mtype.
  CLEAR lw_msg  .

  CALL FUNCTION 'ZWM_FIFO'
    EXPORTING
      i_zoccasion = 'B'
      i_matnr     = wa_9001-matnr
      i_werks     = wa_9001-werks
      i_lgort     = wa_9001-lgort
      i_charg     = wa_9001-charg
      i_menge_all = wa_9001_gz-menge
      i_ztag      = wa_9001-ztag
    IMPORTING
      e_type      = lw_mtype
      e_message   = lw_msg.
  IF lw_mtype NE 'S'.
    lg_mes = lw_msg.
    EXIT.
  ELSE.
    CLEAR:lg_mes.
  ENDIF.


  READ TABLE it_9001 INTO wa_9001_gz WITH KEY id = wa_9001-id.
  IF sy-subrc = 0.

    MODIFY it_9001 FROM wa_9001 TRANSPORTING menge WHERE id = wa_9001-id.
  ELSE.

    DESCRIBE TABLE it_9001 LINES l_line.
    wa_9001-tabix = l_line + 1.
    wa_9001-up_ye = wa_9001-tabix.
    APPEND wa_9001 TO it_9001.
  ENDIF.




ENDMODULE.                 " UPDATE_MENGE  INPUT
*&---------------------------------------------------------------------*
*&      Form  CLEAR_9002_DATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM clear_9002_date .
  CLEAR:   ebeln1,
           ebelp1,
           matnr1,
           menge1,
           meins1,
           menge_l1,
           ebeln2,
           ebelp2,
           matnr2,
           menge2,
           meins2,
           menge_l2,
           ebeln3,
           ebelp3,
           matnr3,
           menge3,
           meins3,
           menge_l3,
           ebeln4,
           ebelp4,
           matnr4,
           menge4,
           meins4,
           menge_l4.
ENDFORM.                    " CLEAR_9002_DATE
*&---------------------------------------------------------------------*
*&      Module  SET_MENGE  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_menge OUTPUT.
  DATA: l_zlotid TYPE ztwm0003-zlotid,
          l_subset TYPE ztwm0003-subset."下层标示.
  CLEAR: l_zlotid,l_subset.
  DATA: gw_ztwm0003 TYPE ztwm0003.

  SELECT SINGLE zlotid"LOTID
         subset"下层标示
    FROM ztwm0003
    INTO (l_zlotid,l_subset)
    WHERE zlotid = wa_9001-id.
  IF sy-subrc NE 0.

  ELSE.

    IF l_subset = 'X'.
      LOOP AT SCREEN.
        IF screen-name EQ 'WA_9001-MENGE'.
          screen-input = 0. "0代表不能输入 1代表可以输入!
          MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.

  IF lg_mes IS NOT INITIAL.
    LOOP AT SCREEN.
      IF screen-name EQ 'WA_9001-S_ID'.
        screen-input = 0. "0代表不能输入 1代表可以输入!
        MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.


ENDMODULE.                 " SET_MENGE  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  SET_ZYWLX  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_zywlx OUTPUT.
  CLEAR:gt_list1,gs_value1.
  gs_value1-key = '1'.
*  gs_value1-text = '公司间受托直发客户'.
  gs_value1-text = text-024 .
  APPEND gs_value1 TO gt_list1.

  gs_value1-key = '0'.
*  gs_value1-text = '常规发货'.
  gs_value1-text = text-025 .
  APPEND gs_value1 TO gt_list1.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'WA_9001-ZYWLX'
      values = gt_list1.
ENDMODULE.                 " SET_ZYWLX  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  CHECK_ZYWLX  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE check_zywlx INPUT.
  IF wa_9001-zywlx IS INITIAL.
    lg_mes = text-e01.
  ENDIF.
ENDMODULE.                 " CHECK_ZYWLX  INPUT

*&---------------------------------------------------------------------*
*&      Form  FRM_GET_LOT_ID
*&---------------------------------------------------------------------*
*       根据批次获取所有LOT_ID
*----------------------------------------------------------------------*
FORM frm_get_lot_id.

  IF wa_9001-vbeln IS INITIAL.
*    lg_mes = '请先输入DN!'.
    lg_mes = text-007 .
    EXIT.
  ENDIF.

*  "根据批次取所有lot
*  CLEAR: gt_ztwm0004,gw_ztwm0004,gs_ztwm0004.
*  SELECT zreceipt zlotid charg
*    INTO  TABLE gt_ztwm0004
*    FROM ztwm0004
*    WHERE zreceipt = wa_9001-vbeln
*      AND charg = wa_9001-s_id.
*  IF sy-subrc NE 0.
*    lg_mes = '请检查批次'.
*    RETURN.
*  ENDIF.
*
*  LOOP AT gt_ztwm0004 INTO gw_ztwm0004 .
*    APPEND gw_ztwm0004 TO gt_ztwm0004_02.
*    CLEAR: gw_ztwm0004.
*  ENDLOOP.

  "根据批次取所有lot
  CLEAR: gt_ztwm0030,gw_ztwm0030,gs_ztwm0030.
  SELECT *
    FROM ztwm0030
    INTO CORRESPONDING FIELDS OF TABLE gt_ztwm0030
    WHERE charg = wa_9001-s_id
      AND zcodi = '03'
      AND xloek = ''.
  IF sy-subrc NE 0.
*    lg_mes = '请检查批次'.
    lg_mes = text-026 .
    RETURN.
  ENDIF.

  SELECT COUNT(*)
  FROM ztwm0017
  FOR ALL ENTRIES IN gt_ztwm0030
  WHERE zlotid = gt_ztwm0030-lot_no
    AND type NE '03'.
  IF sy-subrc = 0.
*    lg_mes = '该批次有冻结数据,请扫描LOT'.
    lg_mes = text-027 .
    RETURN.
  ENDIF.

  READ TABLE gt_ztwm0030 INTO gw_ztwm0030 INDEX 1.
  IF sy-subrc = 0.
    LOOP AT gt_ztwm0030 INTO gs_ztwm0030 WHERE matnr NE gw_ztwm0030-matnr
                                            OR werks NE gw_ztwm0030-werks
                                            OR store_name NE gw_ztwm0030-store_name
                                            OR lot_marking NE gw_ztwm0030-lot_marking.
*      lg_mes = '批次数据不唯一'.
      lg_mes = text-028 .
      EXIT.
    ENDLOOP.
    IF lg_mes IS NOT INITIAL.
      RETURN.
    ENDIF.
  ENDIF.

  LOOP AT gt_ztwm0030 INTO gw_ztwm0030 .
    APPEND gw_ztwm0030 TO gt_ztwm0030_02.
    CLEAR: gw_ztwm0030.
  ENDLOOP.
ENDFORM.                    " FRM_GET_LOT_ID
*&---------------------------------------------------------------------*
*&      Form  FRM_UPTADE_TABLE
*&---------------------------------------------------------------------*
*       按照批次获取LOT_ID 刷新屏幕
*----------------------------------------------------------------------*
FORM frm_uptade_table .

  DATA: wa_9001_id TYPE ty_9001.
  DATA: l_umrez TYPE umrez,
        l_umren TYPE umren.
  DATA: it_lqua TYPE STANDARD TABLE OF lqua,
        wa_lqua TYPE lqua,
        l_lqua  TYPE n.
  DATA: message(40) TYPE c  .
  DATA: l_lgnum TYPE lgnum,
        l_ltkze TYPE mlgn_ltkze,
        e_charg TYPE  charg_d,
        e_message TYPE  char100,
        l_matkl TYPE matkl,
        l_menge TYPE menge_d.

  DATA: it_ztlotid TYPE STANDARD TABLE OF zzlotid,
        wa_ztlotid TYPE zzlotid.
  DATA: i_status TYPE bapiret2-type.

  FREE: it_zwm0003,it_zwm0004,it_zwm0006,it_zpp002,it_zwm0014,it_zwm0015,it_zwm0017.
  CLEAR:l_matkl,wa_zwm0014, wa_zwm0015,wa_zwm0017.

*  IF wa_9001-vbeln IS INITIAL.
*    lg_mes = '请先输入DN!'.
*    EXIT.
*  ENDIF.

  LOOP AT gt_ztwm0030 INTO gw_ztwm0030.

*  LOOP AT gt_ztwm0004 INTO gw_ztwm0004.

    wa_9001-id = gw_ztwm0030-lot_no.
    CLEAR: wa_9001-s_id.

**** BEGIN OF DEL EC3K907363***
    "上一页的仓位自动带到下一页。
*  CLEAR:wa_9001-lgpla.
**** END   OF DEL EC3K907363***

    READ TABLE it_9001 INTO wa_9001_id WITH  KEY id = wa_9001-id.
    IF sy-subrc = 0.
      MOVE-CORRESPONDING wa_9001_id TO wa_9001.
      DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
      wa_9001-up_ye =  wa_9001_id-tabix.
      CLEAR: wa_9001_id.
      EXIT.
    ENDIF.

    SELECT *
      FROM ztwm0017
      INTO TABLE it_zwm0017
      WHERE zlotid = wa_9001-id.
    IF it_zwm0017 IS NOT INITIAL.
      READ TABLE it_zwm0017 INTO wa_zwm0017 WITH KEY zlotid = wa_9001-id.
*      CONCATENATE 'ID在' wa_zwm0017-type '被' wa_zwm0017-uname '锁定' INTO lg_mes.
      CONCATENATE text-008 wa_zwm0017-type text-009 wa_zwm0017-uname text-010 INTO lg_mes.
      EXIT.
    ENDIF.

    FREE: it_ztlotid.
    CLEAR:wa_9001_gz.
    LOOP AT it_9001 INTO wa_9001_gz.
      wa_ztlotid-zlotid = wa_9001_gz-id.
      APPEND wa_ztlotid TO it_ztlotid.
    ENDLOOP.

    CALL FUNCTION 'ZWM_RELATE_LOTID'
      EXPORTING
        zlotid  = wa_9001-id
        ztlotid = it_ztlotid
      IMPORTING
        status  = i_status
        message = message.
    IF message IS NOT INITIAL.
      lg_mes = message.
      EXIT.
    ENDIF.

    SELECT zlotid
           matnr
           werk
           charg
           zremnum
           zsubmitnum
           meins
           verab
           zreqadate
           zatlverab
           xloek
***BEGIN  OF ADD  EC3K907602***
           lgort
           zoriginalnum"原数量
***END    OF ADD   EC3K907602***
      FROM ztwm0003
      INTO CORRESPONDING FIELDS OF TABLE it_zwm0003
      WHERE zlotid = wa_9001-id.
    IF sy-subrc NE 0 .
      CLEAR it_zwm0030.
      SELECT lot_no"LOTID
             zcodi
             zremnum"剩余数量
             matnr"物料
             werks"工厂
             charg"批次
             xloek"已删除项目
             proslt
             store_name
             group_marking
             set_no
***BEGIN  OF ADD  EC3K907602***
             meins"基本计量单位
             zoriginalnum "原数量
***END    OF ADD   EC3K907602***
        FROM ztwm0030
        INTO  CORRESPONDING FIELDS OF TABLE it_zwm0030
        WHERE lot_no = wa_9001-id..
    ENDIF.

    IF it_zwm0003 IS INITIAL AND it_zwm0030 IS  INITIAL AND wa_9001-id IS NOT INITIAL .
*      lg_mes = '输入ID不正确,请重新输入!'.
      lg_mes = text-011 .
      EXIT.
    ELSE.
      IF it_zwm0003 IS NOT INITIAL.
        READ TABLE it_zwm0003 INTO wa_zwm0003 WITH KEY zlotid = wa_9001-id.
        IF sy-subrc = 0.
          READ TABLE it_lips INTO wa_lips WITH  KEY matnr = wa_zwm0003-matnr
                                                    .
          IF sy-subrc = 0.
***BEGIN OF ADD EC3K915017***
            IF wa_lips-lgort IS NOT INITIAL.
              IF wa_zwm0003-werk NE wa_lips-werks OR wa_zwm0003-lgort NE wa_lips-lgort.
                lg_mes = text-017 .
                EXIT.
              ENDIF.

              wa_9001-posnr = wa_lips-posnr.
              wa_9001-lgort = wa_lips-lgort.
              wa_9001-werks = wa_lips-werks.
            ENDIF.

***END OD ADD EC3K915017***
***BEGIN OF DEL EC3K915017***
***在上面IF中处理
*            wa_9001-posnr = wa_lips-posnr.
*            wa_9001-lgort = wa_lips-lgort.
*            wa_9001-werks = wa_lips-werks.
***END OD DEL EC3K915017***

            IF wa_lips-lgort IS INITIAL.

***BEGIN  OF MOD  EC3K907602***
              "MOD 交货单库位为空,则取第一个标签上的库位
              wa_9001-lgort = wa_zwm0003-lgort.
***BEGIN OF MOD EC3K915017***
              wa_9001-posnr = wa_lips-posnr.   "Add BY EC3K915017
***此处不更新LIPS
*              wa_lips-lgort = wa_zwm0003-lgort.
*              MODIFY it_lips FROM wa_lips TRANSPORTING lgort WHERE matnr = wa_zwm0003-matnr.
***END OD MOD EC3K915017***

              READ TABLE it_9001 INTO wa_9001_id WITH  KEY posnr = wa_9001-posnr.
              IF sy-subrc = 0.
                IF wa_9001-lgort <> wa_9001_id-lgort.
*                  lg_mes = '扫描ID的库位不一致,请检查'.
                  lg_mes = text-012 .
                  EXIT.
                ENDIF.
              ENDIF.
              "原来代码
*            lg_mes = '请先维护DN行项目的库位!'.
*            EXIT.
***END    OF MOD   EC3K907602***
            ENDIF.

          ELSE.
*            lg_mes = '请手动指定行项目!'.
            lg_mes = text-013 .
            EXIT.
          ENDIF.

          SELECT SINGLE maktx
                   FROM makt
             INTO wa_9001-maktx
            WHERE matnr = wa_zwm0003-matnr
              AND spras = sy-langu.

          wa_9001-matnr = wa_zwm0003-matnr.
          wa_9001-charg = wa_zwm0003-charg.
          wa_9001-menge = wa_zwm0003-zremnum - wa_zwm0003-zsubmitnum.
          IF  wa_9001-menge <= 0 .
            wa_9001-menge = 0.
          ENDIF.
          wa_9001-meins = wa_zwm0003-meins.

          IF wa_zwm0003-verab IS NOT INITIAL AND sy-datum > wa_zwm0003-verab.
*            lg_mes = '超过日期!'.
            EXIT.

***BEGIN  OF MOD  EC3K907602***
*        ELSEIF wa_zwm0003-zreqadate IS NOT INITIAL  AND sy-datum > wa_zwm0003-zreqadate.
            "MOD
****BEGIN OF MOD EC3K908296****
*        ELSEIF wa_zwm0003-zreqadate <> ''AND sy-datum > wa_zwm0003-zreqadate.
****MOD
          ELSEIF wa_zwm0003-zreqadate <> '00000000'AND sy-datum > wa_zwm0003-zreqadate.
****END OF MOD EC3K908296****
***END    OF MOD   EC3K907602***
*            lg_mes = '超过日期!'.
            lg_mes = text-014 .
            EXIT.
          ELSEIF wa_zwm0003-zatlverab IS NOT INITIAL AND sy-datum > wa_zwm0003-zatlverab.
*            lg_mes = '超过日期!'.
            lg_mes = text-014 .
            EXIT.
          ENDIF.

          IF wa_zwm0003-zremnum = 0.
*            lg_mes = 'ID 剩余数量为0!'.
            lg_mes = text-015 .
            EXIT.
          ELSEIF wa_zwm0003-xloek = 'X'.
*            lg_mes = 'ID 已经删除!'.
            lg_mes = text-016 .
            EXIT.
          ENDIF.

***BEGIN  OF ADD  EC3K907602***
          "扫描LOT ID时,剩余数量(ZREMNUM)不等于原数量,不能出库,报错:LOT ID剩余数量不等于原数量,不允许发已拆包LOT ID;
          IF  wa_zwm0003-zremnum <> wa_zwm0003-zoriginalnum.
            lg_mes = text-001.
            EXIT.
          ENDIF.
***END    OF ADD   EC3K907602***

        ENDIF.
      ELSEIF it_zwm0030 IS NOT INITIAL.
        READ TABLE it_zwm0030 INTO wa_zwm0030 WITH KEY lot_no = wa_9001-id.
        IF sy-subrc = 0.
          READ TABLE it_lips INTO wa_lips WITH  KEY matnr = wa_zwm0030-matnr
                                                     .
          IF sy-subrc = 0.

***BEGIN  OF ADD  EC3K907602***
            IF wa_lips-lgort IS NOT INITIAL.
***END    OF ADD   EC3K907602***

              IF wa_lips-werks NE wa_zwm0030-werks OR wa_lips-lgort NE wa_zwm0030-store_name.
*                lg_mes = 'ID工厂库位与交货单不匹配'.
                lg_mes = text-017 .
                EXIT.
              ENDIF.
              wa_9001-posnr = wa_lips-posnr.
              wa_9001-lgort = wa_lips-lgort.
              wa_9001-werks = wa_lips-werks.

***BEGIN  OF ADD  EC3K907602***
            ENDIF.
***END    OF ADD   EC3K907602***

            IF wa_lips-lgort IS INITIAL.

***BEGIN  OF MOD  EC3K907602***
              "MOD 交货单库位为空,则取第一个标签上的库位
              wa_9001-posnr = wa_lips-posnr.
              wa_9001-werks = wa_lips-werks.
              wa_9001-lgort = wa_zwm0030-store_name.
***BEGIN OF DEL EC3K915017***
***此处不更新LIPS
*              wa_lips-lgort = wa_zwm0030-store_name.
*              MODIFY it_lips FROM wa_lips TRANSPORTING lgort WHERE matnr = wa_zwm0030-matnr.
***END OD DEL EC3K915017***

              READ TABLE it_9001 INTO wa_9001_id WITH  KEY posnr = wa_9001-posnr.
              IF sy-subrc = 0.
                IF wa_9001-lgort <> wa_9001_id-lgort.
*                  lg_mes = '扫描ID的库位不一致,请检查'.
                  lg_mes = text-012 .
                  EXIT.
                ENDIF.
              ENDIF.
              "原来代码
*            lg_mes = '请先维护DN行项目的库位!'.
*            EXIT.
***END    OF MOD   EC3K907602***

            ENDIF.
          ELSE.
*            lg_mes = '请手动指定行项目!'.
            lg_mes = text-013 .
            EXIT.
          ENDIF.

          SELECT SINGLE maktx
                    FROM makt
              INTO wa_9001-maktx
             WHERE matnr = wa_zwm0030-matnr
               AND spras = sy-langu.

          wa_9001-matnr = wa_zwm0030-matnr.
          wa_9001-charg = wa_zwm0030-charg.
          wa_9001-menge = wa_zwm0030-zremnum  .
          IF  wa_9001-menge <= 0 .
            wa_9001-menge = 0.
          ENDIF.
          wa_9001-meins = wa_zwm0030-meins.
          IF wa_zwm0030-zremnum = 0.
*            lg_mes = 'ID 剩余数量为0!'.
            lg_mes = text-015 .
            EXIT.
          ELSEIF wa_zwm0030-xloek = 'X'.
*            lg_mes = 'ID 已经删除!'.
            lg_mes = text-016 .
            EXIT.
          ENDIF.

***BEGIN  OF ADD  EC3K907602***
          "扫描LOT ID时,剩余数量(ZREMNUM)不等于原数量,不能出库,报错:LOT ID剩余数量不等于原数量,不允许发已拆包LOT ID;
          IF  wa_zwm0030-zremnum <> wa_zwm0030-zoriginalnum.
            lg_mes = text-001.
            EXIT.
          ENDIF.
***END    OF ADD   EC3K907602***

        ENDIF.
      ENDIF.

      CLEAR:wa_9001_id,wa_9001_gz.
      FREE: it_9001_gz.
      LOOP AT it_9001 INTO wa_9001_id WHERE id <> wa_9001-id..
        READ TABLE it_9001_gz INTO wa_9001_gz WITH  KEY vbeln = wa_9001_id-vbeln
                                                        posnr = wa_9001_id-posnr
                                                        matnr = wa_9001_id-matnr.
        IF sy-subrc = 0.
          wa_9001_gz-menge = wa_9001_gz-menge + wa_9001_id-menge.
          MODIFY  it_9001_gz FROM wa_9001_gz TRANSPORTING menge  WHERE vbeln = wa_9001_id-vbeln
                                                                  AND posnr = wa_9001_id-posnr
                                                                  AND matnr = wa_9001_id-matnr.
          CLEAR:wa_9001_gz.
        ELSE.
          wa_9001_id-tabix = ''.
          APPEND wa_9001_id TO it_9001_gz.
          CLEAR: wa_9001_id.
        ENDIF.
      ENDLOOP.

      READ TABLE  it_9001_gz INTO wa_9001_gz WITH  KEY vbeln = wa_9001-vbeln
                                                       posnr = wa_9001-posnr
                                                       matnr  = wa_9001-matnr.

      CLEAR: wa_9001-xchar.
      SELECT SINGLE xchar
               INTO wa_9001-xchar
               FROM marc
              WHERE matnr = wa_9001-matnr
                AND werks = wa_9001-werks.
      IF wa_9001-xchar IS INITIAL.
        CLEAR: wa_9001-charg.
      ENDIF.

      CLEAR lw_mtype.
      CLEAR lw_msg  .

      CALL FUNCTION 'ZWM_FIFO'
        EXPORTING
          i_zoccasion = 'B'
          i_matnr     = wa_9001-matnr
          i_werks     = wa_9001-werks
          i_lgort     = wa_9001-lgort
*         I_KUNNR     =
*         I_ZPACKHOUSE          =
          i_charg     = wa_9001-charg
*         I_MENGE     =
          i_menge_all = wa_9001_gz-menge
          i_ztag      = wa_9001-ztag
*         I_MARKING   =
*         I_GROUP_MARKING       =
*         I_MARKING_TYPE        =
        IMPORTING
          e_type      = lw_mtype
          e_message   = lw_msg.
      IF lw_mtype NE 'S'.
        lg_mes = lw_msg.
        EXIT.
      ENDIF.
********* END OF MOD EC3K900177********************


      SELECT SINGLE lgnum
      INTO l_lgnum
      FROM t320
     WHERE werks = wa_9001-werks
       AND  lgort = wa_9001-lgort.

      IF l_lgnum IS NOT INITIAL .

        SELECT SINGLE ltkze
                FROM mlgn
                INTO l_ltkze
               WHERE matnr = wa_9001-matnr
                 AND lgnum = l_lgnum.
        SELECT SINGLE lgty0
                 INTO wa_9001-lgtyp
                 FROM t334t
                WHERE lgnum = l_lgnum
                  AND lgtkz = l_ltkze
                  AND kzear = 'E'.
        SELECT *
           INTO CORRESPONDING FIELDS OF TABLE it_lqua
           FROM lqua
          WHERE lgnum =  l_lgnum
            AND matnr = wa_9001-matnr
            AND werks = wa_9001-werks
            AND charg = wa_9001-charg
            AND lgtyp = wa_9001-lgtyp
            AND bestq = ''.

        IF it_lqua IS NOT INITIAL.
          DESCRIBE TABLE it_lqua LINES l_lqua.
          IF l_lqua = 1.
            READ TABLE it_lqua INTO wa_lqua WITH  KEY lgnum =  l_lgnum
                                                              matnr = wa_9001-matnr
                                                              werks = wa_9001-werks
                                                              charg = wa_9001-charg
                                                              lgtyp = wa_9001-lgtyp
                                                              bestq = ''.
            IF sy-subrc = 0.
              wa_9001-lgpla =  wa_lqua-lgpla .
            ENDIF.
          ENDIF.

        ENDIF.
        CLEAR: l_lqua.
        FREE:it_lqua.

        IF l_lgnum IS NOT INITIAL AND wa_9001-lgpla IS INITIAL AND wa_9001-bsskz <> 'A'.
          IF lg_mes IS INITIAL.
*            lg_mes = '请输入仓位!'.
            lg_mes =  text-018 .
            EXIT.
          ENDIF.
        ENDIF.

        SELECT SINGLE ltkze
          FROM mlgn
          INTO l_ltkze
         WHERE matnr = wa_9001-matnr
           AND lgnum = l_lgnum.
        IF sy-subrc <> 0 .
          IF lg_mes IS INITIAL.
*            lg_mes = '请先维护物料主数据!'.
            lg_mes =  text-019 .
            EXIT.
          ENDIF.
        ENDIF.
      ENDIF.
****BEGIN OF MOD EC3K911555****
      "IF wa_9001-menge > wa_lips-lfimg.
      IF wa_9001-menge > wa_lips-lgmng.
****END OF MOD  EC3K911555****
*        lg_mes = '扫描数量大于交货单数量!'.
        lg_mes =  text-020 .
        g_cwbj = 'X'.
        EXIT.
      ENDIF.
****BEGIN OF MOD EC3K911555****
      "IF wa_9001_gz-menge + wa_9001-menge > wa_lips-lfimg.
      IF wa_9001_gz-menge + wa_9001-menge > wa_lips-lgmng.
****END OF MOD  EC3K911555****
*        lg_mes = '扫描汇总数量大于交货单数量!'.
        lg_mes =  text-021 .
        g_cwbj = 'X'.
        EXIT.
      ENDIF.
*    ENDIF.

      IF wa_9001-id IS NOT INITIAL AND lg_mes IS INITIAL.
        CLEAR:l_lgnum,l_ltkze.
        DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
        wa_9001-tabix = wa_9001-down_ye + 1.
        wa_9001-up_ye = wa_9001-tabix .
        l_menge = l_menge + wa_9001-menge.
***BEGIN OF ADD EC3K911215***
        IF gv_r_set_no = 'X'.
          wa_9001-set_no = gw_ztwm0030-set_no.
        ENDIF.
***END OF ADD EC3K911215***
        APPEND wa_9001 TO it_9001.
        CLEAR: lg_mes.
      ENDIF.

    ENDIF.
  ENDLOOP.
ENDFORM.                    " FRM_UPTADE_TABLE
*&---------------------------------------------------------------------*
*&      Module  SET_ZJS  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_zjs OUTPUT.
  DATA lv_line TYPE i.
  DATA lt_ztwm0030 TYPE TABLE OF ztwm0030.
  IF gv_charg = 'X'.
    CLEAR: gv_zjs, lv_line.
    CLEAR: lt_ztwm0030.
    LOOP AT gt_ztwm0030_02 INTO gw_ztwm0030 WHERE charg = wa_9001-charg.
      APPEND gw_ztwm0030 TO lt_ztwm0030.
      CLEAR  gw_ztwm0030.
    ENDLOOP.

    DESCRIBE TABLE lt_ztwm0030 LINES lv_line.
    gv_zjs = lv_line.

*    DATA lt_ztwm0004 TYPE TABLE OF ty_ztwm0004.
*    CLEAR:lt_ztwm0004 .
*    LOOP AT gt_ztwm0004_02 INTO gw_ztwm0004 WHERE charg = wa_9001-charg.
*      APPEND gw_ztwm0004 TO lt_ztwm0004.
*      CLEAR  gw_ztwm0004.
*    ENDLOOP.
*    DESCRIBE TABLE lt_ztwm0004 LINES lv_line.
*    gv_zjs = lv_line.
***BEGIN OF ADD EC3K911215***
  ELSEIF gv_r_set_no = 'X'.
    CLEAR: gv_zjs, lv_line.

    CLEAR: lt_ztwm0030.
    LOOP AT gt_ztwm0030_02 INTO gw_ztwm0030 WHERE set_no = wa_9001-set_no.
      APPEND gw_ztwm0030 TO lt_ztwm0030.
      CLEAR  gw_ztwm0030.
    ENDLOOP.

    DESCRIBE TABLE lt_ztwm0030 LINES lv_line.
    gv_zjs = lv_line.
***END OF ADD EC3K911215***

  ENDIF.
ENDMODULE.                 " SET_ZJS  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  FRM_DELETE_IT_9001
*&---------------------------------------------------------------------*
*       删除数据
*----------------------------------------------------------------------*
FORM frm_delete_it_9001 .
***BEGNI OF MOD EC3K911215***
*  IF gv_charg = 'X'."勾选了批次 删除整个批次的
**    IF wa_9001-charg IS NOT INITIAL.
**      DELETE it_9001 WHERE charg = wa_9001-charg .
**    ENDIF.
**  ELSE."未勾选批次,删除该行
*
*    DELETE gt_ztwm0030_02 WHERE lot_no = wa_9001-id.
**    DELETE gt_ztwm0004_02 WHERE zlotid = wa_9001-id.
*  ENDIF.
*  IF wa_9001-s_id IS NOT INITIAL.
*    DELETE it_9001 WHERE s_id = wa_9001-s_id.
*  ELSEIF wa_9001-id IS NOT INITIAL.
*    DELETE it_9001 WHERE id = wa_9001-id.
*  ENDIF.
**  ENDIF.
  IF gv_r_lotid = 'X'.
    DELETE it_9001 WHERE id = wa_9001-id.
    DELETE gt_ztwm0030_02 WHERE lot_no = wa_9001-id.
  ELSEIF gv_charg = 'X'.
    DELETE it_9001 WHERE charg = wa_9001-charg.
    DELETE gt_ztwm0030_02 WHERE charg = wa_9001-charg.
  ELSEIF gv_r_set_no = 'X'.
    DELETE it_9001 WHERE set_no = wa_9001-set_no.
    DELETE gt_ztwm0030_02 WHERE set_no = wa_9001-set_no.
  ENDIF.
***END OF MOD EC3K911215***
ENDFORM.                    " FRM_DELETE_IT_9001
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_NEW_PAGE
*&---------------------------------------------------------------------*
*       删除之后显示下一页
*----------------------------------------------------------------------*
FORM frm_set_new_page .

  LOOP AT it_9001 ASSIGNING FIELD-SYMBOL(<fs_9001>).
    <fs_9001>-tabix =  sy-tabix.
    <fs_9001>-up_ye =  sy-tabix.
  ENDLOOP.
  DESCRIBE TABLE it_9001 LINES wa_9001-down_ye.
  READ TABLE it_9001 INTO wa_9001 INDEX wa_9001-down_ye.

ENDFORM.                    " FRM_SET_NEW_PAGE
***BEGIN OF ADD EC3K911215***
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_LOTID_BY_SET_NO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_lotid_by_set_no .
  IF wa_9001-vbeln IS INITIAL.
    lg_mes = text-007 .
    EXIT.
  ENDIF.

  CLEAR: gt_ztwm0030,gw_ztwm0030,gs_ztwm0030.
  SELECT *
    FROM ztwm0030
    INTO CORRESPONDING FIELDS OF TABLE gt_ztwm0030
    WHERE set_no = wa_9001-s_id
      AND zcodi = '03'
      AND xloek = ''.
  IF sy-subrc NE 0.
    lg_mes = '请检查套号'(043) .
    RETURN.
  ENDIF.

  SELECT COUNT(*)
    FROM ztwm0017
    FOR ALL ENTRIES IN gt_ztwm0030
    WHERE zlotid = gt_ztwm0030-lot_no
    AND type NE '03'.
  IF sy-subrc = 0.
    lg_mes = '该套号有冻结数据,请扫描LOT或者批次'(044).
    RETURN.
  ENDIF.

  READ TABLE gt_ztwm0030 INTO gw_ztwm0030 INDEX 1.
  IF sy-subrc = 0.
    LOOP AT gt_ztwm0030 INTO gs_ztwm0030 WHERE matnr NE gw_ztwm0030-matnr
                                            OR werks NE gw_ztwm0030-werks
                                            OR store_name NE gw_ztwm0030-store_name
                                            OR lot_marking NE gw_ztwm0030-lot_marking.
      lg_mes = text-028 .
      EXIT.
    ENDLOOP.
    IF lg_mes IS NOT INITIAL.
      RETURN.
    ENDIF.
  ENDIF.

  LOOP AT gt_ztwm0030 INTO gw_ztwm0030 .
    APPEND gw_ztwm0030 TO gt_ztwm0030_02.
    CLEAR: gw_ztwm0030.
  ENDLOOP.
ENDFORM.                    " FRM_GET_LOTID_BY_SET_NO
***END OF ADD EC3K911215***
****BEGIN OF MOD EC3K915017****
FORM check_post USING  pv_vbeln.
  DATA:lt_lips TYPE TABLE OF lips,
       wa_header_data      TYPE bapiobdlvhdrchg,
       wa_header_control   TYPE bapiobdlvhdrctrlchg,
       it_item_data        TYPE STANDARD TABLE OF bapiobdlvitemchg ,
       ls_itemdata         TYPE bapiobdlvitemchg,
       it_item_control     TYPE STANDARD TABLE OF bapiobdlvitemctrlchg,
       ls_itemcontrol      TYPE bapiobdlvitemctrlchg,
       it_item_data_spl    TYPE STANDARD TABLE OF /spe/bapiobdlvitemchg,
       ls_itemdataspl      TYPE /spe/bapiobdlvitemchg,
       lt_return           TYPE STANDARD TABLE OF bapiret2,
       lw_return           TYPE bapiret2,
       lw_lipso            TYPE lips.
  IF pv_vbeln IS NOT INITIAL.

    "检查是否过账成功
    SELECT vbeln posnn
      INTO CORRESPONDING FIELDS OF TABLE gt_vbfa
      FROM vbfa
      WHERE vbelv = pv_vbeln
        AND bwart = '107'.
    SORT gt_vbfa BY vbeln posnn.
    CLEAR:lt_lips.
    SELECT vbeln
           posnr
           matnr
           umvkz
           umvkn
           lgort
           uecha
           lfimg
       INTO CORRESPONDING FIELDS OF TABLE lt_lips
       FROM lips
       WHERE vbeln = pv_vbeln.

    SORT lt_lips BY vbeln posnr.
    LOOP AT lt_lips INTO DATA(lw_lips) WHERE uecha IS NOT INITIAL.
      "判断是否过账成功
      READ TABLE gt_vbfa INTO DATA(lw_bfa) WITH KEY vbeln = lw_lips-vbeln
                                                    posnn = lw_lips-posnr BINARY SEARCH.
      IF sy-subrc = 0.
        CONTINUE.
      ENDIF.

      "还原被拆分数量
      READ TABLE lt_lips INTO lw_lipso WITH KEY vbeln = lw_lips-vbeln
                                                posnr = lw_lips-uecha BINARY SEARCH.
      IF sy-subrc = 0.
        READ TABLE it_item_data ASSIGNING FIELD-SYMBOL(<fw_itemdata>) WITH KEY deliv_numb = lw_lipso-vbeln
                                                                               deliv_item = lw_lipso-posnr.
        IF sy-subrc = 0.
          "更新数量
          <fw_itemdata>-dlv_qty = <fw_itemdata>-dlv_qty + lw_lips-lfimg.
        ELSE.
          "修改被拆分行的数量
          CLEAR: ls_itemdata,ls_itemcontrol,ls_itemdataspl.

          ls_itemdata-deliv_numb      = lw_lipso-vbeln.
          ls_itemdata-deliv_item      = lw_lipso-posnr.
          ls_itemdata-material        = lw_lipso-matnr.
          ls_itemdata-dlv_qty         = lw_lipso-lfimg + lw_lips-lfimg.
          ls_itemdata-fact_unit_nom   = lw_lipso-umvkz. "分子
          ls_itemdata-fact_unit_denom = lw_lipso-umvkn."分母
          APPEND ls_itemdata TO it_item_data.

          ls_itemcontrol-deliv_numb = lw_lipso-vbeln.
          ls_itemcontrol-deliv_item = lw_lipso-posnr.
          ls_itemcontrol-chg_delqty = 'X'.

          APPEND ls_itemcontrol TO it_item_control.

          ls_itemdataspl-deliv_numb = lw_lipso-vbeln.
          ls_itemdataspl-deliv_item = lw_lipso-posnr.
          ls_itemdataspl-stge_loc   = lw_lipso-lgort.
          APPEND ls_itemdataspl TO it_item_data_spl.

        ENDIF.
      ENDIF.
      "拆分后过账不成功的,删除行项目
      CLEAR: ls_itemdata,ls_itemcontrol,ls_itemdataspl.
      ls_itemdata-deliv_numb      = lw_lips-vbeln.
      ls_itemdata-deliv_item      = lw_lips-posnr.
      ls_itemdata-material        = lw_lips-matnr.
      ls_itemdata-fact_unit_nom   = lw_lips-umvkz. "分子
      ls_itemdata-fact_unit_denom = lw_lips-umvkn."分母
      APPEND ls_itemdata TO it_item_data.

      ls_itemcontrol-deliv_numb = lw_lips-vbeln.
      ls_itemcontrol-deliv_item = lw_lips-posnr.
      ls_itemcontrol-chg_delqty = 'X'.
      IF lw_lips-uecha IS NOT INITIAL.
        ls_itemcontrol-del_item = abap_true.
      ENDIF.
      APPEND ls_itemcontrol TO it_item_control.

      ls_itemdataspl-deliv_numb = lw_lips-vbeln.
      ls_itemdataspl-deliv_item = lw_lips-posnr.
      ls_itemdataspl-stge_loc   = lw_lips-lgort.
      APPEND ls_itemdataspl TO it_item_data_spl.

      wa_header_data-deliv_numb    = lw_lips-vbeln.
      wa_header_control-deliv_numb = lw_lips-vbeln.
      CLEAR: lw_lips,ls_itemdata,ls_itemcontrol,ls_itemdataspl.
    ENDLOOP.

    IF it_item_data IS NOT INITIAL.
      CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
        EXPORTING
          header_data    = wa_header_data
          header_control = wa_header_control
          delivery       = wa_header_data-deliv_numb
        TABLES
          item_data      = it_item_data
          item_control   = it_item_control
          item_data_spl  = it_item_data_spl
          return         = lt_return.

      READ TABLE lt_return INTO lw_return WITH KEY type = 'E'.
      IF sy-subrc = 0 .
        MESSAGE ID lw_return-id
              TYPE lw_return-type
            NUMBER lw_return-number
              WITH lw_return-message_v1
                   lw_return-message_v2
                   lw_return-message_v3
                   lw_return-message_v4.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.

        SELECT * FROM lips INTO TABLE it_lips
          WHERE vbeln = wa_9001-vbeln.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                    " CHECK_POST
****BEGIN OF MOD EC3K915017****

标签:lg,9001,wa,ZWMP165,mes,ENDIF,id
来源: https://blog.csdn.net/m0_56991695/article/details/119106895