`
Jack Wu
  • 浏览: 891477 次
  • 来自: ...
社区版块
存档分类
最新评论

SAP的BOM删除和维护

阅读更多

1、删除BOM函数
 CSAP_MAT_BOM_DELETE

2、删除BOM(DELETE)方法
参见sap的标准程序RCBOMDEL

3、BOM新增函数
BAPI_MATERIAL_BOM_GROUP_CREATE
*&---------------------------------------------------------------------*
*& Report  ZTS_I_COPY_COSTBOM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTS_I_COPY_COSTBOM.

TABLES: MAST,MARA,MARC,STKO,STPO,AFKO,AFPO,RESB,T100.

DATA: BEGIN OF IT_TAB OCCURS 0,
        AUFNR LIKE AFKO-AUFNR,
        GSTRI LIKE AFKO-GSTRI,
        GSUZI LIKE AFKO-GSUZI,
        RSNUM LIKE AFKO-RSNUM,
        GAMNG LIKE AFKO-GAMNG,
        MATNR LIKE AFPO-MATNR,
        WERKS LIKE AUFK-WERKS,
        OBJNR LIKE AUFK-OBJNR,
      END OF IT_TAB.

DATA: BEGIN OF IT_SORT OCCURS 0,
        GSTRI LIKE AFKO-GSTRI,
        GSUZI LIKE AFKO-GSUZI,
        AUFNR LIKE AFKO-AUFNR,
        RSNUM LIKE AFKO-RSNUM,
        GAMNG LIKE AFKO-GAMNG,
        MATNR LIKE AFPO-MATNR,
        WERKS LIKE AUFK-WERKS,
        OBJNR LIKE AUFK-OBJNR,
      END OF IT_SORT.

DATA: BEGIN OF IT_TAB2 OCCURS 0,
        AUFNR LIKE AFKO-AUFNR,
        RSNUM LIKE AFKO-RSNUM,
        MATNR LIKE MARA-MATNR,
        WERKS LIKE MARC-WERKS,
        GAMNG LIKE AFKO-GAMNG,
        FLAG(1),
        MSG(100),
      END OF IT_TAB2.

DATA: BEGIN OF IT_ITEM OCCURS 0 ,
        RSNUM LIKE AFKO-RSNUM,
        MATNR LIKE RESB-MATNR,
        BDMNG LIKE RESB-BDMNG,
        MEINS LIKE RESB-MEINS,
        POSTP LIKE RESB-POSTP,
        WERKS LIKE MARC-WERKS,
        LVORM LIKE MARC-LVORM,
        MMSTA LIKE MARC-MMSTA,
        MSTAE LIKE MARA-MSTAE,
      END OF IT_ITEM .

DATA: IT_ITEM2 LIKE IT_ITEM OCCURS 0 WITH HEADER LINE .
DATA: BEGIN OF IT_DEL OCCURS 0 ,
        MATNR LIKE MARA-MATNR ,
        WERKS LIKE MARC-WERKS ,
      END OF IT_DEL .

DATA: BEGIN OF ITAB_STKO OCCURS 0,
        STLNR LIKE STKO-STLNR,
        STLAL LIKE STKO-STLAL,
        STLST LIKE STKO-STLST,
        LKENZ LIKE STKO-LKENZ,
        DATUV LIKE STKO-DATUV,
     END OF ITAB_STKO.
* BDCDATA
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
* BAPI DATA STRUCTURE
DATA: EX_HEADDATA       LIKE BAPIMATHEAD,
      EX_PLANTDATA      LIKE BAPI_MARC,
      EX_PLANTDATAX     LIKE BAPI_MARCX,
      EX_CLIENTDATA     LIKE BAPI_MARA,
      EX_CLIENTDATAX    LIKE BAPI_MARAX,
      IM_RETURN         LIKE  BAPIRET2.

DATA: G_OK TYPE I,         "SUCCESS
      G_NO TYPE I.         "FAIL

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_WERKS FOR MAST-WERKS OBLIGATORY NO INTERVALS.
SELECT-OPTIONS: S_AUFNR FOR AFKO-AUFNR .
SELECT-OPTIONS: S_MATNR FOR AFKO-PLNBEZ .
SELECT-OPTIONS: S_GSTRI FOR AFKO-GSTRI.
SELECTION-SCREEN END OF BLOCK BLK1.


*---------------------------------------------------------------------*
*        INITIALIZATION                                               *
*---------------------------------------------------------------------*
INITIALIZATION.


*---------------------------------------------------------------------*
*        START-OF-SELECTION                                           *
*---------------------------------------------------------------------*
START-OF-SELECTION.
* 取需要拷贝的工单
  PERFORM FRM_GET_ORDER.
  IF NOT IT_DEL[] IS INITIAL.
    PERFORM FRM_DEL_COSTBOM.
  ENDIF.
  IF NOT IT_ITEM2[] IS INITIAL.
    PERFORM FRM_CHANGE_MAT_STATUS.
  ENDIF.
  PERFORM FRM_COPY_COSTBOM.
*  PERFORM FRM_BAPI_CS01.
  IF NOT IT_ITEM2[] IS INITIAL.
    PERFORM FRM_RETURN_MAT_STATUS.
  ENDIF.
*---------------------------------------------------------------------*
*        END-OF-SELECTION                                             *
*---------------------------------------------------------------------*
END-OF-SELECTION.
* 输出记日志到屏幕
  PERFORM FRM_WRITE_LOG.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_ORDER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GET_ORDER .
  DATA: BEGIN OF IT_TEMP OCCURS 0,
          MATNR LIKE MARA-MATNR ,
          WERKS LIKE MARC-WERKS ,
        END OF IT_TEMP .
  DATA: LV_KZKFG LIKE MARA-KZKFG . "可配置物料
  DATA: R_PAIS TYPE RANGE OF JEST-STAT,
        R_PAIS_STAT LIKE LINE OF R_PAIS.
  DATA: R_PAIS2 TYPE RANGE OF JEST-STAT,
        R_PAIS2_STAT LIKE LINE OF R_PAIS2.
  DATA: R_PAIS3 TYPE RANGE OF AUFK-AUART,
        R_PAIS3_AUART LIKE LINE OF R_PAIS3.
  DATA: BEGIN OF GT_JEST OCCURS 0.
  DATA: OBJNR LIKE JEST-OBJNR,
        STAT  LIKE JEST-STAT,
        INACT LIKE JEST-INACT.
  DATA END OF GT_JEST.
  DATA: LV_LINE LIKE BSVX-STTXT .
  DATA: LV_MSTAE LIKE MARA-MSTAE.
  DATA: LV_LVORM LIKE MARA-LVORM.

*
** 工单状态range定义
*  CLEAR: R_PAIS_STAT ,R_PAIS2_STAT  .
*  R_PAIS_STAT-SIGN   = 'I'.
*  R_PAIS_STAT-OPTION = 'EQ'.
*  R_PAIS_STAT-LOW    = 'I0012'.
*  APPEND R_PAIS_STAT TO R_PAIS.
*
*  R_PAIS_STAT-SIGN   = 'I'.
*  R_PAIS_STAT-OPTION = 'EQ'.
*  R_PAIS_STAT-LOW    = 'I0321'.
*  APPEND R_PAIS_STAT TO R_PAIS.
*
*  R_PAIS2_STAT-SIGN   = 'I'.
*  R_PAIS2_STAT-OPTION = 'EQ'.
*  R_PAIS2_STAT-LOW    = 'I0074'.
*  APPEND R_PAIS2_STAT TO R_PAIS2.
*
*  R_PAIS2_STAT-SIGN   = 'I'.
*  R_PAIS2_STAT-OPTION = 'EQ'.
*  R_PAIS2_STAT-LOW    = 'I0321'.
*  APPEND R_PAIS2_STAT TO R_PAIS2.
* 工单类型定义
  CLEAR R_PAIS3_AUART.
  R_PAIS3_AUART-SIGN   = 'I'.
  R_PAIS3_AUART-OPTION = 'EQ'.
  R_PAIS3_AUART-LOW    = 'PP01'.
  APPEND R_PAIS3_AUART TO R_PAIS3.
  R_PAIS3_AUART-SIGN   = 'I'.
  R_PAIS3_AUART-OPTION = 'EQ'.
  R_PAIS3_AUART-LOW    = 'ZPP1'.
  APPEND R_PAIS3_AUART TO R_PAIS3.
  R_PAIS3_AUART-SIGN   = 'I'.
  R_PAIS3_AUART-OPTION = 'EQ'.
  R_PAIS3_AUART-LOW    = 'ZPP3'.
  APPEND R_PAIS3_AUART TO R_PAIS3.
  R_PAIS3_AUART-SIGN   = 'I'.
  R_PAIS3_AUART-OPTION = 'EQ'.
  R_PAIS3_AUART-LOW    = 'ZPP4'.
  APPEND R_PAIS3_AUART TO R_PAIS3.
  R_PAIS3_AUART-SIGN   = 'I'.
  R_PAIS3_AUART-OPTION = 'EQ'.
  R_PAIS3_AUART-LOW    = 'ZPP5'.
  APPEND R_PAIS3_AUART TO R_PAIS3.


  SELECT A~AUFNR A~GSTRI A~GSUZI A~RSNUM A~GAMNG C~MATNR B~WERKS B~OBJNR
    INTO CORRESPONDING FIELDS OF TABLE IT_TAB
    FROM AFKO AS A
    INNER JOIN AUFK AS B ON A~AUFNR = B~AUFNR
    INNER JOIN AFPO AS C ON A~AUFNR = C~AUFNR
*    INNER JOIN JEST AS C ON B~OBJNR = C~OBJNR
    WHERE A~AUFNR IN S_AUFNR
      AND A~GSTRI IN S_GSTRI
      AND C~MATNR IN S_MATNR
      AND B~WERKS IN S_WERKS
      AND B~AUART IN R_PAIS3
      AND B~LOEKZ NE 'X'.

  LOOP AT IT_TAB.
    CLEAR LV_LINE.
    CALL FUNCTION 'STATUS_TEXT_EDIT'
      EXPORTING
*   CLIENT                  = SY-MANDT
*   _USER_STAT           = ' '
        OBJNR                   = IT_TAB-OBJNR
        ONLY_ACTIVE             = 'X'
        SPRAS                   = '1'
*   BYPASS_BUFFER           = ' '
     IMPORTING
*   ANW_STAT_EXISTING       =
*   E_STSMA                 =
       LINE                    =  LV_LINE
*   USER_LINE               =
*   STONR                   =
     EXCEPTIONS
       OBJECT_NOT_FOUND        = 1
       OTHERS                  = 2
              .
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ELSE.
      IF ( LV_LINE CS 'DLV' AND LV_LINE CS 'GMPS' ) OR
         ( LV_LINE CS 'PDLV' AND LV_LINE CS 'GMPS' ).
        IT_TEMP-MATNR = IT_TAB-MATNR .
        IT_TEMP-WERKS = IT_TAB-WERKS .
        APPEND IT_TEMP.
        CLEAR : IT_TAB,IT_TEMP .
      ELSE.
        DELETE IT_TAB.
      ENDIF.
    ENDIF.

    CLEAR IT_TAB.
  ENDLOOP.

*  LOOP AT IT_TAB.
*    IT_TEMP-MATNR = IT_TAB-PLNBEZ .
*    IT_TEMP-WERKS = IT_TAB-WERKS .
*    APPEND IT_TEMP.
*    CLEAR : IT_TAB,IT_TEMP .
*  ENDLOOP.
* 删除重复的bom
* 没有激活的无效BOM
*  DATA: LV_TIX LIKE SY-TABIX .
  SORT IT_TEMP BY MATNR WERKS .
  DELETE ADJACENT DUPLICATES FROM IT_TEMP COMPARING MATNR WERKS.
*  LOOP AT IT_TEMP .
*    LV_TIX = SY-TABIX.
*    CLEAR ITAB_STKO.
*    REFRESH ITAB_STKO.
*    CLEAR MAST.
*    SELECT SINGLE * FROM MAST WHERE MATNR EQ IT_TEMP-MATNR
*                                AND WERKS EQ IT_TEMP-WERKS.
*    IF SY-SUBRC EQ 0.
*      SELECT STLNR STLAL STLST LKENZ DATUV
*        FROM STKO
*        INTO CORRESPONDING FIELDS OF TABLE ITAB_STKO
*       WHERE STLNR = MAST-STLNR
*         AND STLAL = MAST-STLAL
*         AND DATUV <= SY-DATUM
*        ORDER BY DATUV DESCENDING.
*
*      READ TABLE ITAB_STKO INDEX 1.
*
*      IF ITAB_STKO-STLST <> '01' OR ITAB_STKO-LKENZ <> SPACE.
*        "BOM未激活或者已经删除
*        DELETE IT_TEMP INDEX LV_TIX.
*      ENDIF.
*    ENDIF.

*  ENDLOOP.
* 可配置的bom不需要
  LOOP AT IT_TEMP.
    SELECT SINGLE KZKFG MSTAE LVORM
      INTO (LV_KZKFG,LV_MSTAE,LV_LVORM)
      FROM MARA
      WHERE MATNR EQ IT_TEMP-MATNR.
    IF LV_KZKFG EQ 'X' OR LV_MSTAE NE ' ' OR LV_LVORM NE ' '.
      DELETE IT_TEMP .
    ELSE.
      SELECT SINGLE * FROM MAST WHERE WERKS EQ IT_TEMP-WERKS
                                  AND MATNR EQ IT_TEMP-MATNR
                                  AND STLAN EQ '6'.
      IF SY-SUBRC EQ 0.
        APPEND IT_TEMP TO IT_DEL.
      ENDIF.
    ENDIF.
    CLEAR MARC.
    SELECT SINGLE * FROM MARC WHERE MATNR EQ IT_TEMP-MATNR
                               AND WERKS EQ IT_TEMP-WERKS.
    IF MARC-MMSTA NE ' ' OR MARC-LVORM NE ' '.
      DELETE IT_TEMP .
    ENDIF.

    CLEAR IT_TEMP.

  ENDLOOP.

  LOOP AT IT_TAB.
    MOVE-CORRESPONDING IT_TAB TO IT_SORT.
    APPEND IT_SORT.
    CLEAR: IT_TAB,IT_SORT.
  ENDLOOP.

  SORT IT_SORT BY GSTRI DESCENDING GSUZI DESCENDING .

  LOOP AT IT_TEMP.
    READ TABLE IT_SORT WITH KEY MATNR = IT_TEMP-MATNR
                                WERKS = IT_TEMP-WERKS.
    IF SY-SUBRC EQ 0.
      IT_TAB2-AUFNR = IT_SORT-AUFNR .
      IT_TAB2-RSNUM = IT_SORT-RSNUM .
      IT_TAB2-MATNR = IT_SORT-MATNR.
      IT_TAB2-WERKS = IT_SORT-WERKS .
      IT_TAB2-GAMNG = IT_SORT-GAMNG .
      APPEND IT_TAB2.
      CLEAR IT_TAB2.
    ENDIF.
    CLEAR:IT_SORT, IT_TEMP.
  ENDLOOP.

  LOOP AT IT_TAB2.

    SELECT A~RSNUM A~MATNR A~BDMNG A~MEINS A~POSTP B~WERKS B~LVORM B~MMSTA C~MSTAE
     APPENDING CORRESPONDING FIELDS OF TABLE IT_ITEM
      FROM RESB AS A
      INNER JOIN MARC AS B ON A~MATNR = B~MATNR
                          AND A~WERKS = B~WERKS
      INNER JOIN MARA AS C ON A~MATNR = C~MATNR
     WHERE A~RSNUM EQ IT_TAB2-RSNUM
       AND A~WERKS EQ IT_TAB2-WERKS
       AND A~BDMNG NE ' '
       AND C~MTART NE 'LEER'.                               "剔除69
*       AND B~LVORM NE 'X'
*       AND B~MMSTA EQ ' '
*       AND C~MSTAE EQ ' '.

    CLEAR IT_TAB2.
  ENDLOOP.

  LOOP AT IT_ITEM .
    IF IT_ITEM-LVORM EQ 'X' OR IT_ITEM-MMSTA NE ' ' OR IT_ITEM-MSTAE NE ' '.
      APPEND IT_ITEM TO IT_ITEM2 .
    ENDIF.
    CLEAR IT_ITEM.
  ENDLOOP.

 


ENDFORM.                    " FRM_GET_ORDER
*&---------------------------------------------------------------------*
*&      Form  FRM_COPY_COSTBOM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_COPY_COSTBOM .
  DATA:L_OPT LIKE CTU_PARAMS.
  DATA:   L_MSTRING(200)  TYPE C.
  DATA:   MESSAGE1(200)  TYPE C,
          MESSAGE2(200)  TYPE C.
  DATA: LV_FLAG(1).
  DATA: LV_HEDQTY(13).
  DATA: LV_ITEMQTY(13).


  L_OPT-DISMODE = 'N'.
  L_OPT-UPDMODE = 'S'.
  L_OPT-CATTMODE = ''.
  L_OPT-DEFSIZE = 'X'.
*  L_OPT-NOBINPT = 'X'.

  LOOP AT IT_TAB2.

    CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
      EXPORTING
        INPUT  = IT_TAB2-MATNR
      IMPORTING
        OUTPUT = IT_TAB2-MATNR.

    LV_HEDQTY = IT_TAB2-GAMNG.

    PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0100'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM BDC_FIELD       USING 'RC29N-MATNR'
                                  IT_TAB2-MATNR.
    PERFORM BDC_FIELD       USING 'RC29N-WERKS'
                                  IT_TAB2-WERKS.
    PERFORM BDC_FIELD       USING 'RC29N-STLAN'
                                  '6'.
*    PERFORM BDC_FIELD       USING 'RC29N-AENNR'
*                                  ''.

    PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0110'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '/00'.
    PERFORM BDC_FIELD       USING 'RC29K-BMENG'
                                   LV_HEDQTY.

    PERFORM BDC_FIELD       USING 'RC29K-STLST'
                                    '1'.

    PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0111'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '/00'.


    LOOP AT IT_ITEM WHERE RSNUM = IT_TAB2-RSNUM.
      LV_ITEMQTY = IT_ITEM-BDMNG.


      CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
        EXPORTING
          INPUT  = IT_ITEM-MATNR
        IMPORTING
          OUTPUT = IT_ITEM-MATNR.

      IF LV_FLAG = ' '.

        LV_FLAG = 'X'.

        PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0140'.
        PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                      '/00'.
        PERFORM BDC_FIELD       USING 'RC29P-IDNRK(01)'
                                       IT_ITEM-MATNR.
        PERFORM BDC_FIELD       USING 'RC29P-MENGE(01)'
                                      LV_ITEMQTY.
        PERFORM BDC_FIELD       USING 'RC29P-POSTP(01)'
                                      IT_ITEM-POSTP.

        IF IT_ITEM-POSTP EQ 'L'.

          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0130'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.

          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0131'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.

        ELSEIF IT_ITEM-POSTP EQ 'N'.
          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0130'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.

          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0131'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.

          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0133'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.
          PERFORM BDC_FIELD       USING  'RC29P-EKORG' ' '.


        ENDIF.

        PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0140'.
        PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '=FCNP'.
      ELSE.

        PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0140'.
        PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                      '/00'.
        PERFORM BDC_FIELD       USING 'RC29P-IDNRK(02)'
                                       IT_ITEM-MATNR.
        PERFORM BDC_FIELD       USING 'RC29P-MENGE(02)'
                                      LV_ITEMQTY.
        PERFORM BDC_FIELD       USING 'RC29P-POSTP(02)'
                                      IT_ITEM-POSTP.

        IF IT_ITEM-POSTP EQ 'L'.

          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0130'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.

          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0131'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.


        ELSEIF IT_ITEM-POSTP EQ 'N'.
          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0130'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.

          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0131'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.


          PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0133'.
          PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '/00'.
          PERFORM BDC_FIELD       USING  'RC29P-EKORG' ' '.


        ENDIF.

        PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0140'.
        PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                        '=FCNP'.


      ENDIF.

      CLEAR IT_ITEM.
    ENDLOOP.

    PERFORM BDC_DYNPRO      USING 'SAPLCSDI' '0140'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=FCBU'.

*CALL CS01 CREATE COST BOM
    CALL TRANSACTION 'CS01' USING BDCDATA
                            OPTIONS FROM L_OPT
                            MESSAGES INTO MESSTAB.

* BDC SUCCESS
    IF SY-SUBRC = 0.
      IT_TAB2-FLAG = '0'.
      IT_TAB2-MSG = '创建成本BOM成功'.
      ADD 1 TO G_OK.
* BDC ERROR
    ELSE.
      LOOP AT MESSTAB WHERE MSGTYP = 'S'
                         OR MSGTYP = 'I'
                         OR MSGTYP = 'E'
                         OR MSGTYP = 'A'.
      ENDLOOP.
      IF NOT MESSTAB IS INITIAL.
        CLEAR: MESSAGE1,
               MESSAGE2.
        LOOP AT MESSTAB.
          SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
                                    AND   ARBGB = MESSTAB-MSGID
                                    AND   MSGNR = MESSTAB-MSGNR.
          IF SY-SUBRC = 0.
            L_MSTRING = T100-TEXT.
            IF L_MSTRING CS '&1'.
              REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
              REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
              REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
              REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
            ELSE.
              REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.
              REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.
              REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.
              REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.
            ENDIF.
            CONDENSE L_MSTRING.
            CONCATENATE MESSAGE1 L_MSTRING ';' INTO MESSAGE1.
          ELSE.
            CONCATENATE MESSAGE2 MESSTAB ';' INTO MESSAGE2.
          ENDIF.
          CLEAR: MESSTAB,
                 L_MSTRING.
        ENDLOOP.
        CONCATENATE MESSAGE1 MESSAGE2 INTO IT_TAB2-MSG.
        IT_TAB2-FLAG = '1'.
        ADD 1 TO G_NO.
      ENDIF.

    ENDIF.

    MODIFY IT_TAB2.

    CLEAR:LV_FLAG,IT_TAB2,LV_HEDQTY,LV_ITEMQTY.

    REFRESH BDCDATA.CLEAR BDCDATA.
    REFRESH MESSTAB.CLEAR MESSTAB.
  ENDLOOP.

 

 

ENDFORM.                    " FRM_COPY_COSTBOM
*&---------------------------------------------------------------------*
*&      Form  FRM_WRITE_LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_WRITE_LOG .

*BDC RESULT
  FORMAT COLOR 5 ON.
  WRITE:/,(40) '运行结果' CENTERED.
  FORMAT COLOR OFF.

  FORMAT COLOR 6 ON.
  WRITE:/ '创建成本bom成功:',G_OK,'条'.
  FORMAT COLOR OFF.

  SKIP.

  FORMAT COLOR 6 ON.
  WRITE:/ '创建成本bom失败:',G_NO,'条'.
  FORMAT COLOR OFF.

  SORT IT_TAB2 BY FLAG .
  LOOP AT IT_TAB2 .

    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        INPUT        = IT_TAB2-MATNR
      IMPORTING
        OUTPUT       = IT_TAB2-MATNR
      EXCEPTIONS
        LENGTH_ERROR = 1
        OTHERS       = 2.
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


    WRITE:/1(10) IT_TAB2-AUFNR,
            (10) IT_TAB2-RSNUM,
            (18) IT_TAB2-MATNR,
            (04) IT_TAB2-WERKS,
           (100) IT_TAB2-MSG.

  ENDLOOP.

ENDFORM.                    " FRM_WRITE_LOG

*&---------------------------------------------------------------------*
*&      Form  bdc_dynpro
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0644   text
*      -->P_0645   text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA.
ENDFORM.                    "BDC_DYNPRO

*&---------------------------------------------------------------------*
*&      Form  bdc_field
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0639   text
*      -->P_0640   text
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
**  IF FVAL <> NODATA.
  CLEAR BDCDATA.
  BDCDATA-FNAM = FNAM.
  BDCDATA-FVAL = FVAL.
  APPEND BDCDATA.
**  ENDIF.
ENDFORM.                    "BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  FRM_CHANGE_MAT_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CHANGE_MAT_STATUS .

  LOOP AT IT_ITEM2.
    CLEAR: EX_HEADDATA,EX_CLIENTDATA,EX_CLIENTDATAX, EX_PLANTDATA, EX_PLANTDATAX, IM_RETURN.

    MOVE: IT_ITEM2-MATNR TO EX_HEADDATA-MATERIAL,
          'X'            TO EX_HEADDATA-BASIC_VIEW,
          'X'            TO EX_HEADDATA-MRP_VIEW.

    IF IT_ITEM2-LVORM EQ 'X'.
      MOVE: ' ' TO EX_CLIENTDATA-DEL_FLAG.
      MOVE: 'X' TO EX_CLIENTDATAX-DEL_FLAG.
    ENDIF.

    IF IT_ITEM2-MSTAE NE ' '.
      MOVE: ' ' TO EX_CLIENTDATA-PUR_STATUS.
      MOVE: 'X' TO EX_CLIENTDATAX-PUR_STATUS.
    ENDIF.

    IF IT_ITEM2-MMSTA NE ' '.
      MOVE: IT_ITEM2-WERKS     TO EX_PLANTDATA-PLANT,
            ' '     TO EX_PLANTDATA-PUR_STATUS.

      MOVE: IT_ITEM2-WERKS TO EX_PLANTDATAX-PLANT,
            'X'           TO EX_PLANTDATAX-PUR_STATUS.
    ENDIF.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        HEADDATA    = EX_HEADDATA
        CLIENTDATA  = EX_CLIENTDATA
        CLIENTDATAX = EX_CLIENTDATAX
        PLANTDATA   = EX_PLANTDATA
        PLANTDATAX  = EX_PLANTDATAX
      IMPORTING
        RETURN      = IM_RETURN.


    IF IM_RETURN-TYPE = 'E'.

    ELSE.
      COMMIT WORK AND WAIT.
      WAIT UP TO 5 SECONDS.

    ENDIF.

  ENDLOOP.

 

ENDFORM.                    " FRM_CHANGE_MAT_STATUS
*&---------------------------------------------------------------------*
*&      Form  FRM_RETURN_MAT_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_RETURN_MAT_STATUS .
  LOOP AT IT_ITEM2.
    CLEAR: EX_HEADDATA,EX_CLIENTDATA,EX_CLIENTDATAX, EX_PLANTDATA, EX_PLANTDATAX, IM_RETURN.

    MOVE: IT_ITEM2-MATNR TO EX_HEADDATA-MATERIAL,
          'X'            TO EX_HEADDATA-BASIC_VIEW,
          'X'            TO EX_HEADDATA-MRP_VIEW.

    IF IT_ITEM2-LVORM EQ 'X'.
      MOVE: 'X' TO EX_CLIENTDATA-DEL_FLAG.
      MOVE: 'X' TO EX_CLIENTDATAX-DEL_FLAG.
    ENDIF.

    IF IT_ITEM2-MMSTA NE ' '.
      MOVE: IT_ITEM2-MMSTA TO EX_CLIENTDATA-PUR_STATUS.
      MOVE: 'X' TO EX_CLIENTDATAX-PUR_STATUS.
    ENDIF.

    IF IT_ITEM2-MMSTA NE ' '.
      MOVE: IT_ITEM2-WERKS     TO EX_PLANTDATA-PLANT,
            IT_ITEM2-MMSTA     TO EX_PLANTDATA-PUR_STATUS.

      MOVE: IT_ITEM2-WERKS TO EX_PLANTDATAX-PLANT,
            'X'           TO EX_PLANTDATAX-PUR_STATUS.
    ENDIF.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        HEADDATA    = EX_HEADDATA
        CLIENTDATA  = EX_CLIENTDATA
        CLIENTDATAX = EX_CLIENTDATAX
        PLANTDATA   = EX_PLANTDATA
        PLANTDATAX  = EX_PLANTDATAX
      IMPORTING
        RETURN      = IM_RETURN.


    IF IM_RETURN-TYPE = 'E'.

    ELSE.
      COMMIT WORK AND WAIT.

    ENDIF.

  ENDLOOP.
ENDFORM.                    " FRM_RETURN_MAT_STATUS
*&---------------------------------------------------------------------*
*&      Form  FRM_DEL_COSTBOM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DEL_COSTBOM .
  DATA: LV_TEMP LIKE CAPIFLAG-FLWARNING.

  LOOP AT IT_DEL.

    CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
      EXPORTING
        INPUT  = IT_DEL-MATNR
      IMPORTING
        OUTPUT = IT_DEL-MATNR.

    CALL FUNCTION 'CSAP_MAT_BOM_DELETE'
      EXPORTING
        MATERIAL   = IT_DEL-MATNR
        PLANT      = IT_DEL-WERKS
        BOM_USAGE  = '6'
      IMPORTING
        FL_WARNING = LV_TEMP
      EXCEPTIONS
        ERROR      = 1
        OTHERS     = 2.

    IF SY-SUBRC EQ 0.
      COMMIT WORK AND WAIT.
      WAIT UP TO 3 SECONDS.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " FRM_DEL_COSTBOM
*&---------------------------------------------------------------------*
*&      Form  frm_bapi_cs01
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_BAPI_CS01 .
  DATA: ES_MAST LIKE BAPIBOMMST .
  DATA: ES_STZU LIKE BAPIBOMSTZ .
  DATA: IM_RET LIKE BAPIRET2 .
  DATA: IS_STKO LIKE BAPIBOMSTK OCCURS 0 WITH HEADER LINE.
  DATA: IS_STPO LIKE BAPIBOMSTP OCCURS 0 WITH HEADER LINE.
  DATA: IS_STAS LIKE BAPIBOMSTA OCCURS 0 WITH HEADER LINE.
*
  DATA: LV_ITEM TYPE I.

  LOOP AT IT_TAB2.

*    CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
*      EXPORTING
*        INPUT  = IT_TAB2-MATNR
*      IMPORTING
*        OUTPUT = IT_TAB2-MATNR.


    REFRESH IS_STPO . CLEAR ES_MAST . CLEAR IM_RET. CLEAR IS_STKO.
**** BAPI 参数 BOM MAST表****************************
    MOVE : '009' TO ES_MAST-OPERATION ,
           IT_TAB2-MATNR TO ES_MAST-MATERIAL,
           IT_TAB2-WERKS TO ES_MAST-PLANT,
           SY-DATUM TO ES_MAST-CREATE_DAT,
*           '01' TO ES_MAST-ALT_BOM,
           '6' TO ES_MAST-BOM_USAGE.

    MOVE :
           '009' TO IS_STKO-OPERATION,
           'M' TO IS_STKO-BOM_CATEGO,
*           '01' TO IS_STKO-ALT_BOM,
           SY-DATUM TO IS_STKO-VALID_FROM,
           IT_TAB2-GAMNG TO IS_STKO-BASE_QTY.
    APPEND IS_STKO.
    CLEAR IS_STKO.

*    LOOP AT IT_ITEM WHERE RSNUM = IT_TAB2-RSNUM.
*
**      CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
**        EXPORTING
**          INPUT  = IT_ITEM-MATNR
**        IMPORTING
**          OUTPUT = IT_ITEM-MATNR.
*
*      MOVE:
*             '009' TO IS_STPO-OPERATION,
**             IT_ITEM-MEINS TO IS_STPO-UNCOMP,
*             IT_ITEM-BDMNG TO IS_STPO-COMPON_QTY,
**              '1' TO IS_STPO-COMPON_QTY,
*             IT_ITEM-MATNR TO IS_STPO-COMPONENT,
*             IT_ITEM-POSTP TO IS_STPO-ITEM_CAT.
*
*
*      APPEND IS_STPO.
*      CLEAR IS_STPO.
*
*    ENDLOOP.

    MOVE:
           '009' TO IS_STPO-OPERATION,
*             IT_ITEM-MEINS TO IS_STPO-UNCOMP,
           '1' TO IS_STPO-COMPON_QTY,
           '000000000000002009' TO IS_STPO-COMPONENT,
           'N' TO IS_STPO-ITEM_CAT.
*             IT_ITEM-aennr TO IS_STPO-change_no,
*             LV_ITEM TO IS_STPO-BOM_ITM_NO.

    APPEND IS_STPO.
*
*      MOVE:
*             '009' TO IS_STPO-OPERATION,
**             IT_ITEM-MEINS TO IS_STPO-UNCOMP,
*             '1' TO IS_STPO-COMPON_QTY,
*             '000000000031020744' TO IS_STPO-COMPONENT,
*             'L' TO IS_STPO-ITEM_CAT.
**             IT_ITEM-aennr TO IS_STPO-change_no,
**             LV_ITEM TO IS_STPO-BOM_ITM_NO.
*
*      APPEND IS_STPO.

    CALL FUNCTION 'BAPI_BOM_UPLOAD_SAVE'
      EXPORTING
        IS_MAST   = ES_MAST
        IS_STZU   = ES_STZU
      IMPORTING
        ES_RETURN = IM_RET
      TABLES
        IT_STKO   = IS_STKO
        IT_STPO   = IS_STPO
        IT_STAS   = IS_STAS.

    COMMIT WORK.
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ELSE.

      COMMIT WORK AND WAIT .

    ENDIF.
    CLEAR IT_TAB2.

  ENDLOOP.

ENDFORM.                    " frm_bapi_cs01



分享到:
评论
1 楼 maycolour 2011-03-31  
唉,居然在系统里存在一个同样名字和代码类似的程序~~~~~~~~~~~时间上还居然都差不多~~~~~~

相关推荐

    SAP BOM维护

    2. 工具:利用SAP提供的工具,如SE16(数据库表浏览器)、ME54N(采购订单创建)等,可以更便捷地查看和维护BOM数据。此外,第三方工具或增强如SAP Leonardo可以提升BOM的分析和优化能力。 五、替代BOM测试 在实际...

    SAP复杂装配下的BOM管理(SAPCAMS-BOMM).pptx

    在这一模块,学员将接触到BOM管理的其他方面,可能包括特殊场景的应用、数据维护和权限控制等。同时,会强调如何利用SAP的在线帮助系统解决问题,提高工作效率。 **课程目标** 完成此课程后,学员应能够: 1. ...

    SAP-17LSMW使用Standard Batch导入BOM.docx

    BOM(物料清单)是生产计划和控制中的一种重要文件,通过使用 SAP-17LSMW 和 Standard Batch,可以快速导入 BOM 数据到 SAP 系统中。 二、创建批导名 在使用 SAP-17LSMW 导入 BOM 之前,需要创建一个批导名。批导名...

    2001.BOM主数据表关系.pdf

    在SAP中,BOM数据的管理和维护通过特定的表和关系来实现,本文将详细介绍SAP BOM主数据表关系,其内容主要来自于名为“2001.BOM主数据表关系.pdf”的文档,并且是“Tiger”所著。 首先,我们要了解SAP中BOM相关的几...

    SAP CEWB、CS20操作手册

    虽然给定的部分内容中没有明确提及CS20批量新增BOM的具体操作步骤,但基于CEWB的相关操作经验和SAP系统的通用逻辑,我们可以推断出以下关键步骤: **3.1 CS20批量新增BOM操作步骤** **步骤解析:** - **步骤1**: ...

    SAP物料主数据BOM数据管理制度V1.pdf

    本文档介绍了SAP物料主数据BOM数据管理制度的细则,旨在规范SAP系统中的物料主数据和物料清单(BOM)的维护工作。该制度对数据的收集、维护、审核和更新等方面进行了明确的规定,确保SAP系统的正常运转。 一、数据...

    ENOVIA X-BOM for SAP

    标题“ENOVIA X-BOM for SAP”指的是...在实际应用中,ENOVIA X-BOM for SAP可以帮助企业优化其产品数据管理流程,使企业能够更加高效地在ENOVIA和SAP系统之间同步、维护和管理BOM数据,提高制造过程的精确性和协调性。

    SAP B1_DTW导入BOM

    通过以上步骤,可以有效地解决在 SAP B1 中通过 DTW 导入 BOM 清单时遇到的常见问题,从而提高数据导入的准确性和效率。此外,在日常维护过程中,建议定期检查 BOM 数据的准确性,以避免因数据错误而导致的生产问题...

    SAP Query 和 SQVI Quick View

    理解SAP Query和SQVI的区别与应用场景,以及如何有效地维护和使用它们,是提升SAP系统使用效率的关键。通过熟练掌握这些技能,顾问能够帮助用户更高效地获取和分析企业数据,从而支持企业的决策过程。

    sap+pp+顾问认证考试试题及资料.doc

    MRP配置文件和预测配置文件可用于优化物料主数据的维护,同时,物料主数据可以通过删除或归档进行重新组织。 3. 单位度量:在物料主数据中,基础单位、生产单位、订单单位等不同单位度量会影响处理过程。材料状态...

    ECN数据维护流程介绍模板.doc

    在物料BOM维护流程中,用户需要遵循一定的操作规程,包括创建物料BOM的规程、修改物料BOM的规程、删除物料BOM的规程等。这些规程都是为了确保物料BOM的准确性和一致性。 4. ECN数据维护流程的实现 ECN数据维护流程...

    SAP SHD0 屏幕变式

    业务部门希望实现两种不同的BOM清单(物料清单)查询方式:一般查询人员只能查看特定用途(例如用途1)的BOM清单,而BOM维护员则可以查看和维护所有用途的BOM清单。 **需求分析:** 此需求涉及到对CS03(BOM显示...

    SAP-PS模块快速指南及学习基本知识

    该模块不仅帮助用户管理项目的整个生命周期,从创建、规划、执行直至项目结束,而且与其他SAP模块(如物流、物料管理、销售与分销、工厂维护和生产计划等)紧密集成,以实现高效协同工作。 #### 二、项目管理关键...

    SAP tables

    每个SAP模块的表格都是为了支持该模块的具体功能,通过这些表格,用户可以查询、输入、修改和删除数据,从而实现业务流程的自动化和高效化。在SE11中,用户可以直接访问和管理这些数据库表格,进行视图创建、数据...

    sap+pp+顾问认证考试试题及资料

    材料主数据的重新组织,包括删除和归档,也是顾问需要掌握的操作。 4. 单位衡量:基础单位、生产单位、订单单位等不同单位对物料处理有影响,选择合适的单位可以优化生产流程。材料状态用于追踪物料的状态,可以在...

    SAP PP 顾问面试试题及资料

    BOM的有效性和适用范围是指其在特定条件下的有效性。 **4.7 BOM项类别及其规定** 不同的BOM项具有不同的功能,如原材料、半成品等。 **4.8 子项(Sub-Item)** 子项是组成主项的组成部分。 **4.9 特殊情况下的...

    SAP S4 HANA BP后台配置及前台操作详解.pdf

    在传统的SAP系统中,客户和供应商通常是分开处理的,而BP概念的引入使得能够在一个统一的数据模型中管理这些业务实体,从而提高数据的一致性和可维护性。 **1.2 业务伙伴角色或 BP 角色** BP角色是指与业务伙伴...

    SAP屠夫作品汇总

    2建立BOM 543 3.外包给屠夫宰 545 4.使用外包工序 549 关于联产品工单成本怎么结算?你整一个Allocation structure, SAPhelp. Create Allocation Structure 551 5工单 552 Material Ledger 物料分类账详解 552 一.ML...

    Create_Material_BOM

    综上所述,创建物料清单(Material BOM)不仅涉及物料号的定义和编码规则,还需要熟悉SAP系统中的事务代码,并掌握创建物料的具体步骤。通过这些步骤,可以有效地管理和维护物料信息,从而支持企业的生产计划和供应链...

    SAP PP 工艺路线

    - **创建与维护**:通过SAP系统的界面创建和修改工艺路线,包括添加工序、设置参数等。 - **检查与验证**:确保工艺路线的准确性和完整性,通过系统工具进行检查。 - **更改与删除**:支持工艺路线的更新与删除操作...

Global site tag (gtag.js) - Google Analytics