ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 22222222222

22222222222

原创 Linux操作系统 作者:ftsz0079 时间:2012-07-16 16:47:44 0 删除 编辑

START-OF-SELECTION.
************************************************************************
* Main data selection routine
************************************************************************
  IF STK EQ 'X'.
    PERFORM. INIT_DATA.
    PERFORM. GET_STK.
    PERFORM. DATA_SELECTION.
    READ TABLE BESTAND INDEX 1 TRANSPORTING NO FIELDS.
    IF SY-SUBRC = 0.
      PERFORM  DISPLAY_GRID.
      PERFORM  DISPLAY_DATA.
    ELSE.
      MESSAGE S843.
*   Zu den vorgegebenen Daten ist kein Bestand vorhanden
      IF NOT SY-CALLD IS INITIAL.                           "307852
        LEAVE.                                              "307852
      ELSE.                                                 "307852
        LEAVE TO TRANSACTION SY-TCODE.                      "307852
      ENDIF.                                                "307852
    ENDIF.
  ELSEIF WIP EQ 'X'.
    PERFORM. GET_WIP.
    PERFORM. GET_WIP_GRID_DISPLAY.
    PERFORM. GET_WIP_DATA_DISPLAY.
  ELSEIF PRD EQ 'X'.
    PERFORM. INIT_DATA.
    PERFORM. GET_STK.
    PERFORM. DATA_SELECTION.
    READ TABLE BESTAND INDEX 1 TRANSPORTING NO FIELDS.
    IF SY-SUBRC NE 0.
      MESSAGE 'No found data,please check!' TYPE 'I'.
      STOP.
*    ELSE.
*      READ TABLE BESTAND WITH KEY AUFNR = SPACE.
*      CONCATENATE 'The product:' BESTAND-MATNR  'can not expore,Please check!' INTO CHAR1.
*      MESSAGE CHAR1  TYPE 'I'.
*      STOP.
    ENDIF.
    PERFORM. CONSUMPTION_MATERIAL.
    PERFORM. CONSUPTION_GRID_DISPLAY.
    PERFORM. CONSUPTION_DATA_DISPLAY.
  ELSEIF COM EQ 'X'.
    IF XMCHB NE SPACE.
      MESSAGE '合并报表运行,不可包含批次,请检查!'  TYPE 'I'.
      STOP.
    ENDIF.
    PERFORM. INIT_DATA.
    PERFORM. GET_STK.
    PERFORM. DATA_SELECTION.
    READ TABLE BESTAND INDEX 1 TRANSPORTING NO FIELDS.
    CHECK SY-SUBRC = 0.
    IF BYMATR EQ 'X'.
      PERFORM  COMBINE_DATA1.
      PERFORM  COMBINE_DISPLAY_GRID1.
      PERFORM  COMBINE_DISPLAY_DATA1.
    ELSE.
      PERFORM  COMBINE_DATA.
      PERFORM  COMBINE_DISPLAY_GRID.
      PERFORM  COMBINE_DISPLAY_DATA.
    ENDIF.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  GET_STK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. GET_STK .
* it makes no sence to carry out this report
  IF  G_CNT_VARIANT_ERROR > 0.
    IF  NOT SY-SLSET IS INITIAL.
      MESSAGE E634(DB)       WITH  SY-SLSET SY-REPID.
    ENDIF.
  ENDIF.

* does the user restrict the storage locations and want to
* suppress stock objects from plant level ?
  CLEAR                      COLLECTOR-LGORT.

  IF  COLLECTOR-LGORT IN LGORT.
    CLEAR                    G_FLAG_SUPPRESS_INIT_LGORT.
  ELSE.
    MOVE  'X'                TO  G_FLAG_SUPPRESS_INIT_LGORT.
  ENDIF.

ENDFORM.                    " GET_STK

*-------------------------- Datenausgabe-------------------------------*
END-OF-SELECTION.

************************************************************************
* Read organisation
************************************************************************
FORM. ORGANISATION.

* get all existing storage bins of the required plants
  REFRESH : G_T_T001L, G_T_ORGAN.
  CLEAR   : G_S_T001L, G_S_ORGAN, G_FLAG_T001L.

  SELECT  WERKS LGORT LGOBE  FROM T001L
                   INTO CORRESPONDING FIELDS OF TABLE G_T_T001L
                   WHERE  WERKS IN WERKS
                     AND  LGORT IN LGORT
                     AND  LGOBE NE SPACE.

  IF  SY-SUBRC IS INITIAL.
    MOVE  'X'                TO  G_FLAG_T001L.
  ENDIF.

  SELECT DISTINCT WERKS NAME1 BWKEY
                  INTO CORRESPONDING FIELDS OF TABLE G_T_ORGAN
                  FROM T001W
                  WHERE WERKS IN WERKS.

  SORT G_T_ORGAN             BY BWKEY.

  LOOP AT G_T_ORGAN          INTO  G_S_ORGAN.
    ON CHANGE OF G_S_ORGAN-BWKEY.
      CLEAR                  G_FLAG_OK.

      SELECT SINGLE * FROM T001K
                   WHERE BWKEY EQ G_S_ORGAN-BWKEY.

      IF SY-SUBRC IS INITIAL.
        SELECT SINGLE * FROM T001
                   WHERE BUKRS EQ T001K-BUKRS.

        IF SY-SUBRC IS INITIAL.
          MOVE  'X'          TO  G_FLAG_OK.
        ENDIF.
      ENDIF.
    ENDON.

    IF  G_FLAG_OK = 'X'.
      MOVE-CORRESPONDING T001  TO  G_S_ORGAN.
      MODIFY  G_T_ORGAN        FROM  G_S_ORGAN.
    ENDIF.
  ENDLOOP.

ENDFORM.                               " ORGANISATION

************************************************************************
* Check authorization on plant level for all selected plants
************************************************************************
FORM. CHECK_AUTHORIZATION.

* define local working areas
  DATA : L_S_BUKRS           TYPE  STYPE_BUFFER,
         L_T_BUKRS           TYPE  STAB_BUFFER.

  SORT   G_T_ORGAN           BY WERKS.

* report displayed stocks for plant although the user has   "n591618
* not the required authorization for that plant             "n591618
  CLEAR                      G_S_BUFFER.                    "n591618

  LOOP AT G_T_ORGAN          INTO  G_S_ORGAN.
*   check the authority only after the plant has changed    "n531604
    IF  G_S_ORGAN-WERKS NE G_S_BUFFER-WERKS.
      MOVE  G_S_ORGAN-WERKS  TO  G_S_BUFFER-WERKS.

      AUTHORITY-CHECK OBJECT 'M_MATE_WRK'
                     ID 'ACTVT' FIELD '03'
                     ID 'WERKS' FIELD G_S_ORGAN-WERKS.

      IF NOT SY-SUBRC IS INITIAL.
        SET  CURSOR          FIELD  'WERKS-LOW'.
        MESSAGE E120         WITH  G_S_ORGAN-WERKS.
      ENDIF.
    ENDIF.

    IF  NOVALUES IS INITIAL.                                "n531604
*     the user wants to see the values
      IF  G_S_ORGAN-BUKRS NE G_S_BUFFER-BUKRS.
*       check the authority after the company code changed
        AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
*           parameters for AUTHORITY-CHECK command fixed    "n546707
            ID 'BUKRS' FIELD G_S_ORGAN-BUKRS                "n546707
            ID 'ACTVT' FIELD '03'.                          "n546707

        MOVE : G_S_ORGAN-BUKRS    TO  G_S_BUFFER-BUKRS,     "n667256
               SY-SUBRC           TO  G_S_BUFFER-SUBRC.     "n667256

        IF SY-SUBRC <> 0.
*         no authorization -> save the company code
          MOVE : 'X'              TO  G_FLAG_MESS_333,
                 G_S_ORGAN-BUKRS  TO  L_S_BUKRS-BUKRS.
          COLLECT L_S_BUKRS       INTO  L_T_BUKRS.
        ENDIF.
      ENDIF.

*     use the result from the buffer
      IF  G_S_BUFFER-SUBRC <> 0.
        CLEAR                G_S_ORGAN-WAERS.
        MODIFY  G_T_ORGAN    FROM  G_S_ORGAN
                             TRANSPORTING  WAERS.
      ENDIF.
    ENDIF.
  ENDLOOP.

* send the info for each missing autority
  IF  G_FLAG_MESS_333  =  'X'.
    SORT                     L_T_BUKRS.
    SET CURSOR               FIELD  'WERKS-LOW'.

    LOOP AT L_T_BUKRS        INTO  L_S_BUKRS.
*     No authorization to display data for company code &
      MESSAGE  I862(M3)      WITH  L_S_BUKRS-BUKRS.
    ENDLOOP.
  ENDIF.

ENDFORM.                    "check_authorization

************************************************************************
* Check data on selection screen
************************************************************************
FORM. CHECK_ENTRY.

* Check some entered data for consistency
  CALL FUNCTION 'MMIM_ENTRYCHECK_MAIN'
    TABLES
      IT_MATNR = MATNR
      IT_WERKS = WERKS
      IT_LGORT = LGORT
      IT_EKGRP = EKGRUP
      IT_SOBKZ = SO_SOBKZ.

* Material type
  IF NOT MATART-LOW IS INITIAL OR NOT MATART-HIGH IS INITIAL.
    SELECT SINGLE * FROM T134M WHERE MTART IN MATART.
    IF NOT SY-SUBRC IS INITIAL.
      MESSAGE E104(M3) WITH MATART-LOW.
    ENDIF.
  ENDIF.

* Material class
  IF NOT MATKLA-LOW IS INITIAL OR NOT MATART-HIGH IS INITIAL.
    SELECT SINGLE * FROM T023 WHERE MATKL IN MATKLA.
    IF NOT SY-SUBRC IS INITIAL.
      MESSAGE E883 WITH MATKLA-LOW.
    ENDIF.
  ENDIF.

ENDFORM.                               "check_entry


************************************************************************
* Main data selection routine
************************************************************************
FORM. DATA_SELECTION.
* Materials to be processed
  TYPES: BEGIN OF TY_MAT,
           MATNR LIKE MARA-MATNR,
           WERKS LIKE MARC-WERKS,
           XCHAR LIKE MARC-XCHAR,
           MTART LIKE MARA-MTART,
           MATKL LIKE MARA-MATKL,
           MEINS LIKE MARA-MEINS,
           AUSME LIKE MARC-AUSME,
           TRAME LIKE MARC-TRAME,
           UMLMC LIKE MARC-UMLMC,
           LVORM_MARA        LIKE  MARA-LVORM,
           LVORM_MARC        LIKE  MARC-LVORM,
         END OF TY_MAT.

  DATA: T_MAT     TYPE TY_MAT OCCURS 0 WITH HEADER LINE,
        T_BATCH   TYPE TY_MAT OCCURS 0 WITH HEADER LINE,
        T_NOBATCH TYPE TY_MAT OCCURS 0 WITH HEADER LINE.

* buffer for reading working tables
  DATA : L_S_MAT             TYPE  TY_MAT,
         L_F_MATNR           LIKE  MAKT-MATNR.

  RANGES: R_SOBKZ FOR MKOL-SOBKZ.

  DATA: L_CNT_MATNR_I_EQ     TYPE I.                        "n759412
  DATA: L_CNT_MATNR_TOTAL    TYPE I.                        "n759412

************************************************************************
* Read material master data (MARA and MARC)
************************************************************************
  REFRESH COLLECTOR.

  CLEAR : L_CNT_MATNR_TOTAL, L_CNT_MATNR_I_EQ.

  LOOP AT MATNR.
    ADD  1             TO  L_CNT_MATNR_TOTAL.

    IF  NOT MATNR-LOW     IS INITIAL  AND
            MATNR-SIGN    =  'I'      AND
            MATNR-OPTION  =  'EQ'     AND
            MATNR-HIGH    IS INITIAL.
*     the table contains single a material number
      ADD  1           TO  L_CNT_MATNR_I_EQ.
    ELSE.
      EXIT.
    ENDIF.
  ENDLOOP.
* process SELECT command depending on the
* required material selection
  IF  L_CNT_MATNR_TOTAL  > 0  AND
      L_CNT_MATNR_TOTAL  = L_CNT_MATNR_I_EQ.
    SELECT MARA~MATNR WERKS XCHAR MTART MATKL MEINS AUSME TRAME UMLMC
         MARA~LVORM AS LVORM_MARA
         MARC~LVORM AS LVORM_MARC
         INTO CORRESPONDING FIELDS OF TABLE T_MAT
         FROM MARA INNER JOIN MARC
         ON MARA~MATNR = MARC~MATNR
         FOR ALL ENTRIES IN MATNR
         WHERE MARA~MATNR = MATNR-LOW
           AND WERKS IN WERKS
           AND MTART IN MATART
           AND MATKL IN MATKLA
           AND EKGRP IN EKGRUP.
  ELSE.
* END INSERT n_759412
    SELECT MARA~MATNR WERKS XCHAR MTART MATKL MEINS AUSME TRAME UMLMC
         MARA~LVORM AS LVORM_MARA
         MARC~LVORM AS LVORM_MARC
         INTO CORRESPONDING FIELDS OF TABLE T_MAT
         FROM MARA INNER JOIN MARC
         ON MARA~MATNR = MARC~MATNR
         WHERE MARA~MATNR IN MATNR
           AND WERKS IN WERKS
           AND MTART IN MATART
           AND MATKL IN MATKLA
           AND EKGRP IN EKGRUP.
  ENDIF.                                                    "n759412
************************************************************************
* Get "normal" stocks.
* If no detailed batch display is required,
* all data come from MARD. Otherwise, materials with batch
* management are extracted from MCHB, the rest from MARD.
* Dum-dibe-dum-dibe-dum. Dum.
************************************************************************
  REFRESH: T_BATCH, T_NOBATCH.
* Split the worklist into the parts for each table...
  IF XMCHB IS INITIAL.
    T_NOBATCH[] = T_MAT[].
  ELSE.
    LOOP AT T_MAT.
      IF T_MAT-XCHAR IS INITIAL.
        APPEND T_MAT TO T_NOBATCH.
      ELSE.
        APPEND T_MAT TO T_BATCH.
      ENDIF.
    ENDLOOP.
  ENDIF.
* Access MARD
* I you think that instead of SELECT-APPEND we could have used
* an array fetch, please wait for the table names to become different
* from the internal fields. B.T.W.: The DB-interface also buffers.
  CLEAR COLLECTOR.
  READ TABLE T_NOBATCH INDEX 1 TRANSPORTING NO FIELDS.
  IF SY-SUBRC = 0.
    SELECT MATNR WERKS LGORT
           LABST UMLME INSME EINME SPEME RETME LVORM
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-LGORT,
                 COLLECTOR-LABST, COLLECTOR-UMLME, COLLECTOR-INSME,
                 COLLECTOR-EINME, COLLECTOR-SPEME, COLLECTOR-RETME,
                 COLLECTOR-LVORM)
           FROM MARD
           FOR ALL ENTRIES IN T_NOBATCH
           WHERE MATNR = T_NOBATCH-MATNR
             AND WERKS = T_NOBATCH-WERKS
             AND LGORT IN LGORT.

*     save the MARD Key and deletion indicator for later
*     in table G_T_MARD_LV for use with special stocks
      IF NOT PA_SOND         IS INITIAL  AND
         NOT COLLECTOR-LVORM IS INITIAL.
        MOVE-CORRESPONDING  COLLECTOR
                             TO  G_S_MARD_LV.
        INSERT  G_S_MARD_LV  INTO  TABLE  G_T_MARD_LV.
      ENDIF.

      PERFORM                F2000_COLLECT_COLLECTOR.
    ENDSELECT.
  ENDIF.

* Access MCHB
  CLEAR COLLECTOR.
  READ TABLE T_BATCH INDEX 1 TRANSPORTING NO FIELDS.
  IF SY-SUBRC = 0.
    SELECT MATNR WERKS LGORT CHARG
           CLABS CUMLM CINSM CEINM CSPEM CRETM LVORM
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-LGORT,
                 COLLECTOR-CHARG,
                 COLLECTOR-LABST, COLLECTOR-UMLME, COLLECTOR-INSME,
                 COLLECTOR-EINME, COLLECTOR-SPEME, COLLECTOR-RETME,
                 COLLECTOR-LVORM)
           FROM MCHB
           FOR ALL ENTRIES IN T_BATCH
           WHERE MATNR = T_BATCH-MATNR
             AND WERKS = T_BATCH-WERKS
             AND LGORT IN LGORT
             AND CHARG IN CHARG.

      PERFORM                F2000_COLLECT_COLLECTOR.
    ENDSELECT.
  ENDIF.

************************************************************************
* Transfer stocks from MARC (TRAME and UMLMC)
************************************************************************
  CLEAR COLLECTOR.

  LOOP AT T_MAT WHERE UMLMC <> 0 OR TRAME <> 0.
*     there are no lines with stock = zero
*     take the stocks from plant level only when the user   "n577268
*     does not restrict the storage location;               "n577268
    CHECK : G_FLAG_SUPPRESS_INIT_LGORT IS INITIAL.          "n577268

    IF NEGATIV = 'X'.
*       ignore entry if all stocks are zero or greater
      IF  T_MAT-TRAME >= 0 AND
          T_MAT-UMLMC >= 0.
        CONTINUE.          "take the next entry
      ENDIF.
    ENDIF.

    COLLECTOR-MATNR = T_MAT-MATNR.
    COLLECTOR-WERKS = T_MAT-WERKS.
    COLLECTOR-UMLME = T_MAT-TRAME + T_MAT-UMLMC.
    COLLECTOR-LVORM = T_MAT-LVORM_MARC.
    APPEND COLLECTOR.
  ENDLOOP.

************************************************************************
* Consignment from vendor (MKOL)
* Read only if requested by one of the
* flags on the selection screen. Absolutely inconsistent, but
* due to compatibility...
* MKOL has a flag for deletion
************************************************************************

  IF  NOT PA_SOND IS INITIAL  AND
      NOT T_MAT[] IS INITIAL.
    IF  'K' IN SO_SOBKZ  OR
        'M' IN SO_SOBKZ.
      CLEAR                  COLLECTOR.

      SELECT MATNR WERKS LGORT CHARG SOBKZ LIFNR
             SLABS SINSM SEINM SSPEM LVORM
             INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-LGORT,
                   COLLECTOR-CHARG, COLLECTOR-SOBKZ, COLLECTOR-LIFNR,
                   COLLECTOR-LABST, COLLECTOR-INSME, COLLECTOR-EINME,
                   COLLECTOR-SPEME, COLLECTOR-LVORM)
             FROM MKOL
             FOR ALL ENTRIES IN T_MAT
             WHERE MATNR = T_MAT-MATNR
               AND WERKS = T_MAT-WERKS
               AND LGORT IN LGORT
               AND CHARG IN CHARG
               AND SOBKZ IN SO_SOBKZ.

        PERFORM              F2000_COLLECT_COLLECTOR.
      ENDSELECT.
    ENDIF.
  ENDIF.

************************************************************************
* Special stocks at customer side (MSKU)
* MSKU has no flag for deletion
************************************************************************

  IF  NOT  PA_SOND IS INITIAL  AND
      NOT  T_MAT[] IS INITIAL.
    IF  'V' IN SO_SOBKZ  OR
        'W' IN SO_SOBKZ.
      CLEAR COLLECTOR.

      SELECT MATNR WERKS CHARG SOBKZ KUNNR
           KULAB KUINS KUEIN
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-CHARG,
                 COLLECTOR-SOBKZ, COLLECTOR-KUNNR,
                 COLLECTOR-LABST, COLLECTOR-INSME, COLLECTOR-EINME)
           FROM MSKU
           FOR ALL ENTRIES IN T_MAT
           WHERE MATNR = T_MAT-MATNR
             AND WERKS = T_MAT-WERKS
             AND CHARG IN CHARG
             AND SOBKZ  IN  SO_SOBKZ.

        PERFORM              F2000_COLLECT_COLLECTOR.
      ENDSELECT.
    ENDIF.
  ENDIF.

************************************************************************
* Special stocks at vendor provision (MSLB)
* MSLB has no flag for deletion
************************************************************************

  IF  NOT  PA_SOND IS INITIAL  AND
      NOT  T_MAT[] IS INITIAL  AND
           'O'     IN SO_SOBKZ.
    CLEAR COLLECTOR.

    SELECT MATNR WERKS CHARG SOBKZ LIFNR
           LBLAB LBINS LBEIN
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-CHARG,
                 COLLECTOR-SOBKZ, COLLECTOR-LIFNR,
                 COLLECTOR-LABST, COLLECTOR-INSME,
                 COLLECTOR-EINME)
           FROM MSLB
           FOR ALL ENTRIES IN T_MAT
           WHERE MATNR = T_MAT-MATNR
             AND WERKS = T_MAT-WERKS
             AND CHARG IN CHARG
             AND SOBKZ  IN  SO_SOBKZ.

      PERFORM                F2000_COLLECT_COLLECTOR.
    ENDSELECT.
  ENDIF.

************************************************************************
* Customer order stock (MSKA) and sum segment (MSSA) for valuation.
* Sum on the database and FOR ALL ENTRIES is not allowed from
* release 4.5 onwards, so the summation has to be done
* on the application server (here!).
* MSKA has no flag for deletion
************************************************************************

  IF  NOT  PA_SOND IS INITIAL  AND
      NOT  T_MAT[] IS INITIAL  AND
           'E'     IN SO_SOBKZ.
    CLEAR COLLECTOR.

    SELECT MSKA~MATNR MSKA~WERKS LGORT CHARG MSKA~SOBKZ
           MSKA~VBELN MSKA~POSNR
           KALAB KAINS KASPE KAEIN KZBWS
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-LGORT,
                 COLLECTOR-CHARG, COLLECTOR-SOBKZ,
                 COLLECTOR-VBELN, COLLECTOR-POSNR,
                 COLLECTOR-LABST, COLLECTOR-INSME, COLLECTOR-SPEME,
                 COLLECTOR-EINME, COLLECTOR-KZBWS)
           FROM MSKA INNER JOIN MSSA
           ON   MSKA~MATNR = MSSA~MATNR
            AND MSKA~WERKS = MSSA~WERKS
            AND MSKA~SOBKZ = MSSA~SOBKZ
            AND MSKA~VBELN = MSSA~VBELN
            AND MSKA~POSNR = MSSA~POSNR
           FOR ALL ENTRIES IN T_MAT
           WHERE MSKA~MATNR = T_MAT-MATNR
             AND MSKA~WERKS = T_MAT-WERKS
             AND MSKA~LGORT IN LGORT
             AND MSKA~CHARG IN CHARG.

      PERFORM                F2000_COLLECT_COLLECTOR.
    ENDSELECT.

*   Transfer stocks for customer order (SATRA in MSSA)
    CLEAR COLLECTOR.
    SELECT MATNR WERKS SOBKZ VBELN POSNR KZBWS SATRA
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-SOBKZ,
                 COLLECTOR-VBELN, COLLECTOR-POSNR,
                 COLLECTOR-KZBWS, COLLECTOR-UMLME)
           FROM MSSA
           FOR ALL ENTRIES IN T_MAT
           WHERE MATNR = T_MAT-MATNR
             AND WERKS = T_MAT-WERKS
             AND SOBKZ  IN  SO_SOBKZ
             AND SATRA <> 0.

      PERFORM                F2000_COLLECT_COLLECTOR.
    ENDSELECT.
  ENDIF.

************************************************************************
* The same game for project stocks (MSPR/MSSQ).
* MSPR has no flag for deletion
************************************************************************

  IF  NOT  PA_SOND IS INITIAL  AND
      NOT  T_MAT[] IS INITIAL  AND
           'Q'     IN SO_SOBKZ.
    CLEAR COLLECTOR.

    SELECT MSPR~MATNR MSPR~WERKS LGORT CHARG MSPR~SOBKZ MSPR~PSPNR
           PRLAB PRINS PRSPE PREIN KZBWS
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-LGORT,
                 COLLECTOR-CHARG, COLLECTOR-SOBKZ,
                 COLLECTOR-PSPNR,
                 COLLECTOR-LABST, COLLECTOR-INSME, COLLECTOR-SPEME,
                 COLLECTOR-EINME, COLLECTOR-KZBWS)
           FROM MSPR INNER JOIN MSSQ
           ON   MSPR~MATNR = MSSQ~MATNR
            AND MSPR~WERKS = MSSQ~WERKS
            AND MSPR~SOBKZ = MSSQ~SOBKZ
            AND MSPR~PSPNR = MSSQ~PSPNR
           FOR ALL ENTRIES IN T_MAT
           WHERE MSPR~MATNR = T_MAT-MATNR
             AND MSPR~WERKS = T_MAT-WERKS
             AND MSPR~LGORT IN LGORT
             AND MSPR~CHARG IN CHARG.

      PERFORM                F2000_COLLECT_COLLECTOR.
    ENDSELECT.

*   Transfer stocks for projects (SQTRA in MSSQ)
    CLEAR COLLECTOR.
    SELECT MATNR WERKS SOBKZ PSPNR KZBWS SQTRA
           INTO (COLLECTOR-MATNR, COLLECTOR-WERKS, COLLECTOR-SOBKZ,
                 COLLECTOR-PSPNR,
                 COLLECTOR-KZBWS, COLLECTOR-UMLME)
           FROM MSSQ
           FOR ALL ENTRIES IN T_MAT
           WHERE MATNR = T_MAT-MATNR
             AND WERKS = T_MAT-WERKS
             AND SOBKZ  IN  SO_SOBKZ
             AND SQTRA <> 0.

      PERFORM                F2000_COLLECT_COLLECTOR.
    ENDSELECT.
  ENDIF.

************************************************************************
* Extract key-data for other tables.
************************************************************************
  DATA: BEGIN OF T_MAKTKEY OCCURS 0,
          MATNR LIKE MAKT-MATNR,
        END OF T_MAKTKEY,

* working area for the material description
        BEGIN OF L_S_MAKT,
          MATNR LIKE MAKT-MATNR,
          MAKTX LIKE MAKT-MAKTX,
        END OF L_S_MAKT,

        BEGIN OF T_MAKT OCCURS 0,
          MATNR LIKE MAKT-MATNR,
          MAKTX LIKE MAKT-MAKTX,
        END OF T_MAKT,

        BEGIN OF T_MCHAKEY OCCURS 0,
          MATNR LIKE MCHA-MATNR,
          WERKS LIKE MCHA-WERKS,
          CHARG LIKE MCHA-CHARG,
        END OF T_MCHAKEY,
        BEGIN OF T_MCHA OCCURS 0,
          MATNR LIKE MCHA-MATNR,
          WERKS LIKE MCHA-WERKS,
          CHARG LIKE MCHA-CHARG,
          BWTAR LIKE MCHA-BWTAR,
        END OF T_MCHA.

  REFRESH: T_MAKTKEY, T_MCHAKEY, BESTAND.
* remove all items in bestand with wrong batch number. If we would
* not remove this, report will e.g. show materials which has
* only MARD entries, too.
  LOOP AT COLLECTOR WHERE CHARG IN CHARG.               "note 311770
    MOVE-CORRESPONDING COLLECTOR TO BESTAND.

*   fill the key of the special stocks into the field
*   assigment
    CASE    COLLECTOR-SOBKZ.
      WHEN  'E'.
        MOVE  : 'X'               TO  G_FLAG_SOBKZ-VBELN.
        WRITE : COLLECTOR-VBELN   TO  BESTAND-SSNUM.
        MOVE  : '/'               TO  BESTAND-SSNUM+10(01).
        WRITE : COLLECTOR-POSNR   TO  BESTAND-SSNUM+12(08)
                                  NO-ZERO.
        CONDENSE                  BESTAND-SSNUM.

      WHEN  'K'.
        MOVE  : 'X'               TO  G_FLAG_SOBKZ-LIFNR.
        WRITE : COLLECTOR-LIFNR   TO  BESTAND-SSNUM.

      WHEN  'M'.
        MOVE  : 'X'               TO  G_FLAG_SOBKZ-LIFNR.
        WRITE : COLLECTOR-LIFNR   TO  BESTAND-SSNUM.

      WHEN  'O'.
        MOVE  : 'X'               TO  G_FLAG_SOBKZ-LIFNR.
        WRITE : COLLECTOR-LIFNR   TO  BESTAND-SSNUM.

      WHEN  'Q'.
        MOVE  : 'X'               TO  G_FLAG_SOBKZ-PSPNR.
        WRITE : COLLECTOR-PSPNR   TO  BESTAND-SSNUM.

      WHEN  'V'.
        MOVE  : 'X'               TO  G_FLAG_SOBKZ-KUNNR.
        WRITE : COLLECTOR-KUNNR   TO  BESTAND-SSNUM.

      WHEN  'W'.
        MOVE  : 'X'               TO  G_FLAG_SOBKZ-KUNNR.
        WRITE : COLLECTOR-KUNNR   TO  BESTAND-SSNUM.

      WHEN  OTHERS.
        CLEAR                     BESTAND-SSNUM.
    ENDCASE.

    APPEND BESTAND.

    T_MAKTKEY-MATNR = BESTAND-MATNR.
    COLLECT T_MAKTKEY.

    IF BESTAND-CHARG <> SPACE.
      T_MCHAKEY-MATNR = BESTAND-MATNR.
      T_MCHAKEY-WERKS = BESTAND-WERKS.
      T_MCHAKEY-CHARG = BESTAND-CHARG.
      COLLECT T_MCHAKEY.
    ENDIF.
  ENDLOOP.

  FREE                       COLLECTOR.

************************************************************************
* Read additional tables
************************************************************************
  READ TABLE T_MAKTKEY INDEX 1 TRANSPORTING NO FIELDS.
  IF SY-SUBRC = 0.
    SELECT MATNR MAKTX INTO CORRESPONDING FIELDS OF TABLE T_MAKT
           FROM MAKT
           FOR ALL ENTRIES IN T_MAKTKEY
           WHERE MATNR = T_MAKTKEY-MATNR
             AND SPRAS = SY-LANGU.
    SORT T_MAKT BY MATNR.
  ENDIF.

* Read batch data only if values are requested
  READ TABLE T_MCHAKEY INDEX 1 TRANSPORTING NO FIELDS.
  IF SY-SUBRC = 0 AND NOVALUES IS INITIAL.
    SELECT MATNR WERKS CHARG BWTAR
           INTO CORRESPONDING FIELDS OF TABLE T_MCHA
           FROM MCHA
           FOR ALL ENTRIES IN T_MCHAKEY
           WHERE MATNR = T_MCHAKEY-MATNR
             AND WERKS = T_MCHAKEY-WERKS
             AND CHARG = T_MCHAKEY-CHARG.
    SORT T_MCHA BY MATNR WERKS CHARG.
  ENDIF.

************************************************************************
* Data definitions for the valuation extraction
************************************************************************
  DATA: BEGIN OF T_MBEWKEY OCCURS 0,
          MATNR LIKE MBEW-MATNR,
          BWKEY LIKE MBEW-BWKEY,
          BWTAR LIKE MBEW-BWTAR,
        END OF T_MBEWKEY,

*       workin table for the material stock valuation
        BEGIN OF T_MBEW OCCURS 0,
          MATNR LIKE MBEW-MATNR,
          BWKEY LIKE MBEW-BWKEY,
          BWTAR LIKE MBEW-BWTAR,
*         consider the valuation of the special stocks E, Q "n531604
          SOBKZ              LIKE  EBEW-SOBKZ,              "n531604
          VBELN              LIKE  EBEW-VBELN,              "n531604
          POSNR              LIKE  EBEW-POSNR,              "n531604
          PSPNR              LIKE  QBEW-PSPNR,              "n531604

          LBKUM(12)  TYPE P DECIMALS 3,                     "407810
          SALK3(12)  TYPE P DECIMALS 2,                     "388735
          VPRSV LIKE MBEW-VPRSV,                            "353428
          VERPR LIKE MBEW-VERPR,                            "353428
          STPRS LIKE MBEW-STPRS,                            "353428
          PEINH LIKE MBEW-PEINH,                            "353428
        END OF T_MBEW.

  DATA: T_EBEWKEY LIKE T_MBEWKEY OCCURS 0 WITH HEADER LINE.
  DATA: T_QBEWKEY LIKE T_MBEWKEY OCCURS 0 WITH HEADER LINE.
  DATA: T_EBEW    LIKE T_MBEW    OCCURS 0 WITH HEADER LINE.
  DATA: T_QBEW    LIKE T_MBEW    OCCURS 0 WITH HEADER LINE.
  DATA: V_MEINS LIKE ZLJGB-MEINS. "GMT工厂商品单位
  DATA: V_MENGE TYPE EKPO-MENGE, "SAP单位转换为GMT工厂商品单位数量!
        V_NTGEW LIKE ZLJGB-NTGEW,
        V_RATE LIKE ZLJGB-RATE.

  DATA: BEGIN OF T_T134MKEY OCCURS 0,
          BWKEY LIKE T134M-BWKEY,
          MTART LIKE T134M-MTART,
        END OF T_T134MKEY,
        BEGIN OF T_T134M OCCURS 0,
          BWKEY LIKE T134M-BWKEY,
          MTART LIKE T134M-MTART,
          WERTU LIKE T134M-WERTU,
        END OF T_T134M.

************************************************************************
* Fill in additional data (first round) and extract the data
* for the access to the valuation tables.
************************************************************************
  SORT T_MAT BY MATNR WERKS.
  SORT G_T_ORGAN             BY WERKS.
  CLEAR : G_S_T001L,         G_S_ORGAN,   BESTAND.

  LOOP AT BESTAND.
*   get the information per plant and storage location
*   with buffer
    IF  G_FLAG_T001L = 'X'.
      IF  BESTAND-WERKS = G_S_T001L-WERKS  AND
          BESTAND-LGORT = G_S_T001L-LGORT.
      ELSE.
*       read with plant and storage location
        READ TABLE G_T_T001L   INTO  G_S_T001L
          WITH TABLE KEY WERKS = BESTAND-WERKS
                         LGORT = BESTAND-LGORT.

        MOVE : BESTAND-WERKS TO G_S_T001L-WERKS,
               BESTAND-LGORT TO G_S_T001L-LGORT.

        IF SY-SUBRC <> 0.
          CLEAR              G_S_T001L-LGOBE.
        ENDIF.
      ENDIF.
    ENDIF.

*   take the storage bin from the buffer
    MOVE : G_S_T001L-LGOBE   TO  BESTAND-LGOBE.


*   get the information per plant with buffer
    IF  BESTAND-WERKS  NE  G_S_ORGAN-WERKS.
      READ TABLE G_T_ORGAN   INTO  G_S_ORGAN
          WITH KEY WERKS = BESTAND-WERKS
                             BINARY SEARCH.

      IF SY-SUBRC <> 0.
*       sorry nothing found
        CLEAR                G_S_ORGAN.
        MOVE : BESTAND-WERKS TO  G_S_ORGAN-WERKS.
      ENDIF.
    ENDIF.

*   take the following fields from the buffer
    MOVE : G_S_ORGAN-NAME1   TO  BESTAND-NAME1,
           G_S_ORGAN-WAERS   TO  BESTAND-WAERS,
           G_S_ORGAN-BWKEY   TO  BESTAND-BWKEY.


*   get the information from the material master MARC
*   with buffer
    IF  BESTAND-MATNR = L_S_MAT-MATNR  AND
        BESTAND-WERKS = L_S_MAT-WERKS.
*     results are in the buffer
    ELSE.
      CLEAR                  L_S_MAT.
      MOVE : BESTAND-MATNR   TO  L_S_MAT-MATNR,
             BESTAND-WERKS   TO  L_S_MAT-WERKS.

      READ TABLE T_MAT       INTO  L_S_MAT
         WITH KEY MATNR = BESTAND-MATNR
                  WERKS = BESTAND-WERKS
                             BINARY SEARCH.

      IF  SY-SUBRC <> 0.
*       sorry nothing found
        CLEAR                L_S_MAT.
        MOVE : BESTAND-MATNR TO  L_S_MAT-MATNR,
               BESTAND-WERKS TO  L_S_MAT-WERKS.
      ENDIF.
    ENDIF.

*   take the results the buffer
    MOVE : L_S_MAT-MTART     TO  BESTAND-MTART,
           L_S_MAT-MATKL     TO  BESTAND-MATKL,
           L_S_MAT-MEINS     TO  BESTAND-MEINS,
           L_S_MAT-AUSME     TO  BESTAND-AUSME."add by rzwei


*   if this entry has no deletion flag, take the
*   deletion flag from a higher level like MARA, MARC,
*   or MARDA
    IF  BESTAND-LVORM IS INITIAL.
      IF      NOT  L_S_MAT-LVORM_MARC IS INITIAL.
        MOVE  L_S_MAT-LVORM_MARC
                             TO  BESTAND-LVORM.
      ELSEIF  NOT  L_S_MAT-LVORM_MARA IS INITIAL.
        MOVE  L_S_MAT-LVORM_MARA
                             TO  BESTAND-LVORM.

      ELSEIF  NOT G_T_MARD_LV[] IS INITIAL  AND
              NOT BESTAND-LGORT IS INITIAL  AND
              NOT BESTAND-SOBKZ IS INITIAL.
*       look for deletion flag in working table
*       g_t_mard_lv for a line with special stock
        IF  BESTAND-MATNR = G_S_MARD_LV-MATNR  AND
            BESTAND-WERKS = G_S_MARD_LV-WERKS  AND
            BESTAND-LGORT = G_S_MARD_LV-LGORT.
        ELSE.
*         read table only after the key has changed
          READ TABLE G_T_MARD_LV  INTO  G_S_MARD_LV
          WITH TABLE KEY MATNR = BESTAND-MATNR
                         WERKS = BESTAND-WERKS
                         LGORT = BESTAND-LGORT.

          IF SY-SUBRC <> 0.
*           fill the buffer in case the entry does not exist
            MOVE : BESTAND-MATNR  TO  G_S_MARD_LV-MATNR,
                   BESTAND-WERKS  TO  G_S_MARD_LV-WERKS,
                   BESTAND-LGORT  TO  G_S_MARD_LV-LGORT.
            CLEAR                 G_S_MARD_LV-LVORM.
          ENDIF.

*         take the result from the buffer
          MOVE  G_S_MARD_LV-LVORM   TO  BESTAND-LVORM.
        ENDIF.
      ENDIF.
    ENDIF.


*   read the material short description after the material
*   number has changed
    IF  BESTAND-MATNR NE L_S_MAKT-MATNR.
      READ TABLE T_MAKT      INTO  L_S_MAKT
                   WITH KEY MATNR = BESTAND-MATNR
                             BINARY SEARCH.

      IF SY-SUBRC <> 0.
*       sorry nothing found
        CLEAR                L_S_MAKT-MAKTX.
        MOVE  BESTAND-MATNR  TO  L_S_MAKT-MATNR.
      ENDIF.
    ENDIF.

*   take the results the buffer
    MOVE : L_S_MAKT-MAKTX    TO  BESTAND-MAKTX.

    IF BESTAND-VBELN IS NOT INITIAL.
      SELECT SINGLE BSTKD
             INTO BESTAND-BSTKD
             FROM VBKD
             WHERE VBELN = BESTAND-VBELN AND POSNR = BESTAND-POSNR.

      IF SY-SUBRC NE 0.
        SELECT SINGLE BSTKD
               INTO BESTAND-BSTKD
               FROM VBKD
               WHERE VBELN = BESTAND-VBELN AND POSNR = '000000'.
      ENDIF.

    ENDIF.

    IF BESTAND-CHARG <> SPACE AND NOVALUES IS INITIAL.
      READ TABLE T_MCHA WITH KEY MATNR = BESTAND-MATNR
                                 WERKS = BESTAND-WERKS
                                 CHARG = BESTAND-CHARG
                                 BINARY SEARCH.
      IF SY-SUBRC = 0.
        BESTAND-BWTAR = T_MCHA-BWTAR.
      ENDIF.
    ENDIF.

    SELECT SINGLE UMREZ UMREN INTO (TEMP-UMREZ,TEMP-UMREN)
           FROM MARM
           WHERE MATNR = BESTAND-MATNR AND MEINH = BESTAND-AUSME.

    BESTAND-LABOX = BESTAND-LABST * TEMP-UMREN / TEMP-UMREZ.  "add field by rzwei

* Valuation keys
    IF NOVALUES IS INITIAL.
      IF  BESTAND-SOBKZ = ' ' OR BESTAND-SOBKZ = 'O' OR
          BESTAND-SOBKZ = 'W' OR BESTAND-SOBKZ = 'V' OR
          BESTAND-KZBWS = 'A'.
        T_MBEWKEY-MATNR = BESTAND-MATNR.
        T_MBEWKEY-BWKEY = BESTAND-BWKEY.
        T_MBEWKEY-BWTAR = BESTAND-BWTAR.
        COLLECT T_MBEWKEY.
      ELSEIF BESTAND-SOBKZ = 'E' AND BESTAND-KZBWS = 'M'.
        T_EBEWKEY-MATNR = BESTAND-MATNR.
        T_EBEWKEY-BWKEY = BESTAND-BWKEY.
        T_EBEWKEY-BWTAR = BESTAND-BWTAR.
        COLLECT T_EBEWKEY.
      ELSEIF BESTAND-SOBKZ = 'Q' AND BESTAND-KZBWS = 'M'.
        T_QBEWKEY-MATNR = BESTAND-MATNR.
        T_QBEWKEY-BWKEY = BESTAND-BWKEY.
        T_QBEWKEY-BWTAR = BESTAND-BWTAR.
        COLLECT T_QBEWKEY.
      ENDIF.
      T_T134MKEY-BWKEY = BESTAND-BWKEY.
      T_T134MKEY-MTART = BESTAND-MTART.
      COLLECT T_T134MKEY.
    ENDIF.                             " novalues is initial
    MODIFY BESTAND.
  ENDLOOP.

* release the space of global working tables after use
  FREE : G_T_MARD_LV, G_T_T001L, G_T_ORGAN.

************************************************************************
* Read the valuation tables
************************************************************************
  IF NOVALUES IS INITIAL.
    READ TABLE T_MBEWKEY INDEX 1 TRANSPORTING NO FIELDS.
    IF SY-SUBRC = 0.
      SELECT MATNR BWKEY BWTAR LBKUM SALK3
             VPRSV VERPR STPRS PEINH                        "353428
             INTO CORRESPONDING FIELDS OF TABLE T_MBEW
             FROM MBEW
             FOR ALL ENTRIES IN T_MBEWKEY
             WHERE MATNR = T_MBEWKEY-MATNR
               AND BWKEY = T_MBEWKEY-BWKEY
               AND BWTAR = T_MBEWKEY-BWTAR.
      SORT T_MBEW BY MATNR BWKEY BWTAR.
    ENDIF.

    READ TABLE T_EBEWKEY INDEX 1 TRANSPORTING NO FIELDS.
    IF SY-SUBRC = 0.
*     "Unfortunately", EBEW and QBEW do not have sum segments over
*     the valuation types. Therefore, without batch data, another
*     SELECT-statement is needed.
      IF XMCHB = 'X'.
        SELECT MATNR BWKEY BWTAR SOBKZ VBELN POSNR LBKUM SALK3
               VPRSV VERPR STPRS PEINH
               INTO (T_EBEW-MATNR, T_EBEW-BWKEY, T_EBEW-BWTAR,
                     T_EBEW-SOBKZ,  T_EBEW-VBELN, T_EBEW-POSNR,
                     T_EBEW-LBKUM, T_EBEW-SALK3,
                     T_EBEW-VPRSV, T_EBEW-VERPR,
                     T_EBEW-STPRS, T_EBEW-PEINH)
               FROM EBEW
               FOR ALL ENTRIES IN T_EBEWKEY
               WHERE MATNR = T_EBEWKEY-MATNR
                 AND BWKEY = T_EBEWKEY-BWKEY
                 AND BWTAR = T_EBEWKEY-BWTAR.
          COLLECT T_EBEW.
        ENDSELECT.
      ELSE.
        SELECT MATNR BWKEY BWTAR SOBKZ VBELN POSNR LBKUM SALK3
               VPRSV VERPR STPRS PEINH
               INTO (T_EBEW-MATNR, T_EBEW-BWKEY,  T_EBEW-BWTAR,
                     T_EBEW-SOBKZ,  T_EBEW-VBELN, T_EBEW-POSNR,
                     T_EBEW-LBKUM, T_EBEW-SALK3,
                     T_EBEW-VPRSV, T_EBEW-VERPR,
                     T_EBEW-STPRS, T_EBEW-PEINH)
               FROM EBEW
               FOR ALL ENTRIES IN T_EBEWKEY
               WHERE MATNR = T_EBEWKEY-MATNR
                 AND BWKEY = T_EBEWKEY-BWKEY.
          COLLECT T_EBEW.
        ENDSELECT.
      ENDIF.

      SORT T_EBEW BY MATNR BWKEY BWTAR SOBKZ VBELN POSNR.
    ENDIF.

    READ TABLE T_QBEWKEY INDEX 1 TRANSPORTING NO FIELDS.
    IF SY-SUBRC = 0.
      IF XMCHB = 'X'.
        SELECT MATNR BWKEY BWTAR SOBKZ PSPNR LBKUM SALK3
               VPRSV VERPR STPRS PEINH
               INTO (T_QBEW-MATNR, T_QBEW-BWKEY, T_QBEW-BWTAR,
                     T_QBEW-SOBKZ, T_QBEW-PSPNR,
                     T_QBEW-LBKUM, T_QBEW-SALK3,
                     T_QBEW-VPRSV, T_QBEW-VERPR,
                     T_QBEW-STPRS, T_QBEW-PEINH)
               FROM QBEW
               FOR ALL ENTRIES IN T_QBEWKEY
               WHERE MATNR = T_QBEWKEY-MATNR
                 AND BWKEY = T_QBEWKEY-BWKEY
                AND BWTAR = T_QBEWKEY-BWTAR.
          COLLECT T_QBEW.
        ENDSELECT.
      ELSE.
        SELECT MATNR BWKEY BWTAR SOBKZ PSPNR LBKUM SALK3
               VPRSV VERPR STPRS PEINH
               INTO (T_QBEW-MATNR, T_QBEW-BWKEY, T_QBEW-BWTAR,
                     T_QBEW-SOBKZ, T_QBEW-PSPNR,
                     T_QBEW-LBKUM, T_QBEW-SALK3,
                     T_QBEW-VPRSV, T_QBEW-VERPR,
                     T_QBEW-STPRS, T_QBEW-PEINH)
               FROM QBEW
               FOR ALL ENTRIES IN T_QBEWKEY
               WHERE MATNR = T_QBEWKEY-MATNR
                 AND BWKEY = T_QBEWKEY-BWKEY.
          COLLECT T_QBEW.
        ENDSELECT.
      ENDIF.

      SORT T_QBEW BY MATNR BWKEY BWTAR SOBKZ PSPNR.
    ENDIF.

    READ TABLE T_T134MKEY INDEX 1 TRANSPORTING NO FIELDS.
    IF SY-SUBRC = 0.
      SELECT BWKEY MTART WERTU
             INTO CORRESPONDING FIELDS OF TABLE T_T134M
             FROM T134M
             FOR ALL ENTRIES IN T_T134MKEY
             WHERE BWKEY = T_T134MKEY-BWKEY
               AND MTART = T_T134MKEY-MTART.
      SORT T_T134M BY BWKEY MTART.
    ENDIF.
************************************************************************
* Fill the valuation data
************************************************************************
    DATA: FACTOR TYPE F.
    CLEAR:BESTAND.
    LOOP AT BESTAND.

      CHECK BESTAND-WAERS <> SPACE.  "Do nothing for failed Auth-Checks
      READ TABLE T_T134M WITH KEY BWKEY = BESTAND-BWKEY
                                  MTART = BESTAND-MTART
                                  BINARY SEARCH.
      CHECK SY-SUBRC = 0 AND T_T134M-WERTU = 'X'.
      SY-SUBRC = 4.
      IF  BESTAND-SOBKZ = ' ' OR BESTAND-SOBKZ = 'O' OR
          BESTAND-SOBKZ = 'W' OR BESTAND-SOBKZ = 'V' OR
          BESTAND-KZBWS = 'A'.
        READ TABLE T_MBEW WITH KEY MATNR = BESTAND-MATNR
                                   BWKEY = BESTAND-BWKEY
                                   BWTAR = BESTAND-BWTAR
                                   BINARY SEARCH.

      ELSEIF BESTAND-SOBKZ = 'E' AND BESTAND-KZBWS = 'M'.
        READ TABLE T_EBEW WITH KEY MATNR = BESTAND-MATNR
                                   BWKEY = BESTAND-BWKEY
                                   BWTAR = BESTAND-BWTAR
                                   SOBKZ = BESTAND-SOBKZ
                                   VBELN = BESTAND-VBELN    "n531604
                                   POSNR = BESTAND-POSNR    "n531604
                                   BINARY SEARCH.
        MOVE-CORRESPONDING T_EBEW TO T_MBEW.

      ELSEIF BESTAND-SOBKZ = 'Q' AND BESTAND-KZBWS = 'M'.
        READ TABLE T_QBEW WITH KEY MATNR = BESTAND-MATNR
                                   BWKEY = BESTAND-BWKEY
                                   BWTAR = BESTAND-BWTAR
                                   SOBKZ = BESTAND-SOBKZ
                                   PSPNR = BESTAND-PSPNR
                                   BINARY SEARCH.
        MOVE-CORRESPONDING T_QBEW TO T_MBEW.
      ENDIF.

      IF SY-SUBRC = 0.
        IF T_MBEW-LBKUM = 0.
*         Cannot happen, but in R/3 this does not hold in all cases...
          IF T_MBEW-PEINH = 0.                              "353428
            T_MBEW-PEINH = 1.                               "353428
          ENDIF.                                            "353428
*         Calculation of value in case of LBKUM = 0 only possible
*         for MBEW. EBEW and QBEW are collected over all subitems
*         (VBELN...), so the data are not available.
          IF BESTAND-SOBKZ = 'E' OR BESTAND-SOBKZ = 'Q'.    "388735
            FACTOR = 0.                                     "388735
            CLEAR BESTAND-WAERS.                            "388735
          ELSE.                                             "388735
            CASE T_MBEW-VPRSV.
              WHEN 'V'. FACTOR = T_MBEW-VERPR / T_MBEW-PEINH.
              WHEN 'S'. FACTOR = T_MBEW-STPRS / T_MBEW-PEINH.
            ENDCASE.
          ENDIF.                                            "388735
        ELSE.
          FACTOR = T_MBEW-SALK3 / T_MBEW-LBKUM.
        ENDIF.

        BESTAND-WLABS = BESTAND-LABST * FACTOR.
        BESTAND-WINSM = BESTAND-INSME * FACTOR.
        BESTAND-WSPEM = BESTAND-SPEME * FACTOR.
        BESTAND-WEINM = BESTAND-EINME * FACTOR.
        BESTAND-WUMLM = BESTAND-UMLME * FACTOR.
        MODIFY BESTAND.
      ENDIF.
    ENDLOOP.
  ENDIF.                               "novalues is initial

  LOOP AT BESTAND.

    SELECT SINGLE BRGEW NTGEW GEWEI FROM MARA
      INTO (BESTAND-BRGEW,BESTAND-NTGEW,BESTAND-GEWEI)
      WHERE MATNR = BESTAND-MATNR.
    IF BESTAND-MTART = 'ZRAW' OR BESTAND-MTART = 'ZIMM'.
      CLEAR EORD.
      SELECT SINGLE MATNR WERKS LIFNR INTO
        (EORD-MATNR,EORD-WERKS,EORD-LIFNR)
        FROM EORD
        WHERE MATNR = BESTAND-MATNR
          AND WERKS = BESTAND-WERKS
          AND FLIFN = 'X'.
      IF SY-SUBRC NE 0.
        SELECT SINGLE MATNR WERKS LIFNR INTO
          (EORD-MATNR,EORD-WERKS,EORD-LIFNR)
          FROM EORD
          WHERE MATNR = BESTAND-MATNR
            AND WERKS = BESTAND-WERKS.
      ENDIF.
      SELECT SINGLE INCO1 INTO BESTAND-INCO1
        FROM EINE JOIN EINA ON EINA~INFNR = EINE~INFNR
        WHERE MATNR = EORD-MATNR
          AND WERKS = EORD-WERKS
          AND LIFNR = EORD-LIFNR.

    ELSE.
      SELECT SINGLE BKLAS INCO1 AUFNR
         INTO (BESTAND-BKLAS,BESTAND-INCO1,BESTAND-AUFNR)
         FROM ZM065
         WHERE CHARG = BESTAND-CHARG.
    ENDIF.

    SELECT SINGLE BKBEZ INTO BESTAND-BKBEZ
      FROM T025T
      WHERE BKLAS = BESTAND-BKLAS
        AND SPRAS = SY-LANGU.

    BESTAND-TOTAL = BESTAND-LABST + BESTAND-INSME + BESTAND-SPEME
                  + BESTAND-EINME + BESTAND-UMLME.

    IF BESTAND-GEWEI = 'G'.
      V_NTGEW = BESTAND-NTGEW / 1000.
    ELSEIF  BESTAND-GEWEI = 'MG'.
      V_NTGEW = BESTAND-NTGEW / 1000000.
    ENDIF.

    BESTAND-BRGEW = BESTAND-NTGEW * BESTAND-TOTAL.

    SELECT SINGLE MEINS NTGEW MEINS_GMT RATE SERIA CUSTN CUSTX MEINS_GMT1
           MEINS_ZH MEINS_GMT_ZH
      INTO (BESTAND-MEINS_GC,BESTAND-NTGEW_GMT,BESTAND-MEINS_GMT,V_RATE,
            BESTAND-SERIA,BESTAND-CUSTN,BESTAND-CUSTX,BESTAND-MEINS_GMT1,
            BESTAND-MEINS_ZH,BESTAND-MEINS_GMT_ZH)
      FROM ZLJGB
      WHERE MATNR = BESTAND-MATNR.

    IF SY-SUBRC = 0.

*    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
*      EXPORTING
*        INPUT                = BESTAND-NTGEW
*        ROUND_SIGN           = 'X'
*        UNIT_IN              = BESTAND-GEWEI
*        UNIT_OUT             = 'KG'
*      IMPORTING
*        OUTPUT               = V_NTGEW
*      EXCEPTIONS
*        CONVERSION_NOT_FOUND = 01
*        DIVISION_BY_ZERO     = 02
*        INPUT_INVALID        = 03
*        OUTPUT_INVALID       = 04
*        OVERFLOW             = 05
*        UNITS_MISSING        = 06
*        UNIT_IN_NOT_FOUND    = 07
*        UNIT_OUT_NOT_FOUND   = 08.
*    IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*    ENDIF.
*重量以KG单位进行比较,SAP重量仍然以物料主数据中重量,单位输出
      BESTAND-VARIA = BESTAND-NTGEW_GMT - V_NTGEW.
      CLEAR V_MEINS.
      V_MEINS = BESTAND-MEINS_GC.
      SELECT SINGLE MSEH3 INTO V_MEINS
        FROM ZT006A WHERE MSEHI = CONSUME-MEINS_GC.
      IF BESTAND-MEINS <> V_MEINS AND V_MEINS NE SPACE.
        CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
          EXPORTING
            I_MATNR              = BESTAND-MATNR
            I_IN_ME              = BESTAND-MEINS
            I_OUT_ME             = V_MEINS
            I_MENGE              = BESTAND-TOTAL
          IMPORTING
            E_MENGE              = V_MENGE
          EXCEPTIONS
            ERROR_IN_APPLICATION = 1
            ERROR                = 2
            OTHERS               = 3.
        BESTAND-SBMNG = V_MENGE * V_RATE.
      ELSE.
        BESTAND-SBMNG = BESTAND-TOTAL * V_RATE.
      ENDIF.

*&工厂单位,申报单位相应GMT中单位描述
*      SELECT SINGLE ZMSEH6 INTO BESTAND-MEINS_GC
*        FROM ZT006A WHERE MSEHI = BESTAND-MEINS_GC.
*
*      SELECT SINGLE ZMSEH6 INTO BESTAND-MEINS_GMT
*        FROM ZT006A WHERE MSEHI = BESTAND-MEINS_GMT.

    ENDIF.
    MODIFY BESTAND.
  ENDLOOP.
*
  IF P_UPD EQ 'X'.
    LOOP AT BESTAND.
      SELECT SINGLE * FROM ZM065 INTO I_ZM065
         WHERE CHARG = BESTAND-CHARG.
      CLEAR I_ZM065.
      IF SY-SUBRC >= 0.
        CALL FUNCTION 'WLF_READ_BKLAS'
          EXPORTING
            I_WERKS       = BESTAND-WERKS
            I_MATNR       = BESTAND-MATNR
          IMPORTING
            E_BKLAS       = BESTAND-BKLAS
          EXCEPTIONS
            MATERIAL_READ = 1
            NO_WERKS      = 2
            OTHERS        = 3.

        IF BESTAND-CHARG NE SPACE AND BESTAND-MTART = 'ZRAW'
           OR BESTAND-MTART = 'ZIMM'.
          CLEAR TA_EKKO.
          SELECT SINGLE EKPO~INCO1 EKKO~LIFNR EKPO~MATNR
                 EKKO~EKORG EKPO~WERKS
            INTO (BESTAND-INCO1,TA_EKKO-LIFNR,TA_EKKO-MATNR,
                  TA_EKKO-EKORG,TA_EKKO-WERKS)
            FROM EKPO
            JOIN EKKO ON EKKO~EBELN = EKPO~EBELN
            JOIN EKBE ON EKBE~EBELN = EKPO~EBELN
                     AND EKBE~EBELP = EKPO~EBELP
            WHERE EKBE~WERKS = BESTAND-WERKS
              AND EKBE~MATNR = BESTAND-MATNR
              AND EKBE~CHARG = BESTAND-CHARG
              AND EKBE~VGABE = '1'.
          IF BESTAND-CHARG NE SPACE AND BESTAND-INCO1 IS INITIAL.
            SELECT SINGLE EINE~INCO1 INTO BESTAND-INCO1
              FROM EINE
              JOIN EINA ON EINA~INFNR = EINE~INFNR
              WHERE EINE~EKORG = TA_EKKO-EKORG
                AND EINE~WERKS = TA_EKKO-WERKS
                AND EINA~MATNR = TA_EKKO-MATNR
                AND EINA~LIFNR = TA_EKKO-LIFNR.
          ENDIF.
        ELSEIF BESTAND-CHARG NE SPACE AND BESTAND-BKLAS BETWEEN '7900' AND '7920'.
          SELECT SINGLE  AUFNR INTO BESTAND-AUFNR
            FROM  AUFM "UP TO 1 ROWS
            WHERE WERKS = BESTAND-WERKS
              AND MATNR = BESTAND-MATNR
              AND CHARG = BESTAND-CHARG
              AND BWART = '101'.
        ENDIF.
        I_ZM065-CHARG = BESTAND-CHARG.
        I_ZM065-MATNR = BESTAND-MATNR.
        I_ZM065-BKLAS = BESTAND-BKLAS.
        I_ZM065-INCO1 = BESTAND-INCO1.
        I_ZM065-AUFNR = BESTAND-AUFNR.
        MODIFY ZM065 FROM I_ZM065.  "INSERT INTO ZM065 VALUES ZM065[].

      ENDIF.

    ENDLOOP.

  ENDIF.
ENDFORM.                    "data_selection

*----------------------------------------------------------------------*
*    f2000_COLLECT_collector.
*----------------------------------------------------------------------*

FORM. F2000_COLLECT_COLLECTOR.

* does the user want to suppress stock objects from plant   "n577268
* level ?                                                   "n577268
  IF  G_FLAG_SUPPRESS_INIT_LGORT = 'X'.                     "n577268
    IF  COLLECTOR-LGORT IS INITIAL.                         "n577268
*     ignore stock objects without storage location         "n577268
      EXIT.                  "--> go to exit                "n577268
    ENDIF.                                                  "n577268
  ENDIF.                                                    "n577268

************************************************************************
* process the functions "No zero stocks",
* "Negative stocks only", "Without batches" here
************************************************************************

  IF NEGATIV = 'X'.
*   ignore entry if all stocks are zero or greater
    IF COLLECTOR-LABST >= 0 AND COLLECTOR-EINME >= 0 AND
       COLLECTOR-INSME >= 0 AND COLLECTOR-RETME >= 0 AND
       COLLECTOR-SPEME >= 0 AND COLLECTOR-UMLME >= 0.
      EXIT.                  "--> go to exit
    ENDIF.
  ENDIF.

  IF NOZERO = 'X'.
*   ignore all entries without stock
    IF COLLECTOR-LABST = 0 AND COLLECTOR-EINME = 0 AND
       COLLECTOR-INSME = 0 AND COLLECTOR-RETME = 0 AND
       COLLECTOR-SPEME = 0 AND COLLECTOR-UMLME = 0.
      EXIT.                  "--> go to exit
    ENDIF.
  ENDIF.

  IF XMCHB IS INITIAL.
    CLEAR COLLECTOR-CHARG.
  ENDIF.

  COLLECT                    COLLECTOR.

ENDFORM.                     "f2000_COLLECT_collector.

*&---------------------------------------------------------------------*
*&      Form  check_author
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. CHECK_AUTHOR .
* AUTHORITY-CHECK OBJECT 'Y_WRK_LAG'
*  ID 'WERKS' FIELD WERKS-LOW
*  ID 'ACTVT' FIELD '03'.
*  IF SY-SUBRC NE 0.
*   MESSAGE I902 WITH '你没有工厂' WERKS-LOW  '的权限,请检查!'.
*   STOP.
*  ENDIF.
*
* AUTHORITY-CHECK OBJECT 'Y_WRK_LAG'
*  ID 'LGORT' FIELD LGORT-LOW
*  ID 'ACTVT' FIELD '03'.
*  IF SY-SUBRC NE 0.
*   MESSAGE I903 WITH '你没有库存地点' LGORT-LOW '的权限,请检查!'.
*   STOP.
*  ENDIF.

ENDFORM.                    " check_author
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_GRID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. DISPLAY_GRID .
  G_REPID = SY-REPID.
  LAYOUT-BOX_FIELDNAME = 'SET'.
  LAYOUT-ZEBRA      = 'X'.
  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  ADDFIELD 'WERKS'             '工厂'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'MTART'             '物料类型'                               '5'       'X'         ''    ''    ''.
  ADDFIELD 'MATNR'             '物料编码'                               '5'       'X'         ''    ''    ''.
  ADDFIELD 'LGORT'             '库位'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'LGOBE'             '库位描述'                               '10'      'X'         'X'    ''    ''.
  ADDFIELD 'SOBKZ'             '库存标示'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'SSNUM'             '特殊库存编号'                           '10'      'X'         ''    ''    ''.
  ADDFIELD 'PSPNR'             'WBS 元素'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'VBELN'             '销售订单号'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'POSNR'             '订单行号'                               '10'      'X'         ''    ''    'X'.
  ADDFIELD 'BSTKD'             '客户订单号'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'LIFNR'             '供应商代码'                             '10'      'X'         ''    ''    ''.
  ADDFIELD 'KUNNR'             '客户代码'                               '10'      'X'         ''    ''    'X'.
  ADDFIELD 'KZBWS'             '特别库存'                               '10'      'X'         ''    ''    'X'.
  ADDFIELD 'CHARG'             '批次号'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'MAKTX'             '物料描述'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'BWKEY'             '评估范围'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'MATKL'             '物料组'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'BWTTY'             '评估类别'                               '10'      'X'         ''    ''    'X'.
  ADDFIELD 'XCHAR'             '批量管理标识'                           '10'      'X'         ''    ''    'X'.
  ADDFIELD 'BWTAR'             '评估类型'                               '10'      'X'         ''    ''    'X'.
  ADDFIELD 'WAERS'             '货币码'                                 '10'      'X'         ''    ''    'X'.
  ADDFIELD 'NAME1'             '名称'                                   '10'      'X'         ''    ''    'X'.
  ADDFIELD 'LABST'             '非限制使用库存'                         '10'      'X'         ''    ''    'X'.
  ADDFIELD 'INSME'             '待检的库存'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'WINSM'             '待检的库存价值'                         '10'      'X'         ''    ''    'X'.
  ADDFIELD 'SPEME'             '冻结的库存'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'WSPEM'             '冻结的库存价值'                         '10'      'X'         ''    ''    'X'.
  ADDFIELD 'EINME'             '批次的总计库存'                         '10'      'X'         ''    ''    'X'.
  ADDFIELD 'WEINM'             '批次的总计库存价值'                     '10'      'X'         ''    ''    'X'.
  ADDFIELD 'MEINS'             '基本单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'TOTAL'             '总库存'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'WLABS'             '总库存价值'                             '10'      'X'         ''    ''    ''.
  ADDFIELD 'RETME'             '返回冻结的库存金额'                     '10'      'X'         ''    ''    'X'.
  ADDFIELD 'WRETM'             '返回冻结的库存金额'                     '10'      'X'         ''    ''    'X'.
  ADDFIELD 'UMLME'             '在途库存'                               '10'      'X'         ''    ''    'X'.
  ADDFIELD 'WUMLM'             '在途库存金额'                           '10'      'X'         ''    ''    'X'.
  ADDFIELD 'LVORM'             '物料输出标示'                           '10'      'X'         ''    ''    'X'.
  ADDFIELD 'BKLAS'             '评估类'                                 '10'      'X'         ''    ''    'X'.
  ADDFIELD 'BKBEZ'             '评估类描述'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'NTGEW'             '净重'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'BRGEW'             '总净重'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'GEWEI'             '重量单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'INCO1'             '采购方式'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'AUFNR'             '工单号'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GC'          'GMT工厂单位'                            '10'      'X'         ''    ''    'X'.
  ADDFIELD 'MEINS_ZH'          'GMT工厂单位'                            '10'      'X'         ''    ''    ''.
  ADDFIELD 'NTGEW_GMT'         'GMT备案重量KG'                          '10'      'X'         ''    ''    ''.
  ADDFIELD 'VARIA'             'G-S差异'                                '10'      'X'         ''    ''    ''.
  ADDFIELD 'SERIA'             '海关序号'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'CUSTN'             '海关编码'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'CUSTX'             '备案名称'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GMT'         '申报单位'                               '10'      'X'         ''    ''    'X'.
  ADDFIELD 'MEINS_GMT_ZH'      '申报单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'SBMNG'             '申报数量'                               '10'      'X'         ''    ''    ''.
ENDFORM.                    " DISPLAY_GRID
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. DISPLAY_DATA .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM          = G_REPID
      IS_LAYOUT                   = LAYOUT
*      I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
*      I_CALLBACK_USER_COMMAND     = SUB_CALLBACK_USER
*      I_CALLBACK_PF_STATUS_SET    = 'PF_STATUS_SET'
      IT_FIELDCAT                 = L_ALV_FILEDCAT
      I_GRID_TITLE                = ''
      I_SAVE                      = 'X'
    TABLES
      T_OUTTAB                    =  BESTAND.
  FREE BESTAND.
ENDFORM.                    " DISPLAY_DATA

*&---------------------------------------------------------------------*
*&      Form  GET_WIP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. GET_WIP .
*  CASE WERKS.
*   WHEN '3020' OR '3021' OR '3022' OR
*         '3026' OR '3027' OR '3028' OR '3012'."For eagle team order WIP
  PERFORM. GET_WIP_LEVELONE.
*    WHEN OTHERS.
*      PERFORM. GET_WIP_LEVELEND.
*  ENDCASE.

ENDFORM.                    " GET_WIP


*&---------------------------------------------------------------------*
*&      Form  GET_WIP_LEVELONE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. GET_WIP_LEVELONE .
  DATA:BEGIN OF H_ORDER,
       AUFNR TYPE AFKO-AUFNR, "Order Number
       RSNUM  TYPE AFKO-RSNUM,
*       WERKS  TYPE AUFK-WERKS,
       PROJN TYPE AFPO-PROJN,
       DISPO TYPE AFKO-DISPO, "MRP controller for the order
       LEAD_AUFNR TYPE AFKO-LEAD_AUFNR,
       ZVBELN     TYPE AUFK-ZVBELN,
       STAT  TYPE PORDARCH-STAT,"Product Order Status
       STATUS(10) TYPE C,       "Status Description
       MATNR TYPE AFPO-MATNR, "Material Number for Order
       MEINS TYPE AFPO-MEINS, "Base unit of measure
       GSTRP TYPE AFKO-GSTRP, "Basic start date
       GLTRP TYPE AFKO-GLTRP, "Basic finish date

       LEAD_PSMNG LIKE AFPO-PSMNG,  "leading order Production qty
       LEAD_WEMNG LIKE AFPO-WEMNG,  "leading order delivery qty
       PSMNG TYPE AFPO-PSMNG, "Order quantity
       WEMNG TYPE AFPO-WEMNG, "Qty of goods received on order unit
       UMREZ TYPE AFPO-UMREZ, "Numerator of conv ot base unit
       UMREN TYPE AFPO-UMREN, "Denominator of conv ot base unit.
       ISTAT TYPE TJ02T-ISTAT,
     END OF H_ORDER.
  DATA H_ORDER01 LIKE H_ORDER OCCURS 10 WITH HEADER LINE.
  DATA H_ORDER02 LIKE H_ORDER OCCURS 10 WITH HEADER LINE.

  TYPES: BEGIN OF ST_RESB,
           RSNUM TYPE RESB-RSNUM,
           RSPOS TYPE RESB-RSPOS,
           WERKS TYPE RESB-WERKS,
           LGORT TYPE RESB-LGORT,
           AUFNR TYPE RESB-AUFNR,
           POSNR TYPE RESB-POSNR,
           MATNR TYPE RESB-MATNR,
           MEINS TYPE RESB-MEINS,
           BDMNG TYPE RESB-BDMNG,
           ENMNG TYPE RESB-ENMNG,
           AUSCH TYPE RESB-AUSCH,
           AVOAU TYPE RESB-AVOAU,
         END OF ST_RESB.
  DATA WA_RESB TYPE ST_RESB.
  DATA IT_RESB TYPE TABLE OF ST_RESB WITH KEY RSNUM RSPOS." AUFNR MATNR.

  DATA: BEGIN OF HEAD OCCURS 0,
         WERKS LIKE MSEG-WERKS,
         MATNR LIKE MSEG-MATNR,
         XBLNR LIKE MKPF-XBLNR,
         AUFNR LIKE MSEG-AUFNR,
       END OF HEAD.

  DATA: BEGIN OF XMSEG OCCURS 0,
          MBLNR LIKE MSEG-MBLNR,
          MJAHR LIKE MSEG-MJAHR,
          ZEILE LIKE MSEG-ZEILE,
          XBLNR LIKE MKPF-XBLNR,
          MATNR LIKE MSEG-MATNR,
          SHKZG LIKE MSEG-SHKZG,
          MENGE LIKE MSEG-MENGE,
          MEINS LIKE MSEG-MEINS,
        END OF XMSEG.
  DATA:  BEGIN OF TA_MSEG OCCURS 0,
          AUFNR LIKE MSEG-AUFNR,
          MATNR LIKE MSEG-MATNR,
          MENGE LIKE MSEG-MENGE,
          MEINS LIKE MSEG-MEINS,
        END OF TA_MSEG.

  DATA: V_DMBTR LIKE MSEG-DMBTR,
        V_MENGE LIKE MSEG-MENGE.
  DATA CUTOFF  TYPE SY-DATUM.
  IF CUTOFF NE SY-DATUM.
    CUTOFF = SY-DATUM.
  ENDIF.
  DATA UNIT_RATE LIKE EKPO-MENGE.
  DATA: V_MEINS LIKE ZLJGB-MEINS. "GMT工厂商品单位
  DATA: V_NTGEW LIKE ZLJGB-NTGEW,
        V_RATE LIKE ZLJGB-RATE.

  DATA: V_MATNR TYPE MARC-MATNR.

**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
  SELECT K~RSNUM K~AUFNR K~LEAD_AUFNR MATNR GSTRP PSMNG WEMNG MEINS
         DISPO UMREZ UMREN PROJN
    INTO CORRESPONDING FIELDS OF TABLE H_ORDER02
    FROM AFKO AS K INNER JOIN AFPO AS P ON K~AUFNR = P~AUFNR
    WHERE P~DWERK IN WERKS
      AND K~AUFNR IN S_AUFNR
      AND P~PROJN IN S_PROJN
*      AND K~AUFNR = A~LEAD_AUFNR
      AND P~DAUTY = '10'  "PP PRODCTION ORDER
      AND K~FTRMI <= CUTOFF
      AND K~AUFNR NOT IN
        ( SELECT AUFNR FROM PORDARCH
           WHERE ( STAT = 'I0013'
                OR STAT = 'I0076'
                OR ( STAT = 'I0045' AND AEDAT <= CUTOFF )
                OR ( STAT = 'I0046' AND AEDAT <= CUTOFF ) )
             AND INACT = SPACE ).
  IF H_ORDER02[] IS INITIAL.
    IF WIP EQ 'X'.
      MESSAGE '没有符合条件的数据,请检查!' TYPE 'I'.
      STOP.
    ELSE.
      EXIT.
    ENDIF.
  ENDIF.

**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
*==============================================================
*READ RESB INTO INTERNAL TABLE IT_RESB
*==============================================================
  CLEAR IT_RESB.
  REFRESH IT_RESB.

  SELECT RSNUM RSPOS WERKS LGORT AUFNR POSNR MATNR MEINS
         BDMNG ENMNG AUSCH AVOAU
    INTO TABLE IT_RESB
    FROM RESB
    FOR ALL ENTRIES IN H_ORDER02
    WHERE  RSNUM = H_ORDER02-RSNUM
      AND DUMPS <> 'X'   "Phantom item
      AND XLOEK <> 'X'.  "Deleted item

  LOOP AT IT_RESB INTO WA_RESB.
    MOVE WA_RESB-WERKS TO HEAD-WERKS.
    MOVE WA_RESB-MATNR TO HEAD-MATNR.
    MOVE WA_RESB-AUFNR TO HEAD-AUFNR.
    MOVE WA_RESB-AUFNR TO HEAD-XBLNR.
    COLLECT HEAD.
  ENDLOOP.

  IF HEAD[] IS NOT INITIAL.
    SELECT MSEG~MBLNR MSEG~MJAHR MSEG~ZEILE MKPF~XBLNR MSEG~MATNR
           MSEG~SHKZG MSEG~MENGE MSEG~MEINS
      INTO TABLE XMSEG
      FROM MSEG
      JOIN MKPF ON MKPF~MBLNR = MSEG~MBLNR
      FOR ALL ENTRIES IN HEAD
      WHERE MSEG~WERKS = HEAD-WERKS
        AND MSEG~MATNR = HEAD-MATNR
        AND MKPF~XBLNR = HEAD-XBLNR
        AND BWART IN ('501','502').
    LOOP AT XMSEG.
      MOVE XMSEG-XBLNR TO TA_MSEG-AUFNR.
      CASE XMSEG-SHKZG.
        WHEN 'H'.
          XMSEG-MENGE = - XMSEG-MENGE.
        WHEN OTHERS.
      ENDCASE.
      MOVE-CORRESPONDING XMSEG TO TA_MSEG.
      COLLECT TA_MSEG.
    ENDLOOP.
  ENDIF.

  LOOP AT H_ORDER02 INTO H_ORDER.
    SELECT SINGLE STAT INTO H_ORDER-STAT
      FROM PORDARCH
      WHERE AUFNR = H_ORDER-AUFNR
        AND WERKS IN WERKS
        AND MATNR = H_ORDER-MATNR
        AND STAT = 'I0002'.
    IF SY-SUBRC <> 0.
      CONTINUE.
    ENDIF.

* Convert order unit qty to base unit qty
    H_ORDER-PSMNG = H_ORDER-PSMNG * H_ORDER-UMREZ / H_ORDER-UMREN.
    H_ORDER-WEMNG = H_ORDER-WEMNG * H_ORDER-UMREZ / H_ORDER-UMREN.

* Select Product Order Status
    CLEAR H_ORDER-STATUS.

    CLEAR H_ORDER-STAT.
    SELECT SINGLE STAT INTO H_ORDER-STAT
      FROM PORDARCH
      WHERE AUFNR = H_ORDER-AUFNR
        AND WERKS = WERKS
        AND MATNR = H_ORDER-MATNR
        AND STAT = 'I0046'.
    IF SY-SUBRC = 0.
      H_ORDER-STATUS = 'Closed'.
    ELSE.
      CLEAR H_ORDER-STAT.
      SELECT SINGLE STAT INTO H_ORDER-STAT
        FROM PORDARCH
        WHERE AUFNR = H_ORDER-AUFNR
          AND WERKS = WERKS
          AND MATNR = H_ORDER-MATNR
          AND STAT = 'I0045'.
      IF SY-SUBRC = 0.
        H_ORDER-STATUS = 'TEL.Completed'.
      ELSE.
        CLEAR H_ORDER-STAT.
        SELECT SINGLE STAT INTO H_ORDER-STAT
          FROM PORDARCH
          WHERE AUFNR = H_ORDER-AUFNR
            AND WERKS = WERKS
            AND MATNR = H_ORDER-MATNR
            AND STAT = 'I0012'.
        IF SY-SUBRC = 0.
          H_ORDER-STATUS = 'Delivered'.
        ELSE.
          H_ORDER-STATUS = 'Released'.
        ENDIF.
      ENDIF.
    ENDIF.
    IF H_ORDER-LEAD_AUFNR IS NOT INITIAL
       AND H_ORDER-LEAD_AUFNR <> H_ORDER-AUFNR.
      SELECT SINGLE PSMNG WEMNG INTO
        (H_ORDER-PSMNG,H_ORDER-WEMNG)
        FROM AFPO
        WHERE AUFNR = H_ORDER-LEAD_AUFNR.
    ENDIF.
    APPEND H_ORDER TO H_ORDER01.
  ENDLOOP.

  SORT H_ORDER01 BY AUFNR MATNR.


  CLEAR ITAB.REFRESH ITAB.
  LOOP AT H_ORDER01 INTO H_ORDER.
    ITAB-AUFNR = H_ORDER-LEAD_AUFNR.
    ITAB-SUB_AUFNR = H_ORDER-AUFNR.
    ITAB-MODEL = H_ORDER-MATNR.
    ITAB-PROJN = H_ORDER-PROJN.
    ITAB-MEINS = H_ORDER-MEINS.
    ITAB-PSMNG = H_ORDER-PSMNG.

    IF H_ORDER-LEAD_AUFNR IS NOT INITIAL
       AND H_ORDER-LEAD_AUFNR <> H_ORDER-AUFNR
       AND H_ORDER-LEAD_PSMNG <> 0.
      ITAB-WEMNG = H_ORDER-LEAD_WEMNG / H_ORDER-LEAD_PSMNG * H_ORDER-WEMNG.
    ELSE.
      ITAB-WEMNG = H_ORDER-WEMNG.
    ENDIF.

    LOOP AT IT_RESB INTO WA_RESB WHERE RSNUM = H_ORDER-RSNUM.
*     MOVE-CORRESPONDING IT_RESB TO ITAB.
      ITAB-WERKS = WA_RESB-WERKS.
      ITAB-LGORT = WA_RESB-LGORT.
      ITAB-MATNR = WA_RESB-MATNR.
      ITAB-GMEIN = WA_RESB-MEINS.
      ITAB-BDMNG = WA_RESB-BDMNG.
      ITAB-ENMNG = WA_RESB-ENMNG.

      IF ITAB-GMEIN = 'EA' OR ITAB-GMEIN = 'KEA'.
        P1 = WA_RESB-BDMNG / ( 1 + WA_RESB-AUSCH / 100 ) / ( 1 + WA_RESB-AVOAU / 100 ).
        ITAB-BDMNG = P1.

        IF H_ORDER-PSMNG NE 0.
          CLEAR P1.
          P1 = ( ITAB-BDMNG / H_ORDER-PSMNG ) * H_ORDER-WEMNG.
          ITAB-COMNG = P1.
        ENDIF.
      ELSE.
        ITAB-BDMNG = WA_RESB-BDMNG / ( 1 + WA_RESB-AUSCH / 100 ) / ( 1 + WA_RESB-AVOAU / 100 ).
        IF H_ORDER-PSMNG NE 0.
          ITAB-COMNG = ( ITAB-BDMNG / H_ORDER-PSMNG ) * H_ORDER-WEMNG.
        ENDIF.
      ENDIF.

      CLEAR TA_MSEG.
      READ TABLE TA_MSEG WITH KEY AUFNR = WA_RESB-AUFNR
                                  MATNR = WA_RESB-MATNR.
      MOVE TA_MSEG-MENGE TO ITAB-BADQTY.

      ITAB-WIPQTY = ITAB-ENMNG - ITAB-COMNG - ITAB-BADQTY.

      CLEAR V_DMBTR. CLEAR V_MENGE.
      SELECT SUM( DMBTR ) SUM( MENGE ) INTO (V_DMBTR,V_MENGE)
        FROM MSEG
        WHERE RSNUM = WA_RESB-RSNUM
          AND RSPOS = WA_RESB-RSPOS
          AND MATNR = WA_RESB-MATNR
          AND BWART = '261'.
      IF V_MENGE NE 0.
        ITAB-DMBTR = ITAB-WIPQTY * V_DMBTR / V_MENGE.
      ENDIF.
      SELECT SINGLE MAKTX INTO ITAB-MAKTX FROM MAKT
        WHERE MATNR = ITAB-MATNR
          AND SPRAS = SY-LANGU.

      SELECT SINGLE MAKTX INTO ITAB-MODTX FROM MAKT
        WHERE MATNR = ITAB-MODEL
          AND SPRAS = SY-LANGU.

      SELECT SINGLE MTART BRGEW NTGEW GEWEI FROM MARA
        INTO (ITAB-MTART,ITAB-BRGEW,ITAB-NTGEW,ITAB-GEWEI)
        WHERE MATNR = ITAB-MATNR.
      IF BESTAND-MTART = 'ZRAW' OR BESTAND-MTART = 'ZIMM'.
        CLEAR EORD.
        SELECT SINGLE MATNR WERKS LIFNR INTO
          (EORD-MATNR,EORD-WERKS,EORD-LIFNR)
          FROM EORD
          WHERE MATNR = ITAB-MATNR
            AND WERKS = ITAB-WERKS
            AND FLIFN = 'X'.
        IF SY-SUBRC NE 0.
          SELECT SINGLE MATNR WERKS LIFNR INTO
            (EORD-MATNR,EORD-WERKS,EORD-LIFNR)
            FROM EORD
            WHERE MATNR = ITAB-MATNR
              AND WERKS = ITAB-WERKS.
        ENDIF.
        SELECT SINGLE INCO1 INTO ITAB-INCO1
          FROM EINE JOIN EINA ON EINA~INFNR = EINE~INFNR
          WHERE MATNR = EORD-MATNR
            AND WERKS = EORD-WERKS
            AND LIFNR = EORD-LIFNR.
      ELSE.
      ENDIF.

      SELECT SINGLE MEINS NTGEW MEINS_GMT RATE SERIA CUSTN
             CUSTX MEINS_GMT1 MEINS_ZH MEINS_GMT_ZH
        INTO (ITAB-MEINS_GC,ITAB-NTGEW_GMT,ITAB-MEINS_GMT,V_RATE,
              ITAB-SERIA,ITAB-CUSTN,ITAB-CUSTX,ITAB-MEINS_GMT1,
              ITAB-MEINS_ZH,ITAB-MEINS_GMT_ZH)
        FROM ZLJGB
        WHERE MATNR = ITAB-MATNR.
      IF SY-SUBRC = 0.
        ITAB-VARIA =  ITAB-NTGEW_GMT - V_NTGEW.

        IF ITAB-MEINS <>  ITAB-MEINS_GC AND  ITAB-MEINS_GC NE SPACE.
          CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
            EXPORTING
              I_MATNR              = ITAB-MATNR
              I_IN_ME              = ITAB-MEINS
              I_OUT_ME             = ITAB-MEINS_GC
              I_MENGE              = ITAB-WIPQTY
            IMPORTING
              E_MENGE              = V_MENGE
            EXCEPTIONS
              ERROR_IN_APPLICATION = 1
              ERROR                = 2
              OTHERS               = 3.
          ITAB-SBMNG = V_MENGE * V_RATE.
        ELSE.
          ITAB-SBMNG =  ITAB-WIPQTY * V_RATE.
        ENDIF.
      ENDIF.

      APPEND ITAB TO ITAB.
      CLEAR ITAB.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    " GET_WIP_LEVELONE

*&---------------------------------------------------------------------*
*&      Form  GET_WIP_LEVELEND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. GET_WIP_LEVELEND.
  DATA:BEGIN OF H_ORDER,
       AUFNR TYPE AFKO-AUFNR, "Order Number
       RSNUM TYPE AFKO-RSNUM,
       WERKS TYPE AUFK-WERKS,
       MODEL LIKE AFPO-MATNR,
       PROJN TYPE AFPO-PROJN,
       DISPO TYPE AFKO-DISPO, "MRP controller for the order
       LEAD_AUFNR TYPE AFKO-LEAD_AUFNR,
       ZVBELN     TYPE AUFK-ZVBELN,
       STAT  TYPE PORDARCH-STAT,"Product Order Status
       STATUS(10) TYPE C,       "Status Description
       MATNR TYPE AFPO-MATNR, "Material Number for Order
       MEINS TYPE AFPO-MEINS, "Base unit of measure
       GSTRP TYPE AFKO-GSTRP, "Basic start date
       GLTRP TYPE AFKO-GLTRP, "Basic finish date

       LEAD_PSMNG LIKE AFPO-PSMNG,  "leading order Production qty
       LEAD_WEMNG LIKE AFPO-WEMNG,  "leading order delivery qty
       PSMNG TYPE AFPO-PSMNG, "Order quantity
       WEMNG TYPE AFPO-WEMNG, "Qty of goods received on order unit
       UMREZ TYPE AFPO-UMREZ, "Numerator of conv ot base unit
       UMREN TYPE AFPO-UMREN, "Denominator of conv ot base unit.
       ISTAT TYPE TJ02T-ISTAT,
     END OF H_ORDER.
  DATA H_ORDER01 LIKE H_ORDER OCCURS 10 WITH HEADER LINE.
  DATA H_ORDER02 LIKE H_ORDER OCCURS 10 WITH HEADER LINE.

  DATA CUTOFF  TYPE SY-DATUM.
  IF CUTOFF NE SY-DATUM.
    CUTOFF = SY-DATUM.
  ENDIF.
  DATA : LS_ORDER_OBJECTS TYPE BAPI_PP_ORDER_OBJECTS,
         LS_BAPIRET2 TYPE BAPIRET2,
         LS_HEADER TYPE STANDARD TABLE OF BAPI_ORDER_HEADER1,
         LS_COMPONENT TYPE STANDARD TABLE OF BAPI_ORDER_COMPONENT.
  DATA : WA LIKE LINE OF LS_COMPONENT.

  DATA UNIT_RATE LIKE EKPO-MENGE.
  DATA: V_MEINS LIKE ZLJGB-MEINS. "GMT工厂商品单位
  DATA: V_MENGE TYPE EKPO-MENGE, "SAP单位转换为GMT工厂商品单位数量!
        V_NTGEW LIKE ZLJGB-NTGEW,
        V_RATE LIKE ZLJGB-RATE.

**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
  SELECT K~RSNUM K~AUFNR K~LEAD_AUFNR P~MATNR AS MODEL K~GSTRP P~PSMNG
         P~WEMNG P~MEINS K~DISPO P~UMREZ P~UMREN P~PROJN
    INTO CORRESPONDING FIELDS OF TABLE H_ORDER02
    FROM AFKO AS K
    INNER JOIN AFPO AS P ON K~AUFNR = P~AUFNR
    INNER JOIN AUFK AS Q ON K~AUFNR = Q~AUFNR
    WHERE P~DWERK IN WERKS
      AND K~AUFNR IN S_AUFNR
      AND P~PROJN IN S_PROJN
      AND K~AUFNR = K~LEAD_AUFNR
      AND P~DAUTY = '10'  "PP PRODCTION ORDER
      AND K~FTRMI <= CUTOFF
      AND K~AUFNR NOT IN
        ( SELECT AUFNR FROM PORDARCH
           WHERE ( STAT = 'I0013'
                OR STAT = 'I0076'
                OR ( STAT = 'I0045' AND AEDAT <= CUTOFF )
                OR ( STAT = 'I0046' AND AEDAT <= CUTOFF ) )
             AND INACT = SPACE ).

  IF H_ORDER02[] IS INITIAL.
    MESSAGE '没有符合条件的数据,请检查!' TYPE 'I'.
    STOP.
  ENDIF.

  CLEAR:H_ORDER02,ITAB.REFRESH:ITAB.
  LOOP AT H_ORDER02.
    LS_ORDER_OBJECTS-COMPONENTS = 'X'.
    LS_ORDER_OBJECTS-HEADER = 'X'.
    CALL FUNCTION 'BAPI_PRODORD_GET_DETAIL'
      EXPORTING
        NUMBER                 = H_ORDER02-AUFNR
        COLLECTIVE_ORDER       = 'X'
        ORDER_OBJECTS          = LS_ORDER_OBJECTS
     IMPORTING
       RETURN                 = LS_BAPIRET2
     TABLES
       HEADER                 = LS_HEADER
*           POSITION               =
*           SEQUENCE               =
*           OPERATION              =
*           TRIGGER_POINT          =
       COMPONENT              = LS_COMPONENT
*           PROD_REL_TOOL          =
              .
    LOOP AT LS_COMPONENT INTO WA.
      MOVE H_ORDER02-WERKS TO ITAB-WERKS.
      MOVE H_ORDER02-MODEL TO ITAB-MODEL.
      SELECT SINGLE MAKTX INTO ITAB-MODTX
        FROM MAKT WHERE MATNR = ITAB-MODEL
                    AND SPRAS = SY-LANGU.
      MOVE H_ORDER02-PROJN TO ITAB-PROJN.
      MOVE H_ORDER02-LEAD_AUFNR TO ITAB-AUFNR.
      MOVE H_ORDER02-PSMNG TO ITAB-PSMNG.
      MOVE H_ORDER02-WEMNG TO ITAB-WEMNG.
      MOVE H_ORDER02-MEINS TO ITAB-MEINS.

      MOVE WA-ORDER_NUMBER TO ITAB-SUB_AUFNR.
      MOVE WA-RESERVATION_NUMBER TO ITAB-RSNUM.
      MOVE WA-MATERIAL TO ITAB-MATNR.
      MOVE WA-STORAGE_LOCATION TO ITAB-LGORT.
      MOVE WA-MATERIAL_DESCRIPTION TO ITAB-MAKTX.
      MOVE WA-ITEM_NUMBER TO ITAB-POSNR.
      MOVE WA-BASE_UOM TO ITAB-GMEIN.
      MOVE WA-WITHDRAWN_QUANTITY TO ITAB-ENMNG.
      MOVE WA-REQ_QUAN TO ITAB-BDMNG.
      ITAB-COMNG = ITAB-BDMNG / ITAB-PSMNG * ITAB-WEMNG.
      ITAB-WIPQTY = ITAB-ENMNG - ITAB-COMNG.

      SELECT SINGLE NTGEW GEWEI INTO (ITAB-NTGEW,ITAB-GEWEI)
             FROM MARA WHERE MATNR = ITAB-MATNR.

      ITAB-BRGEW = ITAB-NTGEW * ITAB-WIPQTY.
      IF ITAB-GEWEI = 'G'.
        ITAB-BRGEW = ITAB-BRGEW  / 1000.
      ELSEIF ITAB-GEWEI = 'MG'.
        ITAB-BRGEW = ITAB-BRGEW  / 10000000.
      ENDIF.
*      CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
*        EXPORTING
*          INPUT                = ITAB-BRGEW
*          ROUND_SIGN           = 'X'
*          UNIT_IN              = ITAB-GEWEI
*          UNIT_OUT             = 'KG'
*        IMPORTING
*          OUTPUT               = ITAB-BRGEW
*        EXCEPTIONS
*          CONVERSION_NOT_FOUND = 01
*          DIVISION_BY_ZERO     = 02
*          INPUT_INVALID        = 03
*          OUTPUT_INVALID       = 04
*          OVERFLOW             = 05
*          UNITS_MISSING        = 06
*          UNIT_IN_NOT_FOUND    = 07
*          UNIT_OUT_NOT_FOUND   = 08.
*      IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*      ENDIF.

      CLEAR V_MEINS.
      SELECT SINGLE MEINS NTGEW MEINS_GMT RATE SERIA CUSTN CUSTX MEINS_GMT
        INTO (ITAB-MEINS_GC,ITAB-NTGEW_GMT,ITAB-MEINS_GMT,V_RATE,ITAB-SERIA,
              ITAB-CUSTN,ITAB-CUSTX,ITAB-MEINS_GMT)
        FROM ZLJGB
        WHERE MATNR = ITAB-MATNR.

      CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
        EXPORTING
          INPUT                = ITAB-NTGEW
          ROUND_SIGN           = 'X'
          UNIT_IN              = ITAB-GEWEI
          UNIT_OUT             = 'KG'
        IMPORTING
          OUTPUT               = V_NTGEW
        EXCEPTIONS
          CONVERSION_NOT_FOUND = 01
          DIVISION_BY_ZERO     = 02
          INPUT_INVALID        = 03
          OUTPUT_INVALID       = 04
          OVERFLOW             = 05
          UNITS_MISSING        = 06
          UNIT_IN_NOT_FOUND    = 07
          UNIT_OUT_NOT_FOUND   = 08.
      IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

      ITAB-VARIA = ITAB-NTGEW_GMT - V_NTGEW.

      IF ITAB-MEINS <> ITAB-MEINS_GC AND ITAB-MEINS_GC NE SPACE.
        CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
          EXPORTING
            I_MATNR              = ITAB-MATNR
            I_IN_ME              = ITAB-MEINS
            I_OUT_ME             = ITAB-MEINS_GC
            I_MENGE              = ITAB-COMNG
          IMPORTING
            E_MENGE              = V_MENGE
          EXCEPTIONS
            ERROR_IN_APPLICATION = 1
            ERROR                = 2
            OTHERS               = 3.
        ITAB-SBMNG = V_MENGE * V_RATE.
      ELSE.
        ITAB-SBMNG = ITAB-COMNG * V_RATE.
      ENDIF.

      ITAB-WERKS = WERKS-LOW.
      APPEND ITAB.
      CLEAR ITAB.
    ENDLOOP.
  ENDLOOP.

ENDFORM.                    " GET_WIP_LEVELEND

*&---------------------------------------------------------------------*
*&      Form  GET_GRID_WIP_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. GET_WIP_GRID_DISPLAY.
  G_REPID = SY-REPID.
  LAYOUT-BOX_FIELDNAME = 'SET'.
  LAYOUT-ZEBRA      = 'X'.
  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  ADDFIELD 'WERKS'             '工厂'                                 '10'       'X'         ''    ''    ''.
  ADDFIELD 'MODEL'             '产品编码'                             '10'       'X'         ''    ''    ''.
  ADDFIELD 'MODTX'             '产品描述'                             '10'       'X'         ''    ''    ''.
  ADDFIELD 'PROJN'             'WBS元素'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'AUFNR'             'Order'                                '10'       'X'         ''    ''    ''.
  ADDFIELD 'MEINS'             '单位'                                 '10'       'X'         ''    ''    ''.
  ADDFIELD 'PSMNG'             '订单数量'                             '10'       'X'         ''    ''    ''.
  ADDFIELD 'WEMNG'             '成品收仓'                             '10'       'X'         ''    ''    ''.

  "  ADDFIELD 'AUFNR'             'Order'                                '10'       'X'         ''    ''    ''.
  ADDFIELD 'MATNR'             '物料'                                 '10'       'X'         ''    ''    ''.
  ADDFIELD 'MAKTX'             '物料描述'                             '10'       'X'         ''    ''    ''.
  ADDFIELD 'LGORT'             '仓位'                                 '10'       'X'         ''    ''    ''.
  ADDFIELD 'GMEIN'             '物料单位'                             '10'       'X'         ''    ''    ''.
  ADDFIELD 'COMNG'             '成品折算材料'                         '10'       'X'         ''    ''    ''.
  ADDFIELD 'ENMNG'             '已发数量'                             '10'       'X'         ''    ''    ''.
  "ADDFIELD 'BDMNG'             '需求数量'                             '10'       'X'         ''    ''    ''.
  ADDFIELD 'WIPQTY'            'WIP数量'                               '10'       'X'         ''    ''    ''.
  ADDFIELD 'INCO1'             '采购方式'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'NTGEW'             'SAP单重'                               '10'       'X'         ''    ''    ''.
  ADDFIELD 'GEWEI'             '重量单位'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'BRGEW'             '总重KG'                                '10'       'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GC'          'GMT工厂单位'                           '10'       'X'         ''    'X'    ''.
  ADDFIELD 'MEINS_GMT_ZH'      'GMT工厂单位'                           '10'       'X'         ''    ''    ''.
  ADDFIELD 'NTGEW_GMT'         'GMT单重KG'                             '10'       'X'         ''    ''    ''.
  ADDFIELD 'VARIA'             'G-S差异'                               '10'       'X'         ''    ''    ''.
  ADDFIELD 'SERIA'             '海关序号'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'CUSTN'             '海关编码'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'CUSTX'             '备案名称'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GMT'         '申报单位'                              '10'       'X'         ''    ''    'X'.
  ADDFIELD 'MEINS_GMT_ZH'      '申报单位'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'SBMNG'             '申报数量'                              '10'       'X'         ''    ''    ''.

ENDFORM.                    " DISPLAY_GRID_WIP
*&---------------------------------------------------------------------*
*&      Form  GET_WIP_DATA_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. GET_WIP_DATA_DISPLAY .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM          = G_REPID
      IS_LAYOUT                   = LAYOUT
*      I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
*      I_CALLBACK_USER_COMMAND     = SUB_CALLBACK_USER
*      I_CALLBACK_PF_STATUS_SET    = 'PF_STATUS_SET'
      IT_FIELDCAT                 = L_ALV_FILEDCAT
      I_GRID_TITLE                = ''
      I_SAVE                      = 'X'
    TABLES
      T_OUTTAB                    =  ITAB.
  FREE ITAB.
ENDFORM.                    " DISPLAY_DATA_WIP
*&---------------------------------------------------------------------*
*&      Form  CONSUMPTION_MATERIAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. CONSUMPTION_MATERIAL .

  CLEAR CONSUME. REFRESH CONSUME.
  DATA: PM_CAPID LIKE TC04-CAPID VALUE 'PP01'.
  DATA: P_STLAL LIKE MAST-STLAL VALUE '01'.
  DATA: PM_DATUV LIKE STPO-DATUV.
  DATA: BEGIN OF GT_MAST.
          INCLUDE STRUCTURE MAST.
  DATA:BMENG LIKE STKO-BMENG,
       BMEIN LIKE STKO-BMEIN,
*       STLAL LIKE STKO-STLAL,
       STLST LIKE STKO-STLST.
  DATA: END OF GT_MAST.

  DATA: BEGIN OF STB OCCURS 0."这个是分解BOM得到的数据
          INCLUDE STRUCTURE STPOX.
  DATA: END OF STB.
  RANGES:RS_MTART FOR MARA-MTART.
  DATA: WA LIKE STB.
  DATA: MATCAT LIKE TABLE OF CSCMAT WITH HEADER LINE.
  DATA V_STLAL TYPE STKO-STLAL."BOM的版本号

  DATA UNIT_RATE LIKE EKPO-MENGE.
  DATA: V_MEINS LIKE ZLJGB-MEINS. "GMT工厂商品单位
  DATA: V_MENGE TYPE EKPO-MENGE, "SAP单位转换为GMT工厂商品单位数量!
        V_NTGEW LIKE ZLJGB-NTGEW,
        V_RATE LIKE ZLJGB-RATE.
  DATA: V_MATNR TYPE MARC-MATNR.
  RS_MTART-LOW = 'ZRAW'.
  RS_MTART-OPTION = 'EQ'.
  RS_MTART-SIGN = 'I'.
  APPEND RS_MTART.
  RS_MTART-LOW = 'ZIMM'.
  RS_MTART-OPTION = 'EQ'.
  RS_MTART-SIGN = 'I'.
  APPEND RS_MTART.

  CLEAR:V_MATNR, BESTAND.
  LOOP AT BESTAND.
    IF BESTAND-MATNR <> V_MATNR.
      V_MATNR = BESTAND-MATNR.
      CLEAR:GT_MAST,STB.
      SELECT SINGLE * INTO GT_MAST
        FROM MAST WHERE MATNR EQ BESTAND-MATNR
                    AND WERKS EQ BESTAND-WERKS
                    AND STLAL EQ P_STLAL.
      SELECT SINGLE STLST INTO GT_MAST-STLST
        FROM STKO WHERE STLNR = GT_MAST-STLNR
                    AND STLAL = GT_MAST-STLAL.
      IF GT_MAST-STLST = '05'.
        PM_CAPID = 'PPSA'.
      ENDIF.
    ENDIF.

    PM_DATUV = SY-DATUM.
    CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
         EXPORTING
           STLAL     = GT_MAST-STLAL
           CAPID     = PM_CAPID
           DATUV     = PM_DATUV
           MTNRV     = V_MATNR
           WERKS     = BESTAND-WERKS
           MEHRS     = 'X'
           EMENG     = 10000000
         TABLES
           STB       = STB
           MATCAT    = MATCAT
         EXCEPTIONS
           ALT_NOT_FOUND         =  4
           CALL_INVALID          =  8
           OBJECT_NOT_FOUND      = 12
           MISSING_AUTHORIZATION = 16
           NO_BOM_FOUND          = 20
           NO_PLANT_DATA         = 24
*d      no_suitable_bom_found = 28.                  "HGD059252
          NO_SUITABLE_BOM_FOUND = 28                        "HGD059252
           CONVERSION_ERROR      = 32.

    IF SY-SUBRC <> 0.
      "WRITE: / WA_MAST-MATNR, ' BOM EXPLODED EXCEPTION FOR THIS ITEM.'.
    ENDIF.

    LOOP AT STB INTO WA.
      IF WA-MTART NOT IN RS_MTART.
        DELETE STB.
        CONTINUE.
      ENDIF.
      MOVE BESTAND-WERKS TO CONSUME-WERKS.
      MOVE BESTAND-MATNR TO CONSUME-MODEL.
      SELECT SINGLE MAKTX INTO CONSUME-MODTX
        FROM MAKT WHERE MATNR = CONSUME-MODEL
                    AND SPRAS = SY-LANGU.
      MOVE BESTAND-PSPNR TO CONSUME-PSPNR.
      MOVE BESTAND-LGORT TO CONSUME-LGORT.
      MOVE BESTAND-LGOBE TO CONSUME-LGOBE.
      MOVE BESTAND-CHARG TO CONSUME-CHARG.
      MOVE BESTAND-MEINS TO CONSUME-MEINS.
      MOVE BESTAND-LABST TO CONSUME-LABST.
      MOVE BESTAND-INSME TO CONSUME-INSME.
      MOVE BESTAND-SPEME TO CONSUME-SPEME.
      MOVE BESTAND-TOTAL TO CONSUME-TOTAL.
      MOVE BESTAND-WLABS TO CONSUME-WLABS.
      MOVE BESTAND-WAERS TO CONSUME-WAERS.
      MOVE BESTAND-AUFNR TO CONSUME-AUFNR.

      SELECT SINGLE PSMNG WEMNG MEINS
        INTO (CONSUME-PSMNG,CONSUME-WEMNG,CONSUME-MEINS)
        FROM AFPO WHERE AUFNR = CONSUME-AUFNR.

      MOVE WA-LGORT TO CONSUME-DLGORT.
      MOVE WA-POSNR  TO CONSUME-POSNR.
      MOVE WA-MTART TO CONSUME-MTART.
      MOVE WA-IDNRK  TO CONSUME-MATNR.
      SELECT SINGLE MAKTX INTO CONSUME-MAKTX
        FROM MAKT WHERE MATNR = CONSUME-MATNR
                    AND SPRAS = '1'.
      SELECT SINGLE MAKTX INTO CONSUME-MAKTZ
        FROM MAKT WHERE MATNR = CONSUME-MATNR
                    AND SPRAS = 'E'.
      MOVE WA-MENGE TO CONSUME-MENGE. "单位组件数量
      MOVE WA-MEINS TO CONSUME-GMEIN.
      MOVE WA-MMEIN TO CONSUME-MMEIN.
      CONSUME-COMNG = WA-MNGLG / 10000000 * CONSUME-TOTAL. "基本单位用量

      SELECT SINGLE MTART NTGEW GEWEI
          INTO (CONSUME-MTART,CONSUME-NTGEW,CONSUME-GEWEI)
          FROM MARA WHERE MATNR = CONSUME-MATNR.


      IF CONSUME-MTART = 'ZRAW' OR CONSUME-MTART = 'ZIMM'.
        CLEAR EORD.
        SELECT SINGLE MATNR WERKS LIFNR INTO
          (EORD-MATNR,EORD-WERKS,EORD-LIFNR)
          FROM EORD
          WHERE MATNR = CONSUME-MATNR
            AND WERKS = CONSUME-WERKS
            AND FLIFN = 'X'.
        IF SY-SUBRC NE 0.
          SELECT SINGLE MATNR WERKS LIFNR INTO
            (EORD-MATNR,EORD-WERKS,EORD-LIFNR)
            FROM EORD
            WHERE MATNR = CONSUME-MATNR
              AND WERKS = CONSUME-WERKS.
        ENDIF.
        SELECT SINGLE INCO1 INTO CONSUME-INCO1
          FROM EINE JOIN EINA ON EINA~INFNR = EINE~INFNR
          WHERE MATNR = EORD-MATNR
            AND WERKS = EORD-WERKS
            AND LIFNR = EORD-LIFNR.
      ENDIF.
      CONSUME-BRGEW = CONSUME-NTGEW * CONSUME-COMNG.

      IF CONSUME-GEWEI = 'G'.
        CONSUME-BRGEW = CONSUME-BRGEW / 1000.
        V_NTGEW = CONSUME-NTGEW / 1000.
      ELSEIF CONSUME-GEWEI = 'MG'.
        CONSUME-BRGEW = CONSUME-BRGEW / 1000000.
        V_NTGEW = CONSUME-NTGEW / 1000000.
      ENDIF.

*          CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
*            EXPORTING
*              INPUT                = CONSUME-BRGEW
*              ROUND_SIGN           = 'X'
*              UNIT_IN              = CONSUME-GEWEI
*              UNIT_OUT             = 'KG'
*            IMPORTING
*              OUTPUT               = CONSUME-BRGEW
*            EXCEPTIONS
*              CONVERSION_NOT_FOUND = 01
*              DIVISION_BY_ZERO     = 02
*              INPUT_INVALID        = 03
*              OUTPUT_INVALID       = 04
*              OVERFLOW             = 05
*              UNITS_MISSING        = 06
*              UNIT_IN_NOT_FOUND    = 07
*              UNIT_OUT_NOT_FOUND   = 08.
*          IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*          ENDIF.

*          CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*            EXPORTING
*              I_MATNR              = CONSUME-MATNR
*              I_IN_ME              = CONSUME-GEWEI
*              I_OUT_ME             = 'KG'
*              I_MENGE              = 1
*            IMPORTING
*              E_MENGE              = UNIT_RATE
*            EXCEPTIONS
*              ERROR_IN_APPLICATION = 1
*              ERROR                = 2
*              OTHERS               = 3.

      CLEAR V_MEINS.
      SELECT SINGLE MEINS NTGEW MEINS_GMT RATE
                    SERIA CUSTN CUSTX MEINS_GMT1 MEINS_ZH MEINS_GMT_ZH
        INTO (CONSUME-MEINS_GC,CONSUME-NTGEW_GMT,CONSUME-MEINS_GMT,V_RATE,
              CONSUME-SERIA,CONSUME-CUSTN,CONSUME-CUSTX,CONSUME-MEINS_GMT1,
              CONSUME-MEINS_ZH,CONSUME-MEINS_GMT_ZH)
        FROM ZLJGB
        WHERE MATNR = CONSUME-MATNR.
      IF SY-SUBRC = 0.
        CONSUME-VARIA = CONSUME-NTGEW_GMT - V_NTGEW.

        IF CONSUME-MMEIN <> CONSUME-MEINS_GC AND CONSUME-MEINS_GC NE SPACE.
          SELECT SINGLE MSEH3 INTO CONSUME-MEINS_GC
            FROM ZT006A WHERE MSEHI = CONSUME-MEINS_GC.

          CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
            EXPORTING
              I_MATNR              = CONSUME-MATNR
              I_IN_ME              = CONSUME-GMEIN
              I_OUT_ME             = CONSUME-MEINS_GC
              I_MENGE              = CONSUME-COMNG
            IMPORTING
              E_MENGE              = V_MENGE
            EXCEPTIONS
              ERROR_IN_APPLICATION = 1
              ERROR                = 2
              OTHERS               = 3.
          CONSUME-SBMNG = V_MENGE * V_RATE.
        ELSE.
          CONSUME-SBMNG = CONSUME-COMNG * V_RATE.
        ENDIF.
      ENDIF.

      APPEND CONSUME.
      CLEAR: CONSUME,WA.
    ENDLOOP.

  ENDLOOP.

  SORT CONSUME BY WERKS MTART MODEL MATNR DESCENDING.
ENDFORM.                    " CONSUMPTION_MATERIAL

*&---------------------------------------------------------------------*
*&      Form  CONSUPTION_GRID_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. CONSUPTION_GRID_DISPLAY.

  G_REPID = SY-REPID.
  LAYOUT-BOX_FIELDNAME = 'SET'.
  LAYOUT-ZEBRA      = 'X'.
  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
* ADDFIELD 'WERKS'             'Plant'                                 '10'       'X'         ''    ''    ''.
  ADDFIELD 'MODEL'             '成品'                      '10'       'X'         ''    ''    ''.
  ADDFIELD 'MODTX'             '成品描述'                  '10'       'X'         ''    ''    ''.
  ADDFIELD 'PSPNR'             'WBS元素'                   '10'       'X'         ''    ''    ''.
  ADDFIELD 'LGORT'             '仓位'                      '10'       'X'         ''    ''    ''.
  ADDFIELD 'CHARG'             '批次'                      '10'       'X'         ''    ''    ''.
  ADDFIELD 'LABST'             '库存数量'                  '10'       'X'         ''    ''    ''.

  ADDFIELD 'AUFNR'             '生产订单'                  '10'       'X'         ''    ''    ''.
  ADDFIELD 'MEINS'             '单位'                      '10'       'X'         ''    ''    ''.
  ADDFIELD 'PSMNG'             'Order Qty'                 '10'       'X'         ''    ''    ''.
  ADDFIELD 'WEMNG'             'Delivery Qty'              '10'       'X'         ''    ''    ''.

  ADDFIELD 'WERKS'             '工厂'                      '10'       'X'         ''    ''    ''.
  ADDFIELD 'DLGORT'            '材料仓位'                  '10'       'X'         ''    ''    ''.
  ADDFIELD 'POSNR'             '行号'                      '10'       'X'         ''    ''    ''.
  ADDFIELD 'MATNR'             '物料编码'                  '10'       'X'         ''    ''    ''.
  ADDFIELD 'MAKTX'             '物料描述'                  '10'       'X'         ''    ''    ''.
  ADDFIELD 'MMEIN'             '物料单位'                  '10'       'X'         ''    ''    ''.
  ADDFIELD 'COMNG'             '折算为材料'                            '10'       'X'         ''    ''    ''.
  ADDFIELD 'INCO1'             '采购方式'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'NTGEW'             'SAP单重'                               '10'       'X'         ''    ''    ''.
  ADDFIELD 'GEWEI'             '重量单位'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'BRGEW'             '总重KG'                                '10'       'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GC'          'GMT工厂单位'                           '10'       'X'         ''    ''    'X'.
  ADDFIELD 'MEINS_ZH'          'GMT工厂单位'                           '10'       'X'         ''    ''    ''.
  ADDFIELD 'NTGEW_GMT'         'GMT单重'                               '10'       'X'         ''    ''    ''.
  ADDFIELD 'VARIA'             'G-S差异'                               '10'       'X'         ''    ''    ''.
  ADDFIELD 'SERIA'             '海关序号'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'CUSTN'             '海关编码'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'CUSTX'             '备案名称'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GMT'         '申报单位'                              '10'       'X'         ''    ''    'X'.
  ADDFIELD 'MEINS_GMT_ZH'      '申报单位'                              '10'       'X'         ''    ''    ''.
  ADDFIELD 'SBMNG'             '申报数量'                              '10'       'X'         ''    ''    ''.

ENDFORM.                    " DISPLAY_GRID_WIP
*&---------------------------------------------------------------------*
*&      Form  CONSUPTION_DATA_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. CONSUPTION_DATA_DISPLAY.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM          = G_REPID
      IS_LAYOUT                   = LAYOUT
*      I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
*      I_CALLBACK_USER_COMMAND     = SUB_CALLBACK_USER
*      I_CALLBACK_PF_STATUS_SET    = 'PF_STATUS_SET'
      IT_FIELDCAT                 = L_ALV_FILEDCAT
      I_GRID_TITLE                = ''
      I_SAVE                      = 'X'
    TABLES
      T_OUTTAB                    =  CONSUME.

ENDFORM.                    " DISPLAY_DATA_WIP

*&---------------------------------------------------------------------*
*&      Form  INIT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. INIT_DATA .
  IF COM = 'X'.
    MATART-LOW = 'ZIMM'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZRAW'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZASM1'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZCMS'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZFPC'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZFPW'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZJFG'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZMPN'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZNFG'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZPRT'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZZFG'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.
  ELSEIF PRD = 'X'.
    MATART-LOW = 'ZASM1'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZCMS'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZFPC'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZFPW'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZJFG'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZMPN'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZNFG'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZPRT'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.

    MATART-LOW = 'ZZFG'.
    MATART-SIGN = 'I'.
    MATART-OPTION = 'EQ'.
    APPEND MATART.
  ENDIF.
ENDFORM.                    " INIT_DATA

*&---------------------------------------------------------------------*
*&      Form  COMBINE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. COMBINE_DATA.
  SORT BESTAND BY WERKS MTART MATNR IDNRK.
  CLEAR:COMBINE.REFRESH:COMBINE.
  LOOP AT BESTAND.
    CASE BESTAND-MTART.
      WHEN 'ZRAW' OR 'ZIMM'.
        MOVE: 'RAW' TO COMBINE-FLAG, "RAW stock
              BESTAND-WERKS TO COMBINE-WERKS,
              BESTAND-MTART TO COMBINE-MTART,
              BESTAND-MATNR TO COMBINE-MATNR,
              BESTAND-MAKTX TO COMBINE-MAKTX,
              BESTAND-LGORT TO COMBINE-LGORT,
              BESTAND-LGOBE TO COMBINE-LGOBE,
              BESTAND-PSPNR TO COMBINE-PSPNR,
              BESTAND-CHARG TO COMBINE-CHARG,
              BESTAND-MEINS TO COMBINE-MEINS,
              BESTAND-LABST TO COMBINE-LABST,
              BESTAND-INSME TO COMBINE-INSME,
              BESTAND-SPEME TO COMBINE-SPEME,
              BESTAND-TOTAL TO COMBINE-TOTAL.
        IF BESTAND-LABST <> 0.
          BESTAND-WLABS = BESTAND-WLABS / BESTAND-LABST.
        ENDIF.
        MOVE: BESTAND-WAERS TO COMBINE-WAERS,
              BESTAND-INCO1 TO COMBINE-INCO1,
              BESTAND-NTGEW TO COMBINE-NTGEW,
              BESTAND-GEWEI TO COMBINE-GEWEI,
              BESTAND-BRGEW TO COMBINE-BRGEW,
              BESTAND-MEINS_GC TO COMBINE-MEINS_GC,
              BESTAND-NTGEW_GMT TO COMBINE-NTGEW_GMT,
              BESTAND-MEINS_GMT TO COMBINE-MEINS_GMT,
              BESTAND-VARIA TO COMBINE-VARIA,
              BESTAND-CUSTN TO COMBINE-CUSTN,
              BESTAND-CUSTX TO COMBINE-CUSTX,
              BESTAND-MEINS_GMT1 TO COMBINE-MEINS_GMT1,
              BESTAND-SBMNG TO COMBINE-SBMNG.
        APPEND COMBINE.
        DELETE BESTAND.
        CLEAR BESTAND.
      WHEN OTHERS.
    ENDCASE.
  ENDLOOP.

  PERFORM. CONSUMPTION_MATERIAL.
  FREE BESTAND.
  CLEAR COMBINE.
  LOOP AT CONSUME.
    MOVE: 'PRD' TO COMBINE-FLAG, "成品折算原材料
          CONSUME-WERKS TO COMBINE-WERKS,
          CONSUME-MTART TO COMBINE-MTART,
          CONSUME-MODEL TO COMBINE-MODEL,
          CONSUME-MATNR TO COMBINE-MATNR,
          CONSUME-MAKTX TO COMBINE-MAKTX,
          CONSUME-LGORT TO COMBINE-LGORT,
          CONSUME-LGOBE TO COMBINE-LGOBE,
          CONSUME-PSPNR TO COMBINE-PSPNR,
          CONSUME-CHARG TO COMBINE-CHARG,
          CONSUME-MEINS TO COMBINE-MEINS,
          CONSUME-LABST TO COMBINE-LABST,
          CONSUME-INSME TO COMBINE-INSME,
          CONSUME-SPEME TO COMBINE-SPEME,
          CONSUME-TOTAL TO COMBINE-TOTAL,
          CONSUME-WLABS TO COMBINE-WLABS,
          CONSUME-WAERS TO COMBINE-WAERS.
    IF CONSUME-LABST <> 0.
      CONSUME-WLABS = CONSUME-WLABS / CONSUME-LABST.
    ENDIF.
    MOVE: CONSUME-COMNG TO COMBINE-COMNG,
          CONSUME-AUFNR TO COMBINE-AUFNR,
          CONSUME-WAERS TO COMBINE-WAERS,
          CONSUME-INCO1 TO COMBINE-INCO1,
          CONSUME-NTGEW TO COMBINE-NTGEW,
          CONSUME-GEWEI TO COMBINE-GEWEI,
          CONSUME-BRGEW TO COMBINE-BRGEW,
          CONSUME-MEINS_GC TO COMBINE-MEINS_GC,
          CONSUME-NTGEW_GMT TO COMBINE-NTGEW_GMT,
          CONSUME-MEINS_GMT TO COMBINE-MEINS_GMT,
          CONSUME-VARIA TO COMBINE-VARIA,
          CONSUME-CUSTN TO COMBINE-CUSTN,
          CONSUME-CUSTX TO COMBINE-CUSTX,
          CONSUME-MEINS_GMT1 TO COMBINE-MEINS_GMT1,
          CONSUME-SBMNG TO COMBINE-SBMNG.
    APPEND COMBINE.
  ENDLOOP.
  FREE CONSUME.

  PERFORM. GET_WIP.
  CHECK ITAB[] IS NOT INITIAL.
  CLEAR:ITAB,COMBINE.
  LOOP AT ITAB.
    MOVE: 'WIP' TO COMBINE-FLAG.  "WIP stock
    COMBINE-WERKS = ITAB-WERKS.
    COMBINE-MTART = ITAB-MTART.
    COMBINE-MATNR = ITAB-MATNR.
    COMBINE-MAKTX = ITAB-MAKTX.
    COMBINE-MODEL = ITAB-MODEL.
    COMBINE-MODTX = ITAB-MODTX.
    COMBINE-LGORT = ITAB-LGORT.
    COMBINE-PSPNR = ITAB-PROJN.
    COMBINE-WIPQTY = ITAB-WIPQTY.
    COMBINE-TOTAL = ITAB-WIPQTY.
    COMBINE-WLABS = ITAB-DMBTR.
    COMBINE-WAERS = 'RMB'.
    COMBINE-MEINS = ITAB-MEINS.
    COMBINE-AUFNR = ITAB-AUFNR.
    COMBINE-INCO1 = ITAB-INCO1.
    COMBINE-NTGEW = ITAB-NTGEW.
    COMBINE-GEWEI = ITAB-GEWEI.
    COMBINE-BRGEW = ITAB-BRGEW.
    COMBINE-MEINS_GC = ITAB-MEINS_GC.
    COMBINE-MEINS_GMT = ITAB-MEINS_GMT.
    COMBINE-VARIA = ITAB-VARIA.
    COMBINE-SERIA = ITAB-SERIA.
    COMBINE-CUSTN = ITAB-CUSTN.
    COMBINE-CUSTX = ITAB-CUSTX.
    COMBINE-MEINS_GMT = ITAB-MEINS_GMT.
    COMBINE-SBMNG = ITAB-SBMNG.
    APPEND COMBINE TO COMBINE.
  ENDLOOP.
  SORT COMBINE BY FLAG WERKS MTART MODEL MATNR DESCENDING.

ENDFORM.                    " COMBINE_EXPORE_MODEL

*&---------------------------------------------------------------------*
*&      Form. COMBINE_DISPLAY_GRID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. COMBINE_DISPLAY_GRID.
  G_REPID = SY-REPID.
  LAYOUT-BOX_FIELDNAME = 'SET'.
  LAYOUT-ZEBRA      = 'X'.
  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  ADDFIELD 'FLAG'              '标示'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'WERKS'             '工厂'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'MODEL'             '成品编码'                               '5'       'X'         ''    ''    ''.
  ADDFIELD 'MTART'             '物料类型'                               '5'       'X'         ''    ''    ''.
  ADDFIELD 'MATNR'             '物料编码'                               '5'       'X'         ''    ''    ''.
  ADDFIELD 'LGORT'             '库位'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'LGOBE'             '库位描述'                               '10'      'X'         'X'    ''    ''.
  ADDFIELD 'PSPNR'             'WBS 元素'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'CHARG'             '批次号'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'MAKTX'             '物料描述'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'LABST'             '非限制使用库存'                         '10'      'X'         ''    ''    'X'.
  ADDFIELD 'INSME'             '待检的库存'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'SPEME'             '冻结的库存'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'MEINS'             '基本单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'WIPQTY'            'WIP数量'                                '10'      'X'         ''    ''    ''.
  ADDFIELD 'TOTAL'             '总库存'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'WAERS'             '货币码'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'WLABS'             '总库存价值'                             '10'      'X'         ''    ''    ''.
  ADDFIELD 'AUFNR'             '工单号'                                 '10'      'X'         ''    ''    ''.

  ADDFIELD 'COMNG'             '折算为材料'                             '10'      'X'         ''    ''    ''.
  ADDFIELD 'INCO1'             '采购方式'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'NTGEW'             'SAP单重'                                '10'      'X'         ''    ''    ''.
  ADDFIELD 'GEWEI'             '重量单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'BRGEW'             '总重KG'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GC'          'GMT工厂单位'                            '10'      'X'         ''    ''    ''.
  ADDFIELD 'NTGEW_GMT'         'GMT备案重量KG'                          '10'      'X'         ''    ''    ''.
  ADDFIELD 'VARIA'             'G-S差异'                                '10'      'X'         ''    ''    ''.
  ADDFIELD 'SERIA'             '海关序号'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'CUSTN'             '海关编码'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'CUSTX'             '备案名称'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GMT'         '申报单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'SBMNG'             '申报数量'                               '10'      'X'         ''    ''    ''.

ENDFORM.                    " DISPLAY_GRID
*&---------------------------------------------------------------------*
*&      Form  COMBINE_DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. COMBINE_DISPLAY_DATA.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM          = G_REPID
      IS_LAYOUT                   = LAYOUT
*      I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
*      I_CALLBACK_USER_COMMAND     = SUB_CALLBACK_USER
*      I_CALLBACK_PF_STATUS_SET    = 'PF_STATUS_SET'
      IT_FIELDCAT                 = L_ALV_FILEDCAT
      I_GRID_TITLE                = ''
      I_SAVE                      = 'X'
    TABLES
      T_OUTTAB                    =  COMBINE.
ENDFORM.                    " DISPLAY_DATA


*&---------------------------------------------------------------------*
*&      Form  COMBINE_DATA1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. COMBINE_DATA1.
  SORT BESTAND BY WERKS MTART MATNR IDNRK.
  CLEAR:COMBINE.REFRESH:COMBINE.
  DATA TABINDEX TYPE SY-TABIX.
  DATA V_MATNR TYPE MATNR.
  CLEAR BESTAND.
  LOOP AT BESTAND.
    IF V_MATNR <> BESTAND-MATNR.
      V_MATNR = BESTAND-MATNR.
      CASE BESTAND-MTART.
        WHEN 'ZRAW' OR 'ZIMM'.
          MOVE: BESTAND-WERKS TO COMBINE-WERKS,
                BESTAND-MTART TO COMBINE-MTART,
                BESTAND-MATNR TO COMBINE-MATNR,
                BESTAND-MAKTX TO COMBINE-MAKTX,
                BESTAND-LGORT TO COMBINE-LGORT,
                BESTAND-LGOBE TO COMBINE-LGOBE,
                BESTAND-PSPNR TO COMBINE-PSPNR,
                BESTAND-CHARG TO COMBINE-CHARG,
                BESTAND-MEINS TO COMBINE-MEINS,
                BESTAND-LABST TO COMBINE-LABST,
                BESTAND-INSME TO COMBINE-INSME,
                BESTAND-SPEME TO COMBINE-SPEME,
                BESTAND-TOTAL TO COMBINE-TOTAL.
          IF BESTAND-LABST <> 0.
            BESTAND-WLABS = BESTAND-WLABS / BESTAND-LABST.
          ENDIF.
          MOVE: BESTAND-WAERS TO COMBINE-WAERS,
                BESTAND-INCO1 TO COMBINE-INCO1,
                BESTAND-NTGEW TO COMBINE-NTGEW,
                BESTAND-GEWEI TO COMBINE-GEWEI,
                BESTAND-BRGEW TO COMBINE-BRGEW,
                BESTAND-MEINS_GC TO COMBINE-MEINS_GC,
                BESTAND-NTGEW_GMT TO COMBINE-NTGEW_GMT,
                BESTAND-MEINS_GMT TO COMBINE-MEINS_GMT,
                BESTAND-VARIA TO COMBINE-VARIA,
                BESTAND-CUSTN TO COMBINE-CUSTN,
                BESTAND-CUSTX TO COMBINE-CUSTX,
                BESTAND-MEINS_GMT1 TO COMBINE-MEINS_GMT1,
                BESTAND-SBMNG TO COMBINE-SBMNG.
          APPEND COMBINE.
          DELETE BESTAND.
          CLEAR BESTAND.
        WHEN OTHERS.
      ENDCASE.
    ELSE.
      READ TABLE COMBINE WITH KEY MATNR = BESTAND-MATNR
                            WERKS = BESTAND-WERKS.
      IF SY-SUBRC = 0.
        TABINDEX = SY-TABIX.
        ADD BESTAND-BRGEW TO COMBINE-BRGEW.
        ADD BESTAND-TOTAL TO COMBINE-TOTAL.
        ADD BESTAND-SBMNG TO COMBINE-SBMNG.
        MODIFY COMBINE INDEX TABINDEX TRANSPORTING BRGEW TOTAL SBMNG.
      ENDIF.
    ENDIF.
  ENDLOOP.

  PERFORM. CONSUMPTION_MATERIAL.
  FREE BESTAND.

  CLEAR CONSUME.
  LOOP AT CONSUME.
    CLEAR COMBINE.
    READ TABLE COMBINE WITH KEY MATNR = CONSUME-MATNR
                                WERKS = CONSUME-WERKS.
    IF SY-SUBRC = 0.
      TABINDEX = SY-TABIX.
      MOVE: CONSUME-COMNG TO COMBINE-COMNG,
            CONSUME-SBMNG TO COMBINE-SBMNG.
      MODIFY COMBINE INDEX TABINDEX FROM COMBINE TRANSPORTING COMNG SBMNG.
    ELSE.
      MOVE: CONSUME-WERKS TO COMBINE-WERKS,
            CONSUME-MTART TO COMBINE-MTART,
            CONSUME-MATNR TO COMBINE-MATNR,
            CONSUME-MAKTX TO COMBINE-MAKTX,
            CONSUME-LGORT TO COMBINE-LGORT,
            CONSUME-LGOBE TO COMBINE-LGOBE,
            CONSUME-PSPNR TO COMBINE-PSPNR,
            CONSUME-CHARG TO COMBINE-CHARG,
            CONSUME-MEINS TO COMBINE-MEINS,
            CONSUME-LABST TO COMBINE-LABST,
            CONSUME-INSME TO COMBINE-INSME,
            CONSUME-SPEME TO COMBINE-SPEME,
            CONSUME-TOTAL TO COMBINE-TOTAL,
            CONSUME-WLABS TO COMBINE-WLABS,
            CONSUME-WAERS TO COMBINE-WAERS.
      IF CONSUME-LABST <> 0.
        CONSUME-WLABS = CONSUME-WLABS / CONSUME-LABST.
      ENDIF.
      MOVE: CONSUME-COMNG TO COMBINE-COMNG,
            CONSUME-WAERS TO COMBINE-WAERS,
            CONSUME-INCO1 TO COMBINE-INCO1,
            CONSUME-NTGEW TO COMBINE-NTGEW,
            CONSUME-GEWEI TO COMBINE-GEWEI,
            CONSUME-BRGEW TO COMBINE-BRGEW,
            CONSUME-MEINS_GC TO COMBINE-MEINS_GC,
            CONSUME-NTGEW_GMT TO COMBINE-NTGEW_GMT,
            CONSUME-MEINS_GMT TO COMBINE-MEINS_GMT,
            CONSUME-VARIA TO COMBINE-VARIA,
            CONSUME-CUSTN TO COMBINE-CUSTN,
            CONSUME-CUSTX TO COMBINE-CUSTX,
            CONSUME-MEINS_GMT1 TO COMBINE-MEINS_GMT1,
            CONSUME-SBMNG TO COMBINE-SBMNG.
      APPEND COMBINE.
    ENDIF.
  ENDLOOP.
  FREE CONSUME.

  PERFORM. GET_WIP.
  CHECK ITAB[] IS NOT INITIAL.
  CLEAR:ITAB,COMBINE.
  LOOP AT ITAB.
    READ TABLE COMBINE WITH KEY MATNR = ITAB-MATNR
                                WERKS = ITAB-WERKS.
    IF SY-SUBRC = 0.
      TABINDEX = SY-TABIX.
      COMBINE-WIPQTY = ITAB-WIPQTY.
      MODIFY COMBINE INDEX TABINDEX TRANSPORTING WIPQTY.
    ELSE.
      COMBINE-WERKS = ITAB-WERKS.
      COMBINE-MTART = ITAB-MTART.
      COMBINE-MATNR = ITAB-MATNR.
      COMBINE-MAKTX = ITAB-MAKTX.
      COMBINE-LGORT = ITAB-LGORT.
      COMBINE-PSPNR = ITAB-PROJN.
      COMBINE-WIPQTY = ITAB-WIPQTY.
      COMBINE-TOTAL = ITAB-WIPQTY.
      COMBINE-WLABS = ITAB-DMBTR.
      COMBINE-WAERS = 'RMB'.
      COMBINE-MEINS = ITAB-GMEIN.
      COMBINE-INCO1 = ITAB-INCO1.
      COMBINE-NTGEW = ITAB-NTGEW.
      COMBINE-GEWEI = ITAB-GEWEI.
      COMBINE-BRGEW = ITAB-BRGEW.
      COMBINE-MEINS_GC = ITAB-MEINS_GC.
      COMBINE-MEINS_GMT = ITAB-MEINS_GMT.
      COMBINE-VARIA = ITAB-VARIA.
      COMBINE-SERIA = ITAB-SERIA.
      COMBINE-CUSTN = ITAB-CUSTN.
      COMBINE-CUSTX = ITAB-CUSTX.
      COMBINE-MEINS_GMT = ITAB-MEINS_GMT.
      COMBINE-SBMNG = ITAB-SBMNG.
      APPEND COMBINE TO COMBINE.
    ENDIF.
  ENDLOOP.
  SORT COMBINE BY WERKS MTART MODEL MATNR DESCENDING.

ENDFORM.                    " COMBINE_EXPORE_MODEL1

*&---------------------------------------------------------------------*
*&      Form. COMBINE_DISPLAY_GRID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. COMBINE_DISPLAY_GRID1.
  G_REPID = SY-REPID.
  LAYOUT-BOX_FIELDNAME = 'SET'.
  LAYOUT-ZEBRA      = 'X'.
  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  ADDFIELD 'WERKS'             '工厂'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'MTART'             '物料类型'                               '5'       'X'         ''    ''    ''.
  ADDFIELD 'MATNR'             '物料编码'                               '5'       'X'         ''    ''    ''.
  ADDFIELD 'LGORT'             '库位'                                   '10'      'X'         ''    ''    ''.
  ADDFIELD 'LGOBE'             '库位描述'                               '10'      'X'         'X'    ''    ''.
  ADDFIELD 'PSPNR'             'WBS 元素'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'MAKTX'             '物料描述'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'LABST'             '非限制使用库存'                         '10'      'X'         ''    ''    'X'.
  ADDFIELD 'INSME'             '待检的库存'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'SPEME'             '冻结的库存'                             '10'      'X'         ''    ''    'X'.
  ADDFIELD 'MEINS'             '基本单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'COMNG'             '折算为材料'                             '10'      'X'         ''    ''    ''.
  ADDFIELD 'WIPQTY'            'WIP数量'                                '10'      'X'         ''    ''    ''.
  ADDFIELD 'TOTAL'             '总库存'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'WAERS'             '货币码'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'WLABS'             '总库存价值'                             '10'      'X'         ''    ''    ''.
  ADDFIELD 'INCO1'             '采购方式'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'NTGEW'             'SAP单重'                                '10'      'X'         ''    ''    ''.
  ADDFIELD 'GEWEI'             '重量单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'BRGEW'             '总重KG'                                 '10'      'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GC'          'GMT工厂单位'                            '10'      'X'         ''    ''    ''.
  ADDFIELD 'NTGEW_GMT'         'GMT备案重量KG'                          '10'      'X'         ''    ''    ''.
  ADDFIELD 'VARIA'             'G-S差异'                                '10'      'X'         ''    ''    ''.
  ADDFIELD 'SERIA'             '海关序号'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'CUSTN'             '海关编码'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'CUSTX'             '备案名称'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'MEINS_GMT'         '申报单位'                               '10'      'X'         ''    ''    ''.
  ADDFIELD 'SBMNG'             '申报数量'                               '10'      'X'         ''    ''    ''.

ENDFORM.                    " DISPLAY_GRID
*&---------------------------------------------------------------------*
*&      Form  COMBINE_DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM. COMBINE_DISPLAY_DATA1.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM          = G_REPID
      IS_LAYOUT                   = LAYOUT
*      I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
*      I_CALLBACK_USER_COMMAND     = SUB_CALLBACK_USER
*      I_CALLBACK_PF_STATUS_SET    = 'PF_STATUS_SET'
      IT_FIELDCAT                 = L_ALV_FILEDCAT
      I_GRID_TITLE                = ''
      I_SAVE                      = 'X'
    TABLES
      T_OUTTAB                    =  COMBINE.
ENDFORM.                    " DISPLAY_DATA

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16181884/viewspace-735627/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 学习报表
请登录后发表评论 登录
全部评论

注册时间:2012-07-16

  • 博文量
    47
  • 访问量
    50437