SAP PP ECN CSAP_MAT_BOM_MAINTAIN

news2024/12/22 22:40:11

刚开始的时候ECN总是加不上,

参考kimi给出的案例

点击链接查看和 Kimi 智能助手的对话 https://kimi.moonshot.cn/share/cth1ipmqvl7f04qkggdg

效果 加上了

FUNCTION ZPBOM_PLM2SAP.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     VALUE(OUTPUT) TYPE  ZSM8_SALESORDER_CREATE_OUTPUT
*"  TABLES
*"      INPUT_PBOM STRUCTURE  ZPBOM
*"      OUTPUT_MESSAGE STRUCTURE  ZMAT_MESSAGE
*"----------------------------------------------------------------------
*  新增 input_bom
*  修改 input_bom
*  删除 ECN  日期

  TABLES: MAST,STPO,STKO,STPU.
  DATA: TEMP_MAT     TYPE MATNR,
        TEMP_WERKS   TYPE WERKS_D,
        TEMP_STLNR   LIKE MAST-STLNR, "物料单号(bom号)
        RETURN(220)  TYPE C,
        ISFIND(1)    TYPE C,
        FROMDATE(10) TYPE C.
  DATA:TEMP_MATNR TYPE MATNR.
  DATA: BEGIN OF ZLOG,
          MATNR             TYPE MATNR,
          WERKS             TYPE WERKS_D,
          INTERFACENAME(60) TYPE C,
          LOGDATE           TYPE DATUM,
          LOGTIME           TYPE UZEIT,
          MAKTX             TYPE MAKTX,
          MEINS             TYPE MEINS,
          MBRSH             TYPE MBRSH,
          LVORM             TYPE LVORM,
          MTART             TYPE MTART,
          SPART             TYPE SPART,
          MATKL             TYPE MATKL,
          BISMT             TYPE BISMT,
          LGFSB             TYPE LGFSB,
          EORIGINNO(40)     TYPE C,
          CREATER(20)       TYPE C,
          MESSAGETYPE(1)    TYPE C,
          MESSAGE(220)      TYPE C,
        END OF ZLOG.

  DATA: BEGIN OF SUBMATNR_COUNT,"用于记录在同一层级下相同子物料,相同数量,出现的次数。
          SUBMATNR TYPE MATNR,
          MENGE    TYPE KMPMG,
          COUNT    TYPE I,
        END OF SUBMATNR_COUNT.

  DATA:SAP_SUBMATNR_COUNT LIKE SUBMATNR_COUNT,
       PLM_SUBMATNR_COUNT LIKE SUBMATNR_COUNT.

  DATA: NO1 TYPE I,
        NO2 TYPE I.

  DATA:I_STKO LIKE STKO_API01.

  DATA:BEGIN OF GS_INPUTPBOM,
         MATNR   TYPE MATNR,
         WERKS   TYPE WERKS_D,
         IDNRK   TYPE IDNRK,
         KMPMG   TYPE KMPMG,
         XUHAO   TYPE I,
         MEINS   TYPE MEINS,
         SORTP   TYPE SORTP,
         LOGDATE TYPE DATUM,
         LOGTIME TYPE UZEIT,
       END OF GS_INPUTPBOM.

  DATA:GT_STPO_INPUT LIKE TABLE OF STPO_API03 WITH HEADER LINE.

  DATA: SAP_STPO LIKE TABLE OF STPO WITH HEADER LINE.
  DATA: PDATAV LIKE  CSAP_MBOM-DATUV.

*1. 根据父物料字段,对输入BOM表排序:
  SORT INPUT_PBOM BY STLAN WERKS MATNR IDNRK KMPMG.

*2.将plm的bom格式转化为SAP能处理的单层bom,并处理(行项目新建或修改和删除的处理)

  CLEAR TEMP_MAT.
  CLEAR TEMP_WERKS.
  I_STKO-BASE_QUAN = 1.
  I_STKO-BOM_STATUS = '01'.

  LOOP AT INPUT_PBOM.
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        INPUT  = INPUT_PBOM-MATNR
      IMPORTING
        OUTPUT = INPUT_PBOM-MATNR.

    TRANSLATE INPUT_PBOM-MATNR TO UPPER CASE.

*    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        INPUT  = INPUT_PBOM-IDNRK
      IMPORTING
        OUTPUT = INPUT_PBOM-IDNRK.

    TRANSLATE INPUT_PBOM-IDNRK TO UPPER CASE.

    CLEAR GS_INPUTPBOM.

*2.1   当从一个小bom切换到另一个小bom时的处理;
*2.1.1 可以是第一个bom的第一条记录,
*2.1.2 或者是另开始一个小bom数据
    IF ( TEMP_MAT <> INPUT_PBOM-MATNR OR TEMP_WERKS <> INPUT_PBOM-WERKS ).

      "2.1.1当是第一个bom的第一条数据时
      IF ( TEMP_MAT IS INITIAL ) AND ( TEMP_WERKS IS INITIAL ).
        TEMP_MAT = INPUT_PBOM-MATNR.
        TEMP_WERKS = INPUT_PBOM-WERKS.

        CLEAR PLM_SUBMATNR_COUNT.
        PLM_SUBMATNR_COUNT-SUBMATNR = INPUT_PBOM-IDNRK.
        PLM_SUBMATNR_COUNT-MENGE = INPUT_PBOM-KMPMG.
        PLM_SUBMATNR_COUNT-COUNT = PLM_SUBMATNR_COUNT-COUNT + 1.

        "保存传入的数据到zinputpbom透视表中,作为记录。
        GS_INPUTPBOM-MATNR = INPUT_PBOM-MATNR.
        GS_INPUTPBOM-WERKS = INPUT_PBOM-WERKS.
        GS_INPUTPBOM-IDNRK = INPUT_PBOM-IDNRK.
        GS_INPUTPBOM-KMPMG = INPUT_PBOM-KMPMG.
        GS_INPUTPBOM-XUHAO = PLM_SUBMATNR_COUNT-COUNT.
        GS_INPUTPBOM-MEINS = INPUT_PBOM-MEINS.
        GS_INPUTPBOM-SORTP = INPUT_PBOM-SORTP.
        GS_INPUTPBOM-LOGDATE = SY-DATUM.
        GS_INPUTPBOM-LOGTIME = SY-UZEIT.

        CLEAR TEMP_MATNR.
        SELECT SINGLE MATNR INTO TEMP_MATNR FROM ZINPUTPBOM
        WHERE MATNR = INPUT_PBOM-MATNR
        AND WERKS = INPUT_PBOM-WERKS
        AND IDNRK = INPUT_PBOM-IDNRK
        AND KMPMG = INPUT_PBOM-KMPMG
        AND XUHAO = PLM_SUBMATNR_COUNT-COUNT.

        IF TEMP_MATNR IS INITIAL.
          INSERT INTO ZINPUTPBOM VALUES GS_INPUTPBOM.
        ELSE.
          UPDATE ZINPUTPBOM SET SORTP = GS_INPUTPBOM-SORTP LOGDATE = SY-DATUM  LOGTIME = SY-UZEIT
          WHERE MATNR = INPUT_PBOM-MATNR
          AND WERKS = INPUT_PBOM-WERKS
          AND IDNRK = INPUT_PBOM-IDNRK
          AND KMPMG = INPUT_PBOM-KMPMG
          AND XUHAO = PLM_SUBMATNR_COUNT-COUNT.
        ENDIF.
        COMMIT WORK AND WAIT.

        "准备行项目数据
        CLEAR TEMP_STLNR.
        SELECT SINGLE STLNR INTO TEMP_STLNR FROM MAST WHERE MATNR = TEMP_MAT AND WERKS = TEMP_WERKS AND STLAN = '1'.
        IF TEMP_STLNR IS INITIAL.  "sap原数据没有bom时的处理
          CLEAR GT_STPO_INPUT.
          IF INPUT_PBOM-STVKN IS NOT INITIAL.
            GT_STPO_INPUT-ITEM_NODE = INPUT_PBOM-STVKN.
          ENDIF.
          GT_STPO_INPUT-CHG_NO_TO = INPUT_PBOM-AENRA.
          GT_STPO_INPUT-VALID_TO = INPUT_PBOM-DATUB+0(4) && '-' && INPUT_PBOM-DATUB+4(2) && '-' && INPUT_PBOM-DATUB+6(2).
          GT_STPO_INPUT-REL_PROD = 'X'."标识 与生产相关项目
          GT_STPO_INPUT-AI_GROUP = 'A'."替代组
          GT_STPO_INPUT-AI_PRIO = '1'."优先级
          GT_STPO_INPUT-AI_STRATEG = '01'."策略
          GT_STPO_INPUT-USAGE_PROB = '100'."使用比例
          GT_STPO_INPUT-IDENTIFIER = '1'."标识
          GT_STPO_INPUT-ITEM_NO = INPUT_PBOM-POSNR.     "项目号 默认9000
          GT_STPO_INPUT-ITEM_CATEG = INPUT_PBOM-POSTP.  "项目类别ICT 默认L
          GT_STPO_INPUT-COMPONENT = INPUT_PBOM-IDNRK.   "组件:即子物料
          GT_STPO_INPUT-COMP_QTY = INPUT_PBOM-KMPMG.    "数量
          GT_STPO_INPUT-COMP_UNIT = INPUT_PBOM-MEINS.   "单位
          GT_STPO_INPUT-REL_COST = 'X'.                 "成本核算标准相关
          GT_STPO_INPUT-SORTSTRING = INPUT_PBOM-SORTP.  "排序字符串
          GT_STPO_INPUT-CHANGE_NO = INPUT_PBOM-AENNR.
          PDATAV = INPUT_PBOM-DATUV+0(4) && '-' && INPUT_PBOM-DATUV+4(2) && '-' && INPUT_PBOM-DATUV+6(2) .
          GT_STPO_INPUT-VALID_FROM = PDATAV.

*        gt_stpo_input-comp_scrap = ."部件废品用百分比表示(BTCI)
*        gt_stpo_input-issue_loc = ."生产订单的发货地点
          APPEND GT_STPO_INPUT.

        ELSE.                     "sap原数据有bom时的处理,指定bom中要更改的具体条目
          CLEAR GT_STPO_INPUT.
          IF INPUT_PBOM-STVKN IS NOT INITIAL.
            GT_STPO_INPUT-ITEM_NODE = INPUT_PBOM-STVKN.
          ENDIF.
          GT_STPO_INPUT-CHG_NO_TO = INPUT_PBOM-AENRA.
          GT_STPO_INPUT-VALID_TO = INPUT_PBOM-DATUB+0(4) && '-' && INPUT_PBOM-DATUB+4(2) && '-' && INPUT_PBOM-DATUB+6(2).
          GT_STPO_INPUT-REL_PROD = 'X'."标识 与生产相关项目
          GT_STPO_INPUT-AI_GROUP = 'A'."替代组
          GT_STPO_INPUT-AI_PRIO = '1'."优先级
          GT_STPO_INPUT-AI_STRATEG = '01'."策略
          GT_STPO_INPUT-USAGE_PROB = '100'."使用比例
          GT_STPO_INPUT-IDENTIFIER = '1'."标识
          GT_STPO_INPUT-ITEM_NO = INPUT_PBOM-POSNR.     "项目号 默认9000
          GT_STPO_INPUT-ITEM_CATEG = INPUT_PBOM-POSTP.  "项目类别ICT 默认L
          GT_STPO_INPUT-COMPONENT = INPUT_PBOM-IDNRK.   "组件:即子物料
          GT_STPO_INPUT-COMP_QTY = INPUT_PBOM-KMPMG.    "数量
          GT_STPO_INPUT-COMP_UNIT = INPUT_PBOM-MEINS.   "单位
          GT_STPO_INPUT-REL_COST = 'X'.                 "成本核算标准相关
          GT_STPO_INPUT-SORTSTRING = INPUT_PBOM-SORTP.  "排序字符串
          GT_STPO_INPUT-CHANGE_NO = INPUT_PBOM-AENNR.
          PDATAV = INPUT_PBOM-DATUV+0(4) && '-' && INPUT_PBOM-DATUV+4(2) && '-' && INPUT_PBOM-DATUV+6(2) .
          GT_STPO_INPUT-VALID_FROM = PDATAV.
*         gt_stpo_input-comp_scrap = ."部件废品用百分比表示(BTCI)
*         gt_stpo_input-issue_loc = ."生产订单的发货地点

          CLEAR SAP_STPO.
          CLEAR SAP_STPO[].
          SELECT * INTO CORRESPONDING FIELDS OF TABLE  SAP_STPO FROM STPO
          WHERE STLNR = TEMP_STLNR AND STLTY = 'M' AND IDNRK = INPUT_PBOM-IDNRK AND MENGE = INPUT_PBOM-KMPMG ORDER BY STLKN STPOZ.
          IF LINES( SAP_STPO[] ) >= PLM_SUBMATNR_COUNT-COUNT.
            CLEAR NO1.
            LOOP AT SAP_STPO.
              NO1 = NO1 + 1.
              IF NO1 = PLM_SUBMATNR_COUNT-COUNT.
                GT_STPO_INPUT-BOM_NO = SAP_STPO-STLNR.
                GT_STPO_INPUT-ITEM_NODE = SAP_STPO-STLKN.
                GT_STPO_INPUT-ITEM_COUNT = SAP_STPO-STPOZ.
                IF ( SAP_STPO-SORTF IS NOT INITIAL ) AND ( INPUT_PBOM-SORTP IS INITIAL ).
                  GT_STPO_INPUT-SORTSTRING = SAP_STPO-SORTF.  "排序字符串
                ENDIF.
                EXIT.
              ENDIF.
            ENDLOOP.
          ENDIF.
          APPEND GT_STPO_INPUT.
        ENDIF.

      ELSE.
        "2.1.2 当完成一个小bom,处理该层小bom的数据同步。进入下一个小bom数据的准备
        CLEAR SAP_STPO.
        CLEAR SAP_STPO[].
        CLEAR SAP_SUBMATNR_COUNT.

*        SELECT * INTO CORRESPONDING FIELDS OF TABLE sap_stpo FROM stpo WHERE stlnr = temp_stlnr AND stlty = 'M' ORDER BY idnrk MENGE STLKN STPOZ.
*
*        LOOP AT sap_stpo."比较输入bom数据和SAPbom数据,判断需要删除的行项目(即输入无,而SAP有的行项目):这里是用物料号做的比较,是否ok?
*          IF sap_stpo-IDNRK = sap_submatnr_count-submatnr AND sap_stpo-MENGE = sap_submatnr_count-MENGE.
*            sap_submatnr_count-COUNT = sap_submatnr_count-COUNT + 1.
*          ELSE.
*            CLEAR sap_submatnr_count.
*            sap_submatnr_count-submatnr = sap_stpo-idnrk.
*            sap_submatnr_count-MENGE = sap_stpo-MENGE.
*            sap_submatnr_count-COUNT = sap_submatnr_count-COUNT + 1.
*          ENDIF.
* 删除用ECN处理
*          isfind = '0'.
*          CLEAR NO2.
*          LOOP AT gt_stpo_input.
*            IF sap_stpo-IDNRK = gt_stpo_input-COMPONENT AND sap_stpo-MENGE = gt_stpo_input-comp_qty.
*              NO2 = NO2 + 1.
*              IF NO2 = sap_submatnr_count-COUNT.
*                isfind = '1'.
*                EXIT.
*              ENDIF.
*            ENDIF.
*          ENDLOOP.
*          IF isfind = '0'."对要删除的行项目做标记,待处理
*            gt_stpo_input-bom_no = sap_stpo-STLNR.
*            gt_stpo_input-ITEM_NODE = sap_stpo-STLKN.
*            gt_stpo_input-ITEM_COUNT = sap_stpo-STPOZ.
*            gt_stpo_input-fldelete = 'X'.
*            APPEND gt_stpo_input.
*          ENDIF.
*        ENDLOOP.

        "下面执行小bom的数据同步

        CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
          EXPORTING
            MATERIAL      = TEMP_MAT
            PLANT         = TEMP_WERKS
            BOM_USAGE     = '1'   "物料清单用途 默认1
            CHANGE_NO     = INPUT_PBOM-AENNR
            VALID_FROM    = PDATAV
            I_STKO        = I_STKO
            FL_BOM_CREATE = 'X'
            FL_NEW_ITEM   = 'X'
            FL_COMPLETE   = 'x'
          TABLES
            T_STPO        = GT_STPO_INPUT
          EXCEPTIONS
            ERROR         = 1
            OTHERS        = 2.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT = 'X'.

        "BOM同步成功与否的记录

        CALL FUNCTION 'MESSAGE_TEXT_BUILD'
          EXPORTING
            MSGID               = SY-MSGID
            MSGNR               = SY-MSGNO
            MSGV1               = SY-MSGV1
            MSGV2               = SY-MSGV2
            MSGV3               = SY-MSGV3
            MSGV4               = SY-MSGV4
          IMPORTING
            MESSAGE_TEXT_OUTPUT = RETURN.

        IF SY-SUBRC <> 0.
          CLEAR OUTPUT_MESSAGE.
          RETURN = RETURN+12(10).
          OUTPUT_MESSAGE-MESSAGETYPE = 'E'.
        ELSE.
          CLEAR OUTPUT_MESSAGE.
          OUTPUT_MESSAGE-MESSAGETYPE = 'S'.
        ENDIF.
        OUTPUT_MESSAGE-MESSAGE = RETURN.

        OUTPUT_MESSAGE-MATNR = TEMP_MAT.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
          EXPORTING
            INPUT  = OUTPUT_MESSAGE-MATNR
          IMPORTING
            OUTPUT = OUTPUT_MESSAGE-MATNR.

        OUTPUT_MESSAGE-WERKS = TEMP_WERKS.

        APPEND OUTPUT_MESSAGE.

        ZLOG-MATNR = OUTPUT_MESSAGE-MATNR.
        ZLOG-WERKS = OUTPUT_MESSAGE-WERKS.
        ZLOG-MESSAGETYPE = OUTPUT_MESSAGE-MESSAGETYPE.
        ZLOG-MESSAGE = OUTPUT_MESSAGE-MESSAGE.
        ZLOG-LOGDATE = SY-DATUM.
        ZLOG-LOGTIME = SY-UZEIT.
        ZLOG-INTERFACENAME = 'ZPBOM_PLM2SAP'.

        INSERT INTO ZLOGOFMATNRORBOM  VALUES ZLOG.
        COMMIT WORK AND WAIT.

        CLEAR ZLOG.

        CLEAR GT_STPO_INPUT[].


        "进入下一个小bom数据的准备
        TEMP_MAT = INPUT_PBOM-MATNR.
        TEMP_WERKS = INPUT_PBOM-WERKS.

        CLEAR PLM_SUBMATNR_COUNT.
        PLM_SUBMATNR_COUNT-SUBMATNR = INPUT_PBOM-IDNRK.
        PLM_SUBMATNR_COUNT-MENGE = INPUT_PBOM-KMPMG.
        PLM_SUBMATNR_COUNT-COUNT = PLM_SUBMATNR_COUNT-COUNT + 1.

        "保存传入的数据到zinputpbom透视表中
        GS_INPUTPBOM-MATNR = INPUT_PBOM-MATNR.
        GS_INPUTPBOM-WERKS = INPUT_PBOM-WERKS.
        GS_INPUTPBOM-IDNRK = INPUT_PBOM-IDNRK.
        GS_INPUTPBOM-KMPMG = INPUT_PBOM-KMPMG.
        GS_INPUTPBOM-XUHAO = PLM_SUBMATNR_COUNT-COUNT.
        GS_INPUTPBOM-MEINS = INPUT_PBOM-MEINS.
        GS_INPUTPBOM-SORTP = INPUT_PBOM-SORTP.
        GS_INPUTPBOM-LOGDATE = SY-DATUM.
        GS_INPUTPBOM-LOGTIME = SY-UZEIT.

        CLEAR TEMP_MATNR.
        SELECT SINGLE MATNR INTO TEMP_MATNR FROM ZINPUTPBOM
        WHERE MATNR = INPUT_PBOM-MATNR
        AND WERKS = INPUT_PBOM-WERKS
        AND IDNRK = INPUT_PBOM-IDNRK
        AND KMPMG = INPUT_PBOM-KMPMG
        AND XUHAO = PLM_SUBMATNR_COUNT-COUNT.

        IF TEMP_MATNR IS INITIAL.
          INSERT INTO ZINPUTPBOM VALUES GS_INPUTPBOM.
        ELSE.
          UPDATE ZINPUTPBOM SET SORTP = GS_INPUTPBOM-SORTP LOGDATE = SY-DATUM  LOGTIME = SY-UZEIT
          WHERE MATNR = INPUT_PBOM-MATNR
          AND WERKS = INPUT_PBOM-WERKS
          AND IDNRK = INPUT_PBOM-IDNRK
          AND KMPMG = INPUT_PBOM-KMPMG
          AND XUHAO = PLM_SUBMATNR_COUNT-COUNT.
        ENDIF.
        COMMIT WORK AND WAIT.

        "准备行项目数据
        CLEAR TEMP_STLNR.
        SELECT SINGLE STLNR INTO TEMP_STLNR FROM MAST WHERE MATNR = TEMP_MAT AND WERKS = TEMP_WERKS AND STLAN = '1'.
        IF TEMP_STLNR IS INITIAL.
          CLEAR GT_STPO_INPUT.
          IF INPUT_PBOM-STVKN IS NOT INITIAL.
            GT_STPO_INPUT-ITEM_NODE = INPUT_PBOM-STVKN.
          ENDIF.
          GT_STPO_INPUT-CHG_NO_TO = INPUT_PBOM-AENRA.
          GT_STPO_INPUT-VALID_TO = INPUT_PBOM-DATUB+0(4) && '-' && INPUT_PBOM-DATUB+4(2) && '-' && INPUT_PBOM-DATUB+6(2).
          GT_STPO_INPUT-ITEM_NO = INPUT_PBOM-POSNR.     "项目号 默认9000
          GT_STPO_INPUT-ITEM_CATEG = INPUT_PBOM-POSTP.  "项目类别ICT 默认L
          GT_STPO_INPUT-COMPONENT = INPUT_PBOM-IDNRK.   "组件:即子物料
          GT_STPO_INPUT-COMP_QTY = INPUT_PBOM-KMPMG.    "数量
          GT_STPO_INPUT-COMP_UNIT = INPUT_PBOM-MEINS.   "单位
          GT_STPO_INPUT-REL_COST = 'X'.                 "成本核算标准相关
          GT_STPO_INPUT-SORTSTRING = INPUT_PBOM-SORTP.  "排序字符串
          GT_STPO_INPUT-CHANGE_NO = INPUT_PBOM-AENNR.
          PDATAV = INPUT_PBOM-DATUV+0(4) && '-' && INPUT_PBOM-DATUV+4(2) && '-' && INPUT_PBOM-DATUV+6(2) .
          GT_STPO_INPUT-VALID_FROM = PDATAV.
*        gt_stpo_input-comp_scrap = ."部件废品用百分比表示(BTCI)
*        gt_stpo_input-issue_loc = ."生产订单的发货地点
          APPEND GT_STPO_INPUT.

        ELSE.
          CLEAR GT_STPO_INPUT.
          IF INPUT_PBOM-STVKN IS NOT INITIAL.
            GT_STPO_INPUT-ITEM_NODE = INPUT_PBOM-STVKN.
          ENDIF.
          GT_STPO_INPUT-CHG_NO_TO = INPUT_PBOM-AENRA.
          GT_STPO_INPUT-VALID_TO = INPUT_PBOM-DATUB+0(4) && '-' && INPUT_PBOM-DATUB+4(2) && '-' && INPUT_PBOM-DATUB+6(2).
          GT_STPO_INPUT-ITEM_NO = INPUT_PBOM-POSNR.     "项目号 默认9000
          GT_STPO_INPUT-ITEM_CATEG = INPUT_PBOM-POSTP.  "项目类别ICT 默认L
          GT_STPO_INPUT-COMPONENT = INPUT_PBOM-IDNRK.   "组件:即子物料
          GT_STPO_INPUT-COMP_QTY = INPUT_PBOM-KMPMG.    "数量
          GT_STPO_INPUT-COMP_UNIT = INPUT_PBOM-MEINS.   "单位
          GT_STPO_INPUT-REL_COST = 'X'.                 "成本核算标准相关
          GT_STPO_INPUT-SORTSTRING = INPUT_PBOM-SORTP.  "排序字符串
          GT_STPO_INPUT-CHANGE_NO = INPUT_PBOM-AENNR.
          PDATAV = INPUT_PBOM-DATUV+0(4) && '-' && INPUT_PBOM-DATUV+4(2) && '-' && INPUT_PBOM-DATUV+6(2) .
          GT_STPO_INPUT-VALID_FROM = PDATAV.
*        gt_stpo_input-comp_scrap = ."部件废品用百分比表示(BTCI)
*        gt_stpo_input-issue_loc = ."生产订单的发货地点

          CLEAR SAP_STPO.
          CLEAR SAP_STPO[].
          SELECT * INTO CORRESPONDING FIELDS OF TABLE  SAP_STPO FROM STPO
          WHERE STLNR = TEMP_STLNR AND STLTY = 'M' AND IDNRK = INPUT_PBOM-IDNRK AND MENGE = INPUT_PBOM-KMPMG ORDER BY STLKN STPOZ.
          IF LINES( SAP_STPO[] ) >= PLM_SUBMATNR_COUNT-COUNT.
            CLEAR NO1.
            LOOP AT SAP_STPO.
              NO1 = NO1 + 1.
              IF NO1 = PLM_SUBMATNR_COUNT-COUNT.
                GT_STPO_INPUT-BOM_NO = SAP_STPO-STLNR.
                GT_STPO_INPUT-ITEM_NODE = SAP_STPO-STLKN.
                GT_STPO_INPUT-ITEM_COUNT = SAP_STPO-STPOZ.
                IF ( SAP_STPO-SORTF IS NOT INITIAL ) AND ( INPUT_PBOM-SORTP IS INITIAL ).
                  GT_STPO_INPUT-SORTSTRING = SAP_STPO-SORTF.  "排序字符串
                ENDIF.
                EXIT.
              ENDIF.
            ENDLOOP.
          ENDIF.
          APPEND GT_STPO_INPUT.
        ENDIF.
      ENDIF.

*2.2  某一小bom内行项目数据的处理:添加该行行项目。
    ELSE.
      IF INPUT_PBOM-IDNRK = PLM_SUBMATNR_COUNT-SUBMATNR AND INPUT_PBOM-KMPMG = PLM_SUBMATNR_COUNT-MENGE.
        PLM_SUBMATNR_COUNT-COUNT = PLM_SUBMATNR_COUNT-COUNT + 1.
      ELSE.
        CLEAR PLM_SUBMATNR_COUNT.
        PLM_SUBMATNR_COUNT-SUBMATNR = INPUT_PBOM-IDNRK.
        PLM_SUBMATNR_COUNT-MENGE = INPUT_PBOM-KMPMG.
        PLM_SUBMATNR_COUNT-COUNT = PLM_SUBMATNR_COUNT-COUNT + 1.
      ENDIF.

      "保存传入的数据到zinputpbom透视表中
      GS_INPUTPBOM-MATNR = INPUT_PBOM-MATNR.
      GS_INPUTPBOM-WERKS = INPUT_PBOM-WERKS.
      GS_INPUTPBOM-IDNRK = INPUT_PBOM-IDNRK.
      GS_INPUTPBOM-KMPMG = INPUT_PBOM-KMPMG.
      GS_INPUTPBOM-XUHAO = PLM_SUBMATNR_COUNT-COUNT.
      GS_INPUTPBOM-MEINS = INPUT_PBOM-MEINS.
      GS_INPUTPBOM-SORTP = INPUT_PBOM-SORTP.
      GS_INPUTPBOM-LOGDATE = SY-DATUM.
      GS_INPUTPBOM-LOGTIME = SY-UZEIT.

      CLEAR TEMP_MATNR.
      SELECT SINGLE MATNR INTO TEMP_MATNR FROM ZINPUTPBOM
      WHERE MATNR = INPUT_PBOM-MATNR
      AND WERKS = INPUT_PBOM-WERKS
      AND IDNRK = INPUT_PBOM-IDNRK
      AND KMPMG = INPUT_PBOM-KMPMG
      AND XUHAO = PLM_SUBMATNR_COUNT-COUNT.

      IF TEMP_MATNR IS INITIAL.
        INSERT INTO ZINPUTPBOM VALUES GS_INPUTPBOM.
      ELSE.
        UPDATE ZINPUTPBOM SET SORTP = GS_INPUTPBOM-SORTP LOGDATE = SY-DATUM  LOGTIME = SY-UZEIT
        WHERE MATNR = INPUT_PBOM-MATNR
        AND WERKS = INPUT_PBOM-WERKS
        AND IDNRK = INPUT_PBOM-IDNRK
        AND KMPMG = INPUT_PBOM-KMPMG
        AND XUHAO = PLM_SUBMATNR_COUNT-COUNT.
      ENDIF.
      COMMIT WORK AND WAIT.

      "准备行项目数据
      CLEAR TEMP_STLNR.
      SELECT SINGLE STLNR INTO TEMP_STLNR FROM MAST WHERE MATNR = TEMP_MAT AND WERKS = TEMP_WERKS AND STLAN = '1'.
      IF TEMP_STLNR IS INITIAL.
        CLEAR GT_STPO_INPUT.
        GT_STPO_INPUT-REL_PROD = 'X'."标识 与生产相关项目
        GT_STPO_INPUT-AI_GROUP = 'A'."替代组
        GT_STPO_INPUT-AI_PRIO = '1'."优先级
        GT_STPO_INPUT-AI_STRATEG = '01'."策略
        GT_STPO_INPUT-USAGE_PROB = '100'."使用比例
        GT_STPO_INPUT-IDENTIFIER = '1'."标识
        GT_STPO_INPUT-ITEM_NO = INPUT_PBOM-POSNR.     "项目号 默认9000
        GT_STPO_INPUT-ITEM_CATEG = INPUT_PBOM-POSTP.  "项目类别ICT 默认L
        GT_STPO_INPUT-COMPONENT = INPUT_PBOM-IDNRK.   "组件:即子物料
        GT_STPO_INPUT-COMP_QTY = INPUT_PBOM-KMPMG.    "数量
        GT_STPO_INPUT-COMP_UNIT = INPUT_PBOM-MEINS.   "单位
        GT_STPO_INPUT-REL_COST = 'X'.                 "成本核算标准相关
        GT_STPO_INPUT-SORTSTRING = INPUT_PBOM-SORTP.  "排序字符串
        PDATAV = INPUT_PBOM-DATUV+0(4) && '-' && INPUT_PBOM-DATUV+4(2) && '-' && INPUT_PBOM-DATUV+6(2) .
        GT_STPO_INPUT-VALID_FROM = PDATAV.
*        gt_stpo_input-comp_scrap = ."部件废品用百分比表示(BTCI)
*        gt_stpo_input-issue_loc = ."生产订单的发货地点
        APPEND GT_STPO_INPUT.

      ELSE.
        CLEAR GT_STPO_INPUT.
        IF INPUT_PBOM-STVKN IS NOT INITIAL.
          GT_STPO_INPUT-ITEM_NODE = INPUT_PBOM-STVKN.
        ENDIF.
        GT_STPO_INPUT-CHG_NO_TO = INPUT_PBOM-AENRA.
        GT_STPO_INPUT-VALID_TO = INPUT_PBOM-DATUB+0(4) && '-' && INPUT_PBOM-DATUB+4(2) && '-' && INPUT_PBOM-DATUB+6(2).
        GT_STPO_INPUT-REL_PROD = 'X'."标识 与生产相关项目
        GT_STPO_INPUT-AI_GROUP = 'A'."替代组
        GT_STPO_INPUT-AI_PRIO = '1'."优先级
        GT_STPO_INPUT-AI_STRATEG = '01'."策略
        GT_STPO_INPUT-USAGE_PROB = '100'."使用比例
        GT_STPO_INPUT-IDENTIFIER = '1'."标识
        GT_STPO_INPUT-ITEM_NO = INPUT_PBOM-POSNR.     "项目号 默认9000
        GT_STPO_INPUT-ITEM_CATEG = INPUT_PBOM-POSTP.  "项目类别ICT 默认L
        GT_STPO_INPUT-COMPONENT = INPUT_PBOM-IDNRK.   "组件:即子物料
        GT_STPO_INPUT-COMP_QTY = INPUT_PBOM-KMPMG.    "数量
        GT_STPO_INPUT-COMP_UNIT = INPUT_PBOM-MEINS.   "单位
        GT_STPO_INPUT-REL_COST = 'X'.                 "成本核算标准相关
        GT_STPO_INPUT-SORTSTRING = INPUT_PBOM-SORTP.  "排序字符串
        PDATAV = INPUT_PBOM-DATUV+0(4) && '-' && INPUT_PBOM-DATUV+4(2) && '-' && INPUT_PBOM-DATUV+6(2) .
        GT_STPO_INPUT-VALID_FROM = PDATAV.
*        gt_stpo_input-comp_scrap = ."部件废品用百分比表示(BTCI)
*        gt_stpo_input-issue_loc = ."生产订单的发货地点

        CLEAR SAP_STPO.
        CLEAR SAP_STPO[].
        SELECT * INTO CORRESPONDING FIELDS OF TABLE  SAP_STPO FROM STPO
        WHERE STLNR = TEMP_STLNR AND STLTY = 'M' AND IDNRK = INPUT_PBOM-IDNRK AND MENGE = INPUT_PBOM-KMPMG ORDER BY STLKN STPOZ.
        IF LINES( SAP_STPO[] ) >= PLM_SUBMATNR_COUNT-COUNT.
          CLEAR NO1.
          LOOP AT SAP_STPO.
            NO1 = NO1 + 1.
            IF NO1 = PLM_SUBMATNR_COUNT-COUNT.
              GT_STPO_INPUT-BOM_NO = SAP_STPO-STLNR.
              GT_STPO_INPUT-ITEM_NODE = SAP_STPO-STLKN.
              GT_STPO_INPUT-ITEM_COUNT = SAP_STPO-STPOZ.
              IF ( SAP_STPO-SORTF IS NOT INITIAL ) AND ( INPUT_PBOM-SORTP IS INITIAL ).
                GT_STPO_INPUT-SORTSTRING = SAP_STPO-SORTF.  "排序字符串
              ENDIF.
              EXIT.
            ENDIF.
          ENDLOOP.
        ENDIF.
        APPEND GT_STPO_INPUT.
      ENDIF.
    ENDIF.
  ENDLOOP.

*3.  所有bom项跑完了,对最后一个小bom的处理
  CLEAR SAP_STPO.
  CLEAR SAP_STPO[].
  CLEAR SAP_SUBMATNR_COUNT.

*  SELECT * INTO CORRESPONDING FIELDS OF TABLE sap_stpo FROM stpo WHERE stlnr = temp_stlnr AND stlty = 'M' ORDER BY idnrk MENGE STLKN STPOZ.
*
*  LOOP AT sap_stpo."比较输入bom数据和SAPbom数据,判断需要删除的行项目(即输入无,而SAP有的行项目):这里是用物料号做的比较,是否ok?
*    IF sap_stpo-IDNRK = sap_submatnr_count-submatnr AND sap_stpo-MENGE = sap_submatnr_count-MENGE.
*      sap_submatnr_count-COUNT = sap_submatnr_count-COUNT + 1.
*    ELSE.
*      CLEAR sap_submatnr_count.
*      sap_submatnr_count-submatnr = sap_stpo-idnrk.
*      sap_submatnr_count-MENGE = sap_stpo-MENGE.
*      sap_submatnr_count-COUNT = sap_submatnr_count-COUNT + 1.
*    ENDIF.
*
*    isfind = '0'.
*    CLEAR NO2.
*    LOOP AT gt_stpo_input.
*      IF sap_stpo-IDNRK = gt_stpo_input-COMPONENT AND sap_stpo-MENGE = gt_stpo_input-comp_qty.
*        NO2 = NO2 + 1.
*        IF NO2 = sap_submatnr_count-COUNT.
*          isfind = '1'.
*          EXIT.
*        ENDIF.
*      ENDIF.
*    ENDLOOP.
*    IF isfind = '0'.
*      gt_stpo_input-bom_no = sap_stpo-STLNR.
*      gt_stpo_input-ITEM_NODE = sap_stpo-STLKN.
*      gt_stpo_input-ITEM_COUNT = sap_stpo-STPOZ.
*      gt_stpo_input-fldelete = 'X'.
*      APPEND gt_stpo_input.
*    ENDIF.
*  ENDLOOP.

  CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
    EXPORTING
      MATERIAL      = TEMP_MAT
      PLANT         = TEMP_WERKS
      BOM_USAGE     = '1'   "物料清单用途 默认1
      CHANGE_NO     = INPUT_PBOM-AENNR
      VALID_FROM    = PDATAV
      I_STKO        = I_STKO
      FL_BOM_CREATE = 'X'
      FL_NEW_ITEM   = 'X'
      FL_COMPLETE   = 'x'
    TABLES
      T_STPO        = GT_STPO_INPUT
    EXCEPTIONS
      ERROR         = 1
      OTHERS        = 2.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      WAIT = 'X'.

  "BOM同步成功与否的记录

  CALL FUNCTION 'MESSAGE_TEXT_BUILD'
    EXPORTING
      MSGID               = SY-MSGID
      MSGNR               = SY-MSGNO
      MSGV1               = SY-MSGV1
      MSGV2               = SY-MSGV2
      MSGV3               = SY-MSGV3
      MSGV4               = SY-MSGV4
    IMPORTING
      MESSAGE_TEXT_OUTPUT = RETURN.

  IF SY-MSGTY = 'S'.
    CLEAR OUTPUT_MESSAGE.
    OUTPUT_MESSAGE-MESSAGETYPE = 'S'.
  ELSE.
    CLEAR OUTPUT_MESSAGE.
*    RETURN = RETURN+12(10).
    OUTPUT_MESSAGE-MESSAGETYPE = 'E'.
  ENDIF.



  OUTPUT_MESSAGE-MESSAGE = RETURN.
  OUTPUT-RETURN-MSGTY = OUTPUT_MESSAGE-MESSAGETYPE.
  OUTPUT-RETURN-MSGTX = OUTPUT_MESSAGE-MESSAGE.

  OUTPUT_MESSAGE-MATNR = TEMP_MAT.

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


  OUTPUT_MESSAGE-WERKS = TEMP_WERKS.
  APPEND OUTPUT_MESSAGE.

  ZLOG-MATNR = OUTPUT_MESSAGE-MATNR.
  ZLOG-WERKS = OUTPUT_MESSAGE-WERKS.
  ZLOG-MESSAGETYPE = OUTPUT_MESSAGE-MESSAGETYPE.
  ZLOG-MESSAGE = OUTPUT_MESSAGE-MESSAGE.
  ZLOG-LOGDATE = SY-DATUM.
  ZLOG-LOGTIME = SY-UZEIT.
  ZLOG-INTERFACENAME = 'ZPBOM_PLM2SAP'.

  INSERT INTO ZLOGOFMATNRORBOM  VALUES ZLOG.
  COMMIT WORK AND WAIT.

  CLEAR GT_STPO_INPUT[].

ENDFUNCTION.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2263929.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

GitLab的安装和使用

1.GitLab 环境说明 系统版本 CentOS 7.2 x86_64 软件版本 gitlab-ce-10.8.4 GitLab 是一个用于仓库管理系统的开源项目&#xff0c;使用Git作为代码管理工具&#xff0c;并在此基础上搭建起来的web服务。可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能…

开放词汇目标检测(Open-Vocabulary Object Detection, OVOD)综述

定义 开放词汇目标检测&#xff08;Open-Vocabulary Object Detection, OVOD&#xff09;是一种目标检测任务&#xff0c;旨在检测和识别那些未在训练集中明确标注的物体类别。传统的目标检测模型通常只能识别有限数量的预定义类别&#xff0c;而OVOD模型则具有识别“开放词汇…

JaxaFx学习(三)

目录&#xff1a; &#xff08;1&#xff09;JavaFx MVVM架构实现 &#xff08;2&#xff09;javaFX知识点 &#xff08;3&#xff09;JavaFx的MVC架构 &#xff08;4&#xff09;JavaFx事件处理机制 &#xff08;5&#xff09;多窗体编程 &#xff08;6&#xff09;数据…

【C++】小乐乐求和问题的高效求解与算法对比分析

博客主页&#xff1a; [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] 本文专栏: C 文章目录 &#x1f4af;前言&#x1f4af;问题描述与数学模型1.1 题目概述1.2 输入输出要求1.3 数学建模 &#x1f4af;方法一&#xff1a;朴素循环求和法2.1 实现原理2.2 分析与问题2.3 改进方案2.4 性能瓶颈与结论…

基于Spring Boot的找律师系统

一、系统背景与意义 在现代社会&#xff0c;法律服务的需求日益增长&#xff0c;但传统寻找律师的方式往往存在信息不透明、选择困难等问题。基于Spring Boot的找律师系统旨在解决这些问题&#xff0c;通过线上平台&#xff0c;用户可以轻松搜索、比较和选择合适的律师&#x…

【Spring】方法注解@Bean,配置类扫描路径

阿华代码&#xff0c;不是逆风&#xff0c;就是我疯 你们的点赞收藏是我前进最大的动力&#xff01;&#xff01; 希望本文内容能够帮助到你&#xff01;&#xff01; 目录 引入 一&#xff1a;Bean方法注解 1&#xff1a;方法注解要搭配类注解使用 2&#xff1a;执行结果 …

深度学习0-前置知识

一、背景 AI最大&#xff0c;它的目的是通过让机器模仿人类进而超越人类&#xff1b; ML次之&#xff0c;它是AI的一个分支&#xff0c;是让机器模仿人类的一种方法。开发人员用大量数据和算法“训练”机器&#xff0c;让机器自行学会如何执行任务&#xff0c;它的成功取决于…

前端面试题整理-前端异步编程

1. 进程、线程、协程的区别 在并发编程领域&#xff0c;进程、线程和协程是三个核心概念&#xff0c;它们在资源管理、调度和执行上有着本质的不同。 首先&#xff0c;进程是操作系统进行资源分配和调度的独立单位&#xff08;资源分配基本单位&#xff09;&#xff0c;每个进…

ARM学习(38)多进程多线程之间的通信方式

ARM学习(38)ARM学习(38)多进程多线程之间的通信方式 一、问题背景 笔者在调试模拟器的时候,碰到进程间通信的问题,一个进程在等另外一个进程ready的时候,迟迟等不到,然后通过调试发现,另外一个进程变量已经变化了,但是当前进程变量没变化,需要了解进程间通信的方式…

群晖利用acme.sh自动申请证书并且自动重载证书的问题解决

前言 21年的时候写了一个在群晖&#xff08;黑群晖&#xff09;下利用acme.sh自动申请Let‘s Encrypt的脚本工具 群晖使用acme自动申请Let‘s Encrypt证书脚本&#xff0c;自动申请虽然解决了&#xff0c;但是自动重载一直是一个问题&#xff0c;本人也懒&#xff0c;一想到去…

level2逐笔委托查询接口

沪深逐笔委托队列查询 前置步骤 分配数据库服务器 查询模板 以下是沪深委托队列查询的请求模板&#xff1a; http://<数据库服务器>/sql?modeorder_book&code<股票代码>&offset<offset>&token<token>查询参数说明 参数名类型说明mo…

delve调试环境搭建—golang

原文地址&#xff1a;delve调试环境搭建—golang – 无敌牛 欢迎参观我的个人博客&#xff1a;无敌牛 – 技术/著作/典籍/分享等 由于平时不用 IDE 开发环境&#xff0c;习惯在 linux终端vim 环境下开发&#xff0c;所以找了golang的调试工具&#xff0c;delve类似gdb的调试界…

PC寄存器(Program Counter Register) jvm

在JVM&#xff08;Java虚拟机&#xff09;中&#xff0c;PC寄存器&#xff08;Program Counter Register&#xff09;扮演着至关重要的角色&#xff0c;它是JVM执行引擎的核心组成部分之一。以下是PC寄存器在JVM中的具体角色和职责&#xff1a; 指令执行指针&#xff1a; PC寄存…

线性分类器(KNN,SVM损失,交叉熵损失,softmax)

KNN 工作机制 k-近邻算法的工作机制可以分为两个主要阶段&#xff1a;训练阶段和预测阶段。 训练阶段 在训练阶段&#xff0c;k-近邻算法并不进行显式的模型训练&#xff0c;而是简单地存储训练数据集。每个样本由特征向量和对应的标签组成。此阶段的主要任务是准备好数据&…

重拾设计模式--适配器模式

文章目录 适配器模式&#xff08;Adapter Pattern&#xff09;概述适配器模式UML图适配器模式的结构目标接口&#xff08;Target&#xff09;&#xff1a;适配器&#xff08;Adapter&#xff09;&#xff1a;被适配者&#xff08;Adaptee&#xff09;&#xff1a; 作用&#xf…

StarRocks:存算一体模式部署

目录 一、StarRocks 简介 二、StarRocks 架构 2.1 存算一体 2.2 存算分离 三、前期准备 3.1前提条件 3.2 集群规划 3.3 配置环境 3.4 准备部署文件 四、手动部署 4.1 部署FE节点 4.2 部署BE节点 4.3 部署CN节点&#xff08;可选&#xff09; 4.4 FE高可用…

找数字:JAVA

题目描述 试计算在区间1 到n 的所有整数中&#xff0c;数字x&#xff08;0 ≤ x ≤ 9&#xff09;共出现了多少次&#xff1f; 例如&#xff0c;在1到11 中&#xff0c;即在1、2、3、4、5、6、7、8、9、10、11 中&#xff0c;数字1 出现了4 次。 输入描述: 输入共1行&#xf…

AI的使用:结构化提示词

根据自己的使用&#xff0c;不断的完善自己的提示词。并且像程序版本一样管理和迭代自己的提示词&#xff0c;这样才能准确的按照自己的目的去使用AI。而为了更好的管理&#xff0c;我们在一开始使用的时候&#xff0c;就要有一个易于管理的定义&#xff0c;即&#xff1a;结构…

Netcat:网络中的瑞士军刀

免责声明&#xff1a;使用本教程或工具&#xff0c;用户必须遵守所有适用的法律和法规&#xff0c;并且用户应自行承担所有风险和责任。 文章目录 一、引言二、简述三、Netcat功能&#xff1f;四、参数选项五、Netcat 的常见功能六、高级用法多连接处理创建简单的代理 七、Netc…

VS Code Copilot 与 Cursor 对比

选手简介 VS Code Copilot&#xff1a;算是“老牌”编程助手了&#xff0c;虽然Copilot在别的编辑器上也有扩展&#xff0c;不过体验最好的还是VS Code&#xff0c;毕竟都是微软家的所以功能集成更好一些&#xff1b;主要提供的是Complete和Chat能力&#xff0c;也就是代码补全…