计算周包材,日包材用来发送给外围系统

文章目录

      • 1 Introduction
      • 2 code

1 Introduction

In this example We get data from BOM and RESB . and calculate it .

2 code


  TYPES: BEGIN OF TY_ZPPT_0015_W,
           AUFNR   TYPE  ZPPT_0015-AUFNR,
           ZXH     TYPE  ZPPT_0015-ZXH,
           ZZJHID  TYPE  ZPPT_0015-ZZJHID,
           ZRJHID  TYPE  ZPPT_0015-ZRJHID,
           MATNR   TYPE  ZPPT_0015-MATNR,
           ZND     TYPE  ZPPT_0015-ZND,
           ZYD     TYPE  ZPPT_0015-ZYD,
           ZZD     TYPE  ZPPT_0015-ZZD,
           MENGE   TYPE  ZPPT_0015-MENGE,
           MEINS   TYPE  ZPPT_0015-MEINS,
           ZSFSD   TYPE  ZPPT_0015-ZSFSD,
           GSTRP   TYPE  ZPPT_0015-GSTRP,
           GLTRP   TYPE  ZPPT_0015-GLTRP,
           ZCXBM   TYPE  ZPPT_0015-ZCXBM,
           ARBPL   TYPE  ZPPT_0015-ARBPL,
           DISPO   TYPE  ZPPT_0015-DISPO,
           ERNAM   TYPE  ZPPT_0015-ERNAM,
           ERSDA   TYPE  ZPPT_0015-ERSDA,
           ERFZEIT TYPE  ZPPT_0015-ERFZEIT,
           ZZZZT   TYPE  ZPPT_0015-ZZZZT,

           ZSTATE1 TYPE  ZPPT_0015-ZSTATE1,
           MATNR1  TYPE MSEG-MATNR ,  " 包材物料名称
           QUAN    TYPE MSEG-MENGE,  " 包材数量
           MIENS1  TYPE MSEG-MEINS, " 包材单位

         END OF TY_ZPPT_0015_W.





           TYPES: BEGIN OF TY_ZPPT_0015_cal,
            ZRJHID  TYPE  ZPPT_0015-ZRJHID,
           AUFNR   TYPE  ZPPT_0015-AUFNR,
           ZXH     TYPE  ZPPT_0015-ZXH,
           ZZJHID  TYPE  ZPPT_0015-ZZJHID,
           MATNR   TYPE  ZPPT_0015-MATNR,
           ZND     TYPE  ZPPT_0015-ZND,
           ZYD     TYPE  ZPPT_0015-ZYD,
           ZZD     TYPE  ZPPT_0015-ZZD,
           MENGE   TYPE  ZPPT_0015-MENGE,
           MEINS   TYPE  ZPPT_0015-MEINS,
           ZSFSD   TYPE  ZPPT_0015-ZSFSD,
           GSTRP   TYPE  ZPPT_0015-GSTRP,
           GLTRP   TYPE  ZPPT_0015-GLTRP,
           ZCXBM   TYPE  ZPPT_0015-ZCXBM,
           ARBPL   TYPE  ZPPT_0015-ARBPL,
           DISPO   TYPE  ZPPT_0015-DISPO,
           ERNAM   TYPE  ZPPT_0015-ERNAM,
           ERSDA   TYPE  ZPPT_0015-ERSDA,
           ERFZEIT TYPE  ZPPT_0015-ERFZEIT,
           ZZZZT   TYPE  ZPPT_0015-ZZZZT,

           ZSTATE1 TYPE  ZPPT_0015-ZSTATE1,
           MATNR1  TYPE MSEG-MATNR ,  " 包材物料名称
           QUAN    TYPE MSEG-MENGE,  " 包材数量
           MIENS1  TYPE MSEG-MEINS, " 包材单位

         END OF TY_ZPPT_0015_cal.


     data :LT_ZPPT_0015_CAL TYPE TABLE OF  TY_ZPPT_0015_cal,
           LW_ZPPT_0015_CAL LIKE LINE OF LT_ZPPT_0015_CAL .








  DATA: LT_ZPPT_0015 LIKE TABLE OF ZPPT_0015,
        LW_ZPPT_0015 LIKE LINE OF LT_ZPPT_0015.

  DATA: LT_ZPPT_0015_Q LIKE TABLE OF ZPPT_0015 ,       " 已经取消的日计划数据
        LW_ZPPT_0015_Q LIKE LINE OF LT_ZPPT_0015_Q.
  DATA: LT_ZPPT_0015_SUM LIKE TABLE OF ZPPT_0015 ,       " 汇总的成品数据
        LW_ZPPT_0015_SUM LIKE LINE OF LT_ZPPT_0015_SUM.




  DATA: LT_ZPPT_0015_W TYPE TABLE OF TY_ZPPT_0015_W ,       " 未发布的日计划数据
        LW_ZPPT_0015_W LIKE LINE OF LT_ZPPT_0015_W.


  DATA: LT_ZPPT_0015_M TYPE TABLE OF TY_ZPPT_0015_W ,       "    安照每个生产订单行汇总
        LW_ZPPT_0015_M LIKE LINE OF LT_ZPPT_0015_M.


  DATA: LT_ZPPT_0015_DAY TYPE TABLE OF TY_ZPPT_0015_W ,      "包材数据
        LW_ZPPT_0015_DAY LIKE LINE OF LT_ZPPT_0015_DAY.



  DATA: LT_ZPPT_0014 LIKE TABLE OF ZPPT_0014,
        LW_ZPPT_0014 LIKE LINE OF LT_ZPPT_0014.

  DATA :  LW_OTB_WEEK_HEAD TYPE       ZSOTB_1477_HEAD,
          IT_OTB_WEEK_ITEM TYPE  ZTOTB_1477_ITEM,
          LW_OTB_WEEK_ITEM TYPE     ZSOTB_1477_ITEM,
          LV_MESSAGE       TYPE STRING,
          LV_CODE          TYPE STRING.


  DATA:      IT_EWM_WEEK_ITEM TYPE   ZTEWM0002_INPUT,
             IW_EWM_WEEK_ITEM TYPE  ZSEWM0002_INPUT.

  DATA: LT_ZPPT_0014_SUM LIKE TABLE OF ZPPT_0014,
        LW_ZPPT_0014_SUM LIKE LINE OF LT_ZPPT_0014_SUM.

  DATA: LS_TOPMAT TYPE CSTMAT,
        LV_DSTST  TYPE CSDATA-XFELD,
        LT_STB    TYPE TABLE OF STPOX,
        LT_MATCAT TYPE TABLE OF CSCMAT.




  DATA :    LT_ZPPT_0017 LIKE TABLE OF ZPPT_0017,
            LW_ZPPT_0017 LIKE LINE  OF LT_ZPPT_0017.


  DATA :   LT_ZPPT_0017_CON LIKE TABLE OF ZPPT_0017 ,                   " 根据条件现在存表数
           LW_ZPPT_0017_CON LIKE LINE  OF LT_ZPPT_0017_CON.


  DATA :  LW_ZSEWM0002_ITEM TYPE ZSEWM0002_ITEM,
          LT_ZSEWM0002_ITEM TYPE ZTEWM0002_ITEM.


  DATA :  ZSTATUS_EWM_WEEK  TYPE STRING,
          ZMESSAGE_EWM_WEEK TYPE STRING.

  DATA: LT_RESB LIKE TABLE OF RESB,
        LW_RESB LIKE LINE OF LT_RESB.


  DATA: LT_RESB_LAST LIKE TABLE OF RESB,             "  最后一条数据
        LW_RESB_LAST LIKE LINE OF LT_RESB_LAST.


  DATA :  LW_OTB_DAY_HEAD  TYPE  ZSOTB_1445_HEAD .
  DATA : LV_MESSAGE_OTB_DAY TYPE STRING.
  DATA : LT_OTB_DAY_ITEM TYPE ZTOTB_1445_ITEM,
         LW_OTB_DAY_ITEM TYPE ZSOTB_1445_ITEM.



  DATA :     LT_EWM_DAY_ITEM    TYPE      ZTEWM0001_INPUT,
             LW_EWM_DAY_ITEM    TYPE      ZSEWM0001_INPUT,
             L_ZSTATUS_EWM_DAY  TYPE STRING,
             L_ZMESSAGE_EWM_DAY TYPE STRING,
             LW_EWM_DAY         TYPE   ZSEWM0001ITEM,
             LT_EWM_DAY         TYPE   ZTEWM0001ITEM.


  DATA :          LW_MES_DAY_HEAD TYPE           ZMESZHGCS009_HEAD,
                  LT_MES_DAY_ITEM TYPE    ZMESZHGCT009_ITEM,
                  LW_MES_DAY_ITEM TYPE    ZMESZHGCS009_ITEM,
                  L_ES_RETURN_MES TYPE   ZMESZHGCS009_RETURN.

  DATA: L_INDEX TYPE SY-TABIX.

  DATA:  L_MENGE_B_SUM    TYPE MSEG-MENGE , " 包材总量
         L_MENGE_C_SUM    TYPE MSEG-MENGE ,  "成品总理
         L_MSEG_B_CAL_SUM TYPE MSEG-MENGE.

  DATA:    L_ANDEC TYPE   T006-ANDEC .

  DATA :  L_MSG TYPE CHAR50.   " 传递消息

  DATA: LT_ZPPT_0015_INT LIKE TABLE OF ZPPT_0015 ,       "    取订单消息
        LW_ZPPT_0015_INT LIKE LINE OF LT_ZPPT_0015_INT.


  DATA:  LT_T024D LIKE TABLE OF T024D WITH HEADER LINE .

  DATA : L_MESNGE TYPE  ZMM_BCBC-MESNGE .
  DATA:LV_MENGE TYPE EKPO-MENGE.


  TYPES : BEGIN OF TY_DAY_SUM,
            MATNR TYPE ZPPT_0015-MATNR,
            AUFNR TYPE ZPPT_0015-AUFNR,
            MENGE TYPE  ZPPT_0015-MENGE,

          END OF TY_DAY_SUM.

  DATA:  LT_DAY_SUM TYPE  TABLE OF      TY_DAY_SUM .  " 汇总日包材数量

  DATA: LW_DAY_SUM  LIKE LINE OF  LT_DAY_SUM .

  DATA : LV_TOTAL TYPE  I .  " 定义内表行数
  DATA: LT_MARA LIKE TABLE OF MARA,
        LW_MARA LIKE LINE OF  LT_MARA.

  DATA: LT_AUSP LIKE TABLE OF AUSP,
        LW_AUSP LIKE LINE OF LT_AUSP.



*     "  日包材数量定义.
*      data : lt_resb  like TABLE OF  resb,
*             lw_resb  like LINE OF resb .

*
*    data : l_MENGE_sum  type   ZPPT_0015-MENGE  . " 日包材汇总

  "  周计划数据
  SELECT *
   INTO CORRESPONDING FIELDS OF TABLE LT_ZPPT_0014
  FROM ZPPT_0014
  WHERE  ( ZSFSD = '' OR   ZSFSD = 2 ) .

    SORT  LT_ZPPT_0014  BY ZZJHID ZZJHHH ERSDA ERFZEIT DESCENDING .

    LOOP AT LT_ZPPT_0014  INTO LW_ZPPT_0014 .

      LW_ZPPT_0014_SUM-ZZJHID =  LW_ZPPT_0014-ZZJHID .
      LW_ZPPT_0014_SUM-ZZJHHH =  LW_ZPPT_0014-ZZJHHH .
      LW_ZPPT_0014_SUM-MATNR =  LW_ZPPT_0014-MATNR .
      LW_ZPPT_0014_SUM-MENGE =  LW_ZPPT_0014-MENGE .

      COLLECT LW_ZPPT_0014_SUM  INTO  LT_ZPPT_0014_SUM .

      CLEAR:LW_ZPPT_0014,LW_ZPPT_0014_SUM .
    ENDLOOP .




    LOOP AT LT_ZPPT_0014_SUM INTO LW_ZPPT_0014_SUM.



      CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
        EXPORTING
          I_MATNR              = LW_ZPPT_0014_SUM-MATNR
          I_IN_ME              = 'PC'
          I_OUT_ME             = 'KG'
          I_MENGE              = 1
        IMPORTING
          E_MENGE              = LV_MENGE
        EXCEPTIONS
          ERROR_IN_APPLICATION = 1
          ERROR                = 2
          OTHERS               = 3.
      LW_ZPPT_0014_SUM-MENGE = LW_ZPPT_0014_SUM-MENGE * LV_MENGE.


      CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
        EXPORTING
          AUMGB                 = 'X'
          AUSKZ                 = 'X'
          CAPID                 = 'PP01'
          DATUV                 = SY-DATUM
          EHNDL                 = '1'
          MEHRS                 = 'X'
          MTNRV                 = LW_ZPPT_0014_SUM-MATNR
          WERKS                 = '1100'
          EMENG                 = LW_ZPPT_0014_SUM-MENGE
          STLAN                 = '1'
*         STLAL                 = '01'
        TABLES
          STB                   = LT_STB
          MATCAT                = LT_MATCAT
        EXCEPTIONS
          ALT_NOT_FOUND         = 1
          CALL_INVALID          = 2
          MATERIAL_NOT_FOUND    = 3
          MISSING_AUTHORIZATION = 4
          NO_BOM_FOUND          = 5
          NO_PLANT_DATA         = 6
          NO_SUITABLE_BOM_FOUND = 7
          CONVERSION_ERROR      = 8
          OTHERS                = 9.
      IF SY-SUBRC = 0.
        LOOP AT LT_STB INTO DATA(LS_STB) WHERE MTART <> 'A002'.


          LW_ZPPT_0017-ZZJHID   =  LW_ZPPT_0014_SUM-ZZJHID.
          LW_ZPPT_0017-ZZJHHH   =  LW_ZPPT_0014_SUM-ZZJHHH.
          LW_ZPPT_0017-MATNR1   =  LS_STB-IDNRK.
          LW_ZPPT_0017-MATNR   =  LW_ZPPT_0014_SUM-MATNR .
          LW_ZPPT_0017-MENGE   =  LW_ZPPT_0014_SUM-MENGE.
          LW_ZPPT_0017-MENGE1   =  LS_STB-MNGLG.
          LW_ZPPT_0017-MEINS1   =  LS_STB-MEINS.
          APPEND  LW_ZPPT_0017  TO LT_ZPPT_0017  .

          CLEAR: GS_DATA, LW_ZPPT_0017  .
        ENDLOOP.


      ENDIF.



    ENDLOOP.




    "  限制取数逻辑


    IF  LT_ZPPT_0017 IS NOT INITIAL .

      SELECT * INTO TABLE LT_MARA
        FROM MARA
        FOR ALL ENTRIES IN LT_ZPPT_0017
        WHERE MATNR = LT_ZPPT_0017-MATNR1   .



      ENDIF.


      SELECT * INTO TABLE LT_AUSP
        FROM AUSP
        WHERE OBJEK IN ('A101' , 'A103' , 'A104')  AND ATINN =  '0000000871'.



        LOOP AT   LT_ZPPT_0017  INTO LW_ZPPT_0017 .

          READ TABLE LT_MARA  INTO LW_MARA WITH KEY MATNR =  LW_ZPPT_0017-MATNR1.
          IF SY-SUBRC = 0.

            READ TABLE LT_AUSP  INTO  LW_AUSP WITH KEY ATWRT  =  LW_MARA-MATKL .
            IF SY-SUBRC = 0 .
              MOVE-CORRESPONDING LW_ZPPT_0017  TO  LW_ZPPT_0017_CON .
              APPEND LW_ZPPT_0017_CON  TO LT_ZPPT_0017_CON  .


            ENDIF.

          ENDIF.
          CLEAR:LW_ZPPT_0017, LW_MARA, LW_AUSP.

        ENDLOOP.


        CLEAR: LT_ZPPT_0017 , LT_MARA.



        LT_ZPPT_0017 =  LT_ZPPT_0017_CON .
        IF  LT_ZPPT_0017 IS NOT INITIAL .
          MODIFY  ZPPT_0017 FROM TABLE  LT_ZPPT_0017  .
          IF SY-SUBRC = 0.
            COMMIT WORK .

          ENDIF.
        ENDIF.


        "  组装OTB周包材需求数据




        LOOP AT  LT_ZPPT_0017  INTO LW_ZPPT_0017 .

          READ TABLE  LT_ZPPT_0014  INTO   LW_ZPPT_0014  WITH KEY ZZJHID  =   LW_ZPPT_0017-ZZJHID     ZZJHHH  = LW_ZPPT_0017-ZZJHHH .
          IF SY-SUBRC = 0.



            LW_OTB_WEEK_ITEM-MATNR    =      LW_ZPPT_0017-MATNR1     .
            LW_OTB_WEEK_ITEM-QUAN    =       LW_ZPPT_0017-MENGE1    .
            LW_OTB_WEEK_ITEM-UNIT    =       LW_ZPPT_0017-MEINS1  .

            SELECT SINGLE  MESNGE  INTO  L_MESNGE
        FROM ZMM_BCBC
            WHERE MATNR =  LW_ZPPT_0017-MATNR1  .

              IF L_MESNGE IS NOT INITIAL.
                LW_OTB_WEEK_ITEM-ZTS     =   LW_ZPPT_0017-MENGE   /    L_MESNGE    .
              ENDIF.
              LW_OTB_WEEK_ITEM-VERSION =        ''   .

              APPEND   LW_OTB_WEEK_ITEM  TO IT_OTB_WEEK_ITEM      .
              AT END OF ZZJHID .



                LW_OTB_WEEK_HEAD-ZYDJH  = LW_ZPPT_0014-ZYJHID .
                LW_OTB_WEEK_HEAD-YEAR   = LW_ZPPT_0014-ZND .
                LW_OTB_WEEK_HEAD-MONTH   = LW_ZPPT_0014-ZYD .
                LW_OTB_WEEK_HEAD-AUFNR   = '' .
                LW_OTB_WEEK_HEAD-WEEKID  =  LW_ZPPT_0014-ZZJHID .
                LW_OTB_WEEK_HEAD-WERKS   =  '1100' .
                LW_OTB_WEEK_HEAD-PLINE   =     LW_ZPPT_0014-DISPO .
                SELECT  *  INTO CORRESPONDING FIELDS OF TABLE LT_T024D FROM  T024D  WHERE  DISPO  = LW_ZPPT_0014-DISPO .
                  READ TABLE  LT_T024D INTO LT_T024D INDEX 1.

                  LW_OTB_WEEK_HEAD-NAME  = LT_T024D-DSNAM .
                  LW_OTB_WEEK_HEAD-MATNR1    =  LW_ZPPT_0014-MATNR  .
                  LW_OTB_WEEK_HEAD-QUAN1   =  LW_ZPPT_0014-MENGE .
                  LW_OTB_WEEK_HEAD-BEGINDATE  =  LW_ZPPT_0014-GSTRP .
                  LW_OTB_WEEK_HEAD-ZXH        =  LW_ZPPT_0014-ZXH .
                  LW_OTB_WEEK_HEAD-ENDDATE    =  LW_ZPPT_0014-GLTRP .
                  LW_OTB_WEEK_HEAD-STATUS    =  LW_ZPPT_0014-ZSTATE1 .

                  IF  LW_ZPPT_0014-DISPO = 'Z01' OR  LW_ZPPT_0014-DISPO ='Z02 ' OR LW_ZPPT_0014-DISPO = 'Z03' OR
                    LW_ZPPT_0014-DISPO = 'Z04' OR  LW_ZPPT_0014-DISPO = 'Z05' OR   LW_ZPPT_0014-DISPO = 'Z06'  .
                    LW_OTB_WEEK_HEAD-LGORT    =  '2100' .
                  ENDIF.
                  LW_OTB_WEEK_HEAD-OWEEKID    =   LW_ZPPT_0014-ZYLID .

                  CALL FUNCTION 'ZFM_OTB_0058'
                    EXPORTING
                      IS_HEAD    = LW_OTB_WEEK_HEAD
                    IMPORTING
                      EV_MESSAGE = LV_MESSAGE
                    TABLES
                      IT_ITEM    = IT_OTB_WEEK_ITEM.

                  CLEAR: LW_OTB_WEEK_HEAD, IT_OTB_WEEK_ITEM.
                ENDAT .


              ENDIF.



              CLEAR:LW_ZPPT_0017 , LW_OTB_WEEK_ITEM  ,LT_T024D .


            ENDLOOP.





            "  组装EWM周计划数据

            LOOP AT  LT_ZPPT_0017  INTO LW_ZPPT_0017 .

              READ TABLE LT_ZPPT_0014  INTO LW_ZPPT_0014  WITH KEY  ZZJHID  =   LW_ZPPT_0017-ZZJHID     ZZJHHH  = LW_ZPPT_0017-ZZJHHH .

              IF SY-SUBRC = 0 .


                LW_ZSEWM0002_ITEM-MATNR  =  LW_ZPPT_0017-MATNR1 .
                LW_ZSEWM0002_ITEM-QUAN   =   LW_ZPPT_0017-MENGE1    .
                LW_ZSEWM0002_ITEM-UNIT   =    LW_ZPPT_0017-MEINS1   .
                SELECT SINGLE  MESNGE  INTO  L_MESNGE
                       FROM ZMM_BCBC
                           WHERE MATNR =  LW_ZPPT_0017-MATNR1  .
                  IF L_MESNGE  IS NOT INITIAL.
                    LW_ZSEWM0002_ITEM-PALLET_QTY  =   LW_ZPPT_0017-MENGE  /  L_MESNGE .
                  ENDIF.
                  LW_ZSEWM0002_ITEM-VERSION      =  ''  .
                  APPEND LW_ZSEWM0002_ITEM  TO LT_ZSEWM0002_ITEM .

                  AT END OF ZZJHID .
*                  LW_ZSEWM0002_ITEM-MATNR  =  LW_ZPPT_0017-MATNR .
*                LW_ZSEWM0002_ITEM-QUAN   =   LW_ZPPT_0017-MENGE    .
*                LW_ZSEWM0002_ITEM-UNIT   =    LW_ZPPT_0017-MEINS1   .
*                 SELECT SINGLE  MESNGE  INTO  L_MESNGE
*                        FROM ZMM_BCBC
*                            WHERE MATNR =  LW_ZPPT_0017-MATNR  .
*                   IF L_MESNGE  IS NOT INITIAL.
*                LW_ZSEWM0002_ITEM-PALLET_QTY  =   LW_ZPPT_0017-MENGE  /  L_MESNGE .
*                  ENDIF.
*                LW_ZSEWM0002_ITEM-VERSION      =  ''  .
*                APPEND LW_ZSEWM0002_ITEM  TO LT_ZSEWM0002_ITEM .
                    IW_EWM_WEEK_ITEM-YEAR    =   LW_ZPPT_0014-ZND .
                    IW_EWM_WEEK_ITEM-MONTH  =    LW_ZPPT_0014-ZYD .
                    IW_EWM_WEEK_ITEM-MONTH_ID =   LW_ZPPT_0014-ZYJHID.
                    IW_EWM_WEEK_ITEM-WEEK_ID   =  LW_ZPPT_0014-ZZJHID .
                    IW_EWM_WEEK_ITEM-WEEK_NO  =   LW_ZPPT_0014-ZZJHHH .
                    IW_EWM_WEEK_ITEM-OWEEK_ID  =  LW_ZPPT_0014-ZYLID .
                    IW_EWM_WEEK_ITEM-PLINE    =  LW_ZPPT_0014-DISPO .
                    SELECT  *  INTO CORRESPONDING FIELDS OF TABLE LT_T024D FROM  T024D  WHERE  DISPO  = LW_ZPPT_0014-DISPO .
                      READ TABLE  LT_T024D INTO LT_T024D INDEX 1.

                      IW_EWM_WEEK_ITEM-NAME     =  LT_T024D-DSNAM .
                      IW_EWM_WEEK_ITEM-WERKS    =  '1100' .
                      IF  LW_ZPPT_0014-DISPO = 'Z01' OR  LW_ZPPT_0014-DISPO ='Z02 ' OR LW_ZPPT_0014-DISPO = 'Z03' OR
                                    LW_ZPPT_0014-DISPO = 'Z04' OR  LW_ZPPT_0014-DISPO = 'Z05' OR   LW_ZPPT_0014-DISPO = 'Z06'  .
                        IW_EWM_WEEK_ITEM-LGORT    =   '2100'  .
                      ENDIF.
                      IW_EWM_WEEK_ITEM-AUFNR    =  ''.
                      IW_EWM_WEEK_ITEM-MATNR   =   LW_ZPPT_0014-MATNR .
                      IW_EWM_WEEK_ITEM-QUAN   =   LW_ZPPT_0014-MENGE .
                      IW_EWM_WEEK_ITEM-UNIT   =    LW_ZPPT_0014-MEINS.
                      IW_EWM_WEEK_ITEM-BEGIN_DATE = LW_ZPPT_0014-GSTRP .
                      IW_EWM_WEEK_ITEM-END_DATE   = LW_ZPPT_0014-GLTRP .
                      IW_EWM_WEEK_ITEM-STATUS    =  LW_ZPPT_0014-ZSTATE1 .

                      IW_EWM_WEEK_ITEM-ITEM  =  LT_ZSEWM0002_ITEM.
                      APPEND IW_EWM_WEEK_ITEM TO  IT_EWM_WEEK_ITEM .

                      CALL FUNCTION 'ZEWMZHGC_FM_002'
                        EXPORTING
                          IN_TAB  = IT_EWM_WEEK_ITEM
                        IMPORTING
                          EV_CODE = ZSTATUS_EWM_WEEK
                          EV_MSG  = ZMESSAGE_EWM_WEEK.

                      CLEAR: IT_EWM_WEEK_ITEM[].

                    ENDAT .


                  ENDIF.
                  CLEAR:LW_ZPPT_0014 , LW_ZPPT_0017  ,LT_T024D .

                ENDLOOP.






                "  日计划数据
                SELECT *
                   INTO CORRESPONDING FIELDS OF TABLE LT_ZPPT_0015
                  FROM ZPPT_0015
                  WHERE  ( ZSFSD = '' OR   ZSFSD = 2 )
                   AND   DISPO  IN ( 'Z01','Z02' ,'Z03'  ,'Z04'  ,'Z05' ,'Z06' ) .



                  LOOP AT  LT_ZPPT_0015 INTO  LW_ZPPT_0015 .

                    IF LW_ZPPT_0015-ZSFSD  = '2' .
                      MOVE-CORRESPONDING  LW_ZPPT_0015  TO LW_ZPPT_0015_Q.
                      APPEND LW_ZPPT_0015_Q TO LT_ZPPT_0015_Q .

                    ELSE .

                      MOVE-CORRESPONDING  LW_ZPPT_0015  TO LW_ZPPT_0015_W.
                      APPEND LW_ZPPT_0015_W TO LT_ZPPT_0015_W .

                    ENDIF.

                    CLEAR:LW_ZPPT_0015,LW_ZPPT_0015_Q ,LW_ZPPT_0015_W.


                  ENDLOOP.

                  SORT LT_ZPPT_0015_W  BY AUFNR MENGE DESCENDING.


                  IF LT_ZPPT_0015_W IS NOT INITIAL.
                    SELECT *
                       INTO CORRESPONDING FIELDS OF TABLE LT_RESB
                      FROM RESB
                      INNER JOIN CAUFV ON  RESB~RSNUM  =  CAUFV~RSNUM
                      FOR ALL ENTRIES IN LT_ZPPT_0015_W
                      WHERE RESB~AUFNR =  LT_ZPPT_0015_W-AUFNR .
                    ENDIF.










                    "  汇总成品数量

                    LOOP AT LT_ZPPT_0015_W  INTO LW_ZPPT_0015_W .
                      LW_ZPPT_0015_SUM-AUFNR  =  LW_ZPPT_0015_W-AUFNR.
                      LW_ZPPT_0015_SUM-MENGE  =  LW_ZPPT_0015_W-MENGE.

                      COLLECT LW_ZPPT_0015_SUM  INTO LT_ZPPT_0015_SUM .

                      CLEAR:LW_ZPPT_0015_SUM,LW_ZPPT_0015_W .

                    ENDLOOP.








                    " 计算日包材用量


                    SORT LT_ZPPT_0015_W  BY AUFNR MENGE .

                    LOOP AT LT_ZPPT_0015_SUM  INTO  LW_ZPPT_0015_SUM  .


                      LOOP AT  LT_ZPPT_0015_W  INTO LW_ZPPT_0015_W WHERE AUFNR = LW_ZPPT_0015_SUM-AUFNR .

                        MOVE-CORRESPONDING  LW_ZPPT_0015_W  TO  LW_ZPPT_0015_M .

                        APPEND LW_ZPPT_0015_M  TO LT_ZPPT_0015_M .


                        CLEAR: LW_ZPPT_0015_W, LW_ZPPT_0015_M.
                      ENDLOOP .


                      L_MENGE_B_SUM =  LW_ZPPT_0015_SUM-MENGE.



                      DESCRIBE TABLE  LT_ZPPT_0015_M LINES LV_TOTAL.

                      LOOP AT  LT_ZPPT_0015_M  INTO LW_ZPPT_0015_M   .

                        L_INDEX = SY-TABIX.






                        IF   L_INDEX <  LV_TOTAL.
                          LOOP AT LT_RESB  INTO LW_RESB  WHERE AUFNR =  LW_ZPPT_0015_M-AUFNR.
                            MOVE-CORRESPONDING  LW_ZPPT_0015_M  TO LW_ZPPT_0015_DAY .

                            LW_ZPPT_0015_DAY-MATNR1   =  LW_RESB-MATNR.

                            LW_ZPPT_0015_DAY-MIENS1   =  LW_RESB-MEINS.
                            LW_ZPPT_0015_DAY-QUAN   =   LW_RESB-BDMNG  *  LW_ZPPT_0015_M-MENGE /  L_MENGE_B_SUM .
                            SELECT SINGLE ANDEC  INTO   L_ANDEC  FROM T006  WHERE MSEHI =  LW_RESB-MEINS.


                              IF   L_ANDEC   IS NOT INITIAL.

                                CALL FUNCTION 'ROUND'
                                  EXPORTING
                                    DECIMALS      = L_ANDEC       " 保留多少位
                                    INPUT         = LW_ZPPT_0015_DAY-QUAN
                                    SIGN          = '+'     " + 向上取舍
                                  IMPORTING
                                    OUTPUT        = LW_ZPPT_0015_DAY-QUAN
                                  EXCEPTIONS
                                    INPUT_INVALID = 1
                                    OVERFLOW      = 2
                                    TYPE_INVALID  = 3
                                    OTHERS        = 4.

                              ENDIF.

                              LW_DAY_SUM-MATNR =  LW_RESB-MATNR.
                              LW_DAY_SUM-AUFNR =  LW_RESB-AUFNR.
                              LW_DAY_SUM-MENGE =  LW_ZPPT_0015_DAY-QUAN.


                              READ TABLE  LT_DAY_SUM   INTO LW_DAY_SUM   WITH KEY MATNR =  LW_RESB-MATNR  AUFNR = LW_RESB-AUFNR .

                              IF SY-SUBRC = 0 .

                                LW_DAY_SUM-MENGE =   LW_ZPPT_0015_DAY-QUAN +  LW_DAY_SUM-MENGE.

                                MODIFY  LT_DAY_SUM  FROM   LW_DAY_SUM  TRANSPORTING  MENGE  WHERE  MATNR = LW_RESB-MATNR AND AUFNR = LW_RESB-AUFNR .


                              ELSE .
                                APPEND  LW_DAY_SUM   TO LT_DAY_SUM .

                              ENDIF.


                              APPEND  LW_ZPPT_0015_DAY  TO LT_ZPPT_0015_DAY   .



                            ENDLOOP.



                          ELSE    .


                            LOOP AT LT_RESB  INTO LW_RESB  WHERE AUFNR =  LW_ZPPT_0015_M-AUFNR.
                              MOVE-CORRESPONDING  LW_ZPPT_0015_M  TO LW_ZPPT_0015_DAY .


                              READ TABLE LT_DAY_SUM   INTO  LW_DAY_SUM WITH KEY  AUFNR =  LW_RESB-AUFNR  MATNR  = LW_RESB-MATNR.

                              IF SY-SUBRC =  0 .
                                LW_ZPPT_0015_DAY-MATNR1   =  LW_RESB-MATNR.

                                LW_ZPPT_0015_DAY-MIENS1   =  LW_RESB-MEINS.

                                LW_ZPPT_0015_DAY-QUAN   =   LW_RESB-BDMNG -  LW_DAY_SUM-MENGE  .

                              ENDIF.

                              SELECT SINGLE ANDEC  INTO   L_ANDEC  FROM T006  WHERE MSEHI =  LW_RESB-MEINS.


                                IF   L_ANDEC   IS NOT INITIAL.

                                  CALL FUNCTION 'ROUND'
                                    EXPORTING
                                      DECIMALS      = L_ANDEC       " 保留多少位
                                      INPUT         = LW_ZPPT_0015_DAY-QUAN
                                      SIGN          = '+'     " + 向上取舍
                                    IMPORTING
                                      OUTPUT        = LW_ZPPT_0015_DAY-QUAN
                                    EXCEPTIONS
                                      INPUT_INVALID = 1
                                      OVERFLOW      = 2
                                      TYPE_INVALID  = 3
                                      OTHERS        = 4.

                                ENDIF.

                                APPEND  LW_ZPPT_0015_DAY  TO LT_ZPPT_0015_DAY   .


                              ENDLOOP.


                            ENDIF.



                            CLEAR:  L_INDEX .





                          ENDLOOP.

                        ENDLOOP.

                        CLEAR: LT_ZPPT_0015_W.


                        LT_ZPPT_0015_W  = LT_ZPPT_0015_DAY   .

                        CLEAR:  LT_ZPPT_0015_DAY.


                             " 限制取数逻辑

                        IF   LT_ZPPT_0015_W IS NOT INITIAL .

                          SELECT * INTO TABLE LT_MARA
                            FROM MARA
                            FOR ALL ENTRIES IN  LT_ZPPT_0015_W
                            WHERE MATNR =  LT_ZPPT_0015_W-MATNR1   .

                          ENDIF.


                          LOOP AT  LT_ZPPT_0015_W INTO  LW_ZPPT_0015_W .


                            READ TABLE LT_MARA  INTO LW_MARA WITH KEY MATNR =  LW_ZPPT_0015_W-MATNR1.
                            IF SY-SUBRC = 0.

                              READ TABLE LT_AUSP  INTO  LW_AUSP WITH KEY ATWRT  =  LW_MARA-MATKL .
                              IF SY-SUBRC = 0 .
                                MOVE-CORRESPONDING LW_ZPPT_0015_W  TO  LW_ZPPT_0015_DAY .
                                APPEND  LW_ZPPT_0015_DAY   TO  LT_ZPPT_0015_DAY   .


                              ENDIF.

                            ENDIF.
                            CLEAR:LW_ZPPT_0015_W, LW_MARA, LW_AUSP.


                          ENDLOOP.

                          LT_ZPPT_0015_W  = LT_ZPPT_0015_DAY   .

                          CLEAR:  LT_ZPPT_0015_DAY.

                          "  组装OTB所需要数据
*                          SORT LT_ZPPT_0015_W  BY ZRJHID.
                          LOOP AT LT_ZPPT_0015_W INTO  LW_ZPPT_0015_W.



                            LW_OTB_DAY_ITEM-MATNR1   =    LW_ZPPT_0015_W-MATNR1.
                            LW_OTB_DAY_ITEM-QUAN  =    LW_ZPPT_0015_W-QUAN.
                            LW_OTB_DAY_ITEM-MEINS  =    LW_ZPPT_0015_W-MIENS1 .
                            SELECT SINGLE  MESNGE  INTO  L_MESNGE
                                        FROM ZMM_BCBC
                                            WHERE MATNR =  LW_ZPPT_0015_W-MATNR1  .

                              IF L_MESNGE IS NOT INITIAL.
                                LW_OTB_DAY_ITEM-ZTS   =   LW_ZPPT_0015_W-QUAN  / L_MESNGE.
                              ENDIF.
                              LW_OTB_DAY_ITEM-VERSION   = ''.
                              LW_OTB_DAY_ITEM-OWEEKID    =  '' .

                              APPEND LW_OTB_DAY_ITEM TO LT_OTB_DAY_ITEM .


                              LW_OTB_DAY_HEAD-USER    =  SY-UNAME.
                              LW_OTB_DAY_HEAD-CRDAT   =  SY-DATUM .
                              LW_OTB_DAY_HEAD-CRDTM   =  SY-UZEIT .
                              LW_OTB_DAY_HEAD-DAYID   =  LW_ZPPT_0015_W-ZRJHID .
                              LW_OTB_DAY_HEAD-AUFNR   =  LW_ZPPT_0015_W-AUFNR .
                              LW_OTB_DAY_HEAD-WEEKID  =  LW_ZPPT_0015_W-ZZJHID .
                              LW_OTB_DAY_HEAD-DAYTYPE  =  '' .
                              LW_OTB_DAY_HEAD-WERKS    =  '1100'.
                              LW_OTB_DAY_HEAD-PLINE   = LW_ZPPT_0015_W-ZCXBM .
*          SELECT  *  INTO CORRESPONDING FIELDS OF TABLE LT_T024D FROM  T024D  WHERE  DISPO  = LW_ZPPT_0015_W-DISPO .
                              LW_OTB_DAY_HEAD-NAME   = LT_T024D-DSNAM .
                              LW_OTB_DAY_HEAD-MATNR  =  LW_ZPPT_0015_W-MATNR .
                              LW_OTB_DAY_HEAD-QUAN   =  LW_ZPPT_0015_W-MENGE .
                              LW_OTB_DAY_HEAD-DATE   =  LW_ZPPT_0015_W-ERSDA .


                              AT END OF ZRJHID.



                                CALL FUNCTION 'ZFM_OTB_0057'
                                  EXPORTING
                                    IS_HEAD    = LW_OTB_DAY_HEAD
                                  IMPORTING
                                    EV_MESSAGE = LV_MESSAGE_OTB_DAY
                                  TABLES
                                    IT_ITEM    = LT_OTB_DAY_ITEM.
                                CLEAR:LW_OTB_DAY_HEAD, LT_OTB_DAY_ITEM.

                              ENDAT.


                              CLEAR: LW_ZPPT_0015_W  .
                            ENDLOOP.






                            "   组装EWM所需要数据.
                            LOOP AT LT_ZPPT_0015_W INTO  LW_ZPPT_0015_W.



                              LW_EWM_DAY-MATNR   =  LW_ZPPT_0015_W-MATNR1.
                              LW_EWM_DAY-QUAN     = LW_ZPPT_0015_W-QUAN.
                              LW_EWM_DAY-UNIT    = LW_ZPPT_0015_W-MIENS1.


                              LW_EWM_DAY-OWEEK_ID  = ''  .

                              LW_EWM_DAY-PALLET_QTY =  '' .
                              APPEND  LW_EWM_DAY TO LT_EWM_DAY .

                              LW_EWM_DAY_ITEM-WEEK_ID   = LW_ZPPT_0015_W-ZZJHID .
                              LW_EWM_DAY_ITEM-DAY_ID  = LW_ZPPT_0015_W-ZRJHID.
                              LW_EWM_DAY_ITEM-DAY_TYPE   =  ''.
                              LW_EWM_DAY_ITEM-WERKS = LW_ZPPT_0015_W-ZZD.
                              LW_EWM_DAY_ITEM-PLINE   = LW_ZPPT_0015_W-ZCXBM.
*                 SELECT  *  INTO CORRESPONDING FIELDS OF TABLE LT_T024D FROM  T024D  WHERE  DISPO  = LW_ZPPT_0015_W-DISPO .

                              LW_EWM_DAY_ITEM-NAME  = LT_T024D-DSNAM .
                              LW_EWM_DAY_ITEM-AUFNR  = LW_ZPPT_0015_W-AUFNR.
                              LW_EWM_DAY_ITEM-MATNR   = LW_ZPPT_0015_W-MATNR.
                              LW_EWM_DAY_ITEM-QUAN   = LW_ZPPT_0015_W-MENGE.
                              LW_EWM_DAY_ITEM-UNIT   = LW_ZPPT_0015_W-MEINS.
                              LW_EWM_DAY_ITEM-PROD_DATE   = LW_ZPPT_0015_W-ERSDA.
                              LW_EWM_DAY_ITEM-STATUS = LW_ZPPT_0015_W-ZSTATE1.

                              AT END OF ZRJHID .


                                LW_EWM_DAY_ITEM-ITEM =  LT_EWM_DAY.
                                APPEND  LW_EWM_DAY_ITEM  TO  LT_EWM_DAY_ITEM .


                                CALL FUNCTION 'ZEWMZHGC_FM_003'
                                  EXPORTING
                                    IN_TAB  = LT_EWM_DAY_ITEM
                                  IMPORTING
                                    EV_CODE = L_ZSTATUS_EWM_DAY
                                    EV_MSG  = L_ZMESSAGE_EWM_DAY.

                                CLEAR:LT_EWM_DAY_ITEM .

                              ENDAT.

                              CLEAR:LW_ZPPT_0015_W ,LW_EWM_DAY .


                            ENDLOOP .

*          CONCATENATE   L_MSG   '日计划EWM'L_ZMESSAGE_EWM_DAY   INTO L_MSG  .


                            "   组装日计划MES数据
                            LOOP AT LT_ZPPT_0015_W INTO  LW_ZPPT_0015_W.

                              LW_MES_DAY_ITEM-MATNR1   =  LW_ZPPT_0015_W-MATNR1.
                              LW_MES_DAY_ITEM-QUAN       =  LW_ZPPT_0015_W-QUAN.
                              LW_MES_DAY_ITEM-VERSION    =   '' .
                              LW_MES_DAY_ITEM-OWEEKID     =   ''.
                              LW_MES_DAY_ITEM-ZTS        =   ''.
                              LW_MES_DAY_ITEM-STATUS     =   ''.
                              APPEND  LW_MES_DAY_ITEM  TO  LT_MES_DAY_ITEM  .
                              LW_MES_DAY_HEAD-WEEKID    = LW_ZPPT_0015_W-ZZJHID .
                              LW_MES_DAY_HEAD-DAYID    =  LW_ZPPT_0015_W-ZRJHID .
                              LW_MES_DAY_HEAD-DAYTYPE   =  '' .
                              LW_MES_DAY_HEAD-WERKS   =  LW_ZPPT_0015_W-ZZD .
                              LW_MES_DAY_HEAD-PLINE    =  LW_ZPPT_0015_W-ZCXBM .
                              LW_MES_DAY_HEAD-AUFNR    =    LW_ZPPT_0015_W-AUFNR .
                              LW_MES_DAY_HEAD-MATNR  =   LW_ZPPT_0015_W-MATNR  .
                              LW_MES_DAY_HEAD-QUAN     =   LW_ZPPT_0015_W-MENGE .
                              LW_MES_DAY_HEAD-DATE    =       LW_ZPPT_0015_W-ERSDA .

                              AT END OF ZRJHID .

                                CALL FUNCTION 'ZMESZHGC_FM_009'
                                  EXPORTING
                                    IS_HEAD   = LW_MES_DAY_HEAD
                                    IT_ITEM   = LT_MES_DAY_ITEM
                                  IMPORTING
                                    ES_RETURN = L_ES_RETURN_MES.
*            ev_code        =   lv_code
*            ev_msg          =   LV_MESSAGE .              .
                                CLEAR: LW_MES_DAY_HEAD, LT_MES_DAY_ITEM.

                              ENDAT.



                            ENDLOOP.


你可能感兴趣的:(ABAP,abap)