ABAP:CS01/CS02/CS03 批量创建/修改/删除BOM BAPI
创建BOM:CSAP_MAT_BOM_CREATE
FORM frm_create_bom_from_bapi TABLES pt_stpo STRUCTURE stpo_api03 USING ps_stko TYPE stko_api01 ps_bom LIKE gs_bom CHANGING pv_msg TYPE char200 pv_subrc TYPE i. DATA:ls_csap_mbom LIKE csap_mbom. DATA: lv_valid_from TYPE csap_mbom-datuv. DATA: ls_ret_stko TYPE stko_api02. DATA:fl_warning LIKE capiflag-flwarning, bom_no LIKE stko_api02-bom_no. CLEAR:lv_valid_from. CLEAR:ls_ret_stko. WRITE ps_bom-datuv TO ls_csap_mbom-datuv. ls_csap_mbom-matnr = ps_bom-matnr . ls_csap_mbom-werks = ps_bom-werks . ls_csap_mbom-stlan = ps_bom-stlan . ls_csap_mbom-stlal = ps_bom-stlal . pv_subrc = 4 . SET UPDATE TASK LOCAL. CALL FUNCTION 'CSAP_MAT_BOM_CREATE' EXPORTING material = ls_csap_mbom-matnr plant = ls_csap_mbom-werks bom_usage = ls_csap_mbom-stlan alternative = ls_csap_mbom-stlal valid_from = ls_csap_mbom-datuv * CHANGE_NO = * REVISION_LEVEL = i_stko = ps_stko * FL_NO_CHANGE_DOC = ' ' fl_commit_and_wait = 'X' * FL_CAD = ' ' * FL_DEFAULT_VALUES = 'X' * FL_RECURSIVE = ' ' IMPORTING fl_warning = fl_warning bom_no = bom_no TABLES t_stpo = pt_stpo * T_DEP_DATA = * T_DEP_DESCR = * T_DEP_ORDER = * T_DEP_SOURCE = * T_DEP_DOC = * T_LTX_LINE = * T_STPU = * T_FSH_BOMD = * T_SGT_BOMC = EXCEPTIONS error = 1 OTHERS = 2. * IF sy-subrc <> 0. ** Implement suitable error handling here * ENDIF. * * ** CLEAR LT_STPO. * CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN' * EXPORTING * material = ls_csap_mbom-matnr * plant = ls_csap_mbom-werks * bom_usage = ls_csap_mbom-stlan * alternative = ls_csap_mbom-stlal ** change_no = gw_excel_input-aennr * valid_from = ls_csap_mbom-datuv * i_stko = ps_stko * fl_commit_and_wait = 'X' * fl_bom_create = 'X' * fl_new_item = 'X' * fl_complete = ' ' * IMPORTING * o_stko = ls_ret_stko * TABLES * t_stpo = pt_stpo * EXCEPTIONS * error = 1 * OTHERS = 2. IF sy-subrc <> 0. CLEAR: pv_msg. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO pv_msg. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. pv_msg = 'BOM创建成功!'. pv_subrc = 0 . ENDIF. ENDFORM.
修改BOM:CSAP_MAT_BOM_MAINTAIN
FUNCTION zfunc_005. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_INPUT) TYPE ZPPS001 OPTIONAL *" EXPORTING *" VALUE(E_OUTPUT) TYPE ZPPS003 *" TABLES *" T_TAB STRUCTURE ZPPS002 OPTIONAL *"---------------------------------------------------------------------- *[MOD-01] 14.07.2022 10:42:19 YSX BOM行项目增加长文本写入 *-----接口日志处理 zmac-rfc-log-b. DATA: lv_material TYPE csap_mbom-matnr, ls_stko TYPE stko_api01, lt_stpo TYPE STANDARD TABLE OF stpo_api03, lt_stpo2 TYPE STANDARD TABLE OF stpo_api02, ls_stpo LIKE LINE OF lt_stpo, ls_stpo2 LIKE LINE OF lt_stpo2, lt_ltx TYPE STANDARD TABLE OF csltx_line, ls_ltx LIKE LINE OF lt_ltx, lv_ident TYPE numc08, lv_datfm TYPE csap_mbom-datuv, lv_flwarning TYPE capiflag-flwarning. DATA : lv_datuv TYPE sy-datum . DATA : lv_posnr TYPE stpox-posnr . DATA : lv_num TYPE i. DATA: lv_stlal TYPE stalt, lv_stlan TYPE stlan, ls_cstmat TYPE cstmat, " ANDAT lt_stpox TYPE STANDARD TABLE OF stpox, " MATMK ls_stpox LIKE LINE OF lt_stpox, lv_index LIKE sy-tabix, lt_cscmat TYPE STANDARD TABLE OF cscmat. DATA : lv_creat TYPE csdata-xfeld . DATA: lv_msg TYPE msgtxt , "STRING, lt_message TYPE STANDARD TABLE OF messages, ls_message LIKE LINE OF lt_message. DATA: l_menge LIKE stpo-menge. DATA:lt_lines TYPE TABLE OF tline, ls_lines TYPE tline. RANGES: rg_matnr FOR marc-matnr. DATA:lv_zcwb TYPE string. * DATA: LV_MSG TYPE MSGTXT. * CLEAR: ET_MESSAGE, ET_MESSAGE[]. IF i_input-matnr EQ space. e_output-sta = 'E'. e_output-message = 'BOM物料不能为空'. lv_msg = e_output-message. zmac-rfc-log-e e_output-sta lv_msg '' '' ''. RETURN. ENDIF. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = i_input-matnr IMPORTING output = lv_material. IF i_input-werks EQ space. e_output-sta = 'E'. e_output-message = '工厂不能为空'. lv_msg = e_output-message. zmac-rfc-log-e e_output-sta lv_msg lv_material '' ''. RETURN. ENDIF. IF i_input-aennr EQ space. * E_OUTPUT-STA = 'E'. * E_OUTPUT-MESSAGE = 'ECN号不能为空'. * LV_MSG = E_OUTPUT-MESSAGE. * ZMAC-RFC-LOG-E E_OUTPUT-STA LV_MSG LV_MATERIAL '' ''. * RETURN. ELSE . CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = i_input-aennr IMPORTING output = i_input-aennr. SELECT COUNT(*) FROM aenr WHERE aennr = i_input-aennr . IF sy-subrc <> 0 . PERFORM sub_creat_ecn USING i_input . ENDIF . ENDIF. rg_matnr-sign = 'I'. rg_matnr-option = 'EQ'. rg_matnr-low = lv_material. APPEND rg_matnr. * LS_STKO-BOM_TEXT = I_INPUT-STKTX. ls_stko-bom_status = '01'. "I_INPUT-STLST. IF i_input-stlan EQ space. lv_stlan = '1'. ELSE. lv_stlan = i_input-stlan. ENDIF. * IF I_INPUT-STLAL EQ SPACE. lv_stlal = '01'. * ELSE. * CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' * EXPORTING * INPUT = I_INPUT-STLAL * IMPORTING * OUTPUT = LV_STLAL. * ENDIF. IF i_input-datuv = '00000000' . lv_datuv = sy-datum . ELSE . lv_datuv = i_input-datuv . ENDIF . CLEAR lv_creat . CLEAR lv_ident . CALL FUNCTION 'CS_BOM_EXPL_MAT_V2' EXPORTING capid = 'PP01' stlan = lv_stlan "'1' cospr = 'X' cuols = 'X' datuv = lv_datuv ehndl = '2' emeng = i_input-basmn " '1' mehrs = 'X' mtnrv = lv_material mmory = '0' rndkz = '1' * STLAL = LV_STLAL "I_INPUT-stlal werks = i_input-werks stpst = 1 "99 IMPORTING topmat = ls_cstmat TABLES stb = lt_stpox matcat = lt_cscmat EXCEPTIONS alt_not_found = 1 call_invalid = 2 material_not_found = 3 missing_authorization = 4 no_bom_found = 5 no_plant_data = 6 no_suitable_bom_found = 7 conversion_error = 8 OTHERS = 9. IF sy-subrc <> 0. lv_creat = 'X' . ELSE . SORT lt_stpox BY index DESCENDING . CLEAR ls_stpox . READ TABLE lt_stpox INTO ls_stpox INDEX 1 . lv_ident = ls_stpox-index . ENDIF. ls_stko-base_quan = i_input-basmn. * LS_STKO-BASE_UNIT = LS_CSTMAT-BMEIN. ls_stko-alt_text = i_input-stktx . CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' EXPORTING date_internal = lv_datuv IMPORTING date_external = lv_datfm EXCEPTIONS date_internal_is_invalid = 1 OTHERS = 2. DATA : ls_tab TYPE zpps002 . SORT lt_stpox BY posnr ASCENDING aennr DESCENDING . LOOP AT t_tab INTO ls_tab. CLEAR: ls_stpo, ls_ltx. CLEAR ls_stpox . CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = ls_tab-idnrk IMPORTING output = ls_tab-idnrk. SELECT COUNT(*) FROM mara WHERE matnr = ls_tab-idnrk AND matkl IN ('331001', '191001') . IF sy-subrc = 0 . e_output-sta = 'E'. e_output-message = ls_tab-posnr && '模具物料无法处理'. lv_msg = e_output-message. zmac-rfc-log-e e_output-sta lv_msg lv_material '' ''. RETURN. ENDIF . lv_posnr = ls_tab-posnr+2(4) . IF lv_creat = '' . READ TABLE lt_stpox INTO ls_stpox WITH KEY posnr = lv_posnr . IF sy-subrc = 0 . ls_stpo-change_no = ls_stpox-aennr. " 变更编号 * LS_STPO-ITM_IDENT = LS_STPOX-STLKN . ls_stpo-item_node = ls_stpox-stlkn . ls_stpo-item_count = ls_stpox-stpoz . * LS_STPO-IDENTIFIER = LS_STPOX-STLKN . ELSE . lv_ident = lv_ident + 1. * LS_STPO-ITM_IDENT = LV_IDENT . * LS_STPO-ITEM_NODE = LV_IDENT . * LS_STPO-ITEM_COUNT = LV_IDENT . * LS_STPO-IDENTIFIER = LV_IDENT . ENDIF . ENDIF . ls_stpo-bom_no = ls_cstmat-stlnr . IF ls_tab-idnrk = ls_stpox-idnrk AND ls_tab-menge = ls_stpox-menge AND ls_tab-meins = ls_stpox-meins AND ls_tab-ausch = ls_stpox-ausch AND ls_tab-sortf = ls_stpox-sortf AND ls_tab-sanka = ls_stpox-sanka AND ls_tab-lgort = ls_stpox-lgort AND ls_tab-potx1 = ls_stpox-potx1 AND ls_tab-potx2 = ls_stpox-potx2 AND ls_tab-alpgr = ls_stpox-alpgr AND ls_tab-alpst = ls_stpox-alpst AND ls_tab-alprf = ls_stpox-alprf AND ls_tab-ewahr = ls_stpox-ewahr . CONTINUE . ENDIF . CALL FUNCTION 'CONVERSION_EXIT_NUMCV_INPUT' EXPORTING input = ls_tab-posnr IMPORTING output = ls_stpo-item_no. ls_stpo-item_categ = ls_tab-postp. " 项目类别 * LS_STPO-BOM_NO = LS_CSTMAT-STLNR. IF ls_tab-idnrk NE space. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = ls_tab-idnrk IMPORTING output = ls_stpo-component EXCEPTIONS length_error = 1 OTHERS = 2. ENDIF. * CLEAR: LS_STPOX,L_MENGE. * READ TABLE LT_STPOX INTO LS_STPOX WITH KEY IDNRK = ls_tab-IDNRK. * IF SY-SUBRC = 0. * L_MENGE = LS_STPOX-MENGE + ls_tab-MENGE. * ELSE. * IF ls_tab-MENGE > 0. * L_MENGE = ls_tab-MENGE. * ENDIF. * ENDIF. * * IF L_MENGE <= 0. ** ls_stpo-fldelete = 'X'. * CONTINUE. * ELSE. * LS_STPO-COMP_QTY = L_MENGE. * ENDIF. ls_stpo-comp_qty = ls_tab-menge . * ls_stpo-comp_qty = ls_tab-menge. * CONDENSE ls_stpo-comp_qty NO-GAPS. IF ls_tab-meins NE space. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = ls_tab-meins IMPORTING output = ls_stpo-comp_unit EXCEPTIONS unit_not_found = 1 OTHERS = 2. IF sy-subrc <> 0. ls_stpo-comp_unit = ls_tab-meins. ENDIF. ENDIF. CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' EXPORTING date_internal = sy-datum IMPORTING date_external = ls_stpo-valid_from EXCEPTIONS date_internal_is_invalid = 1 OTHERS = 2. IF ls_tab-ausch > 0 . ls_stpo-comp_scrap = ls_tab-ausch. " 部件废品百分数 ELSE . ls_stpo-comp_scrap = '!' . ENDIF . CONDENSE ls_stpo-comp_scrap NO-GAPS. * LS_STPO-SPPROCTYPE = ls_tab-ITSOB. " BOM项目的特殊采购类型 IF ls_tab-alpgr <> '' . ls_stpo-ai_group = ls_tab-alpgr. " 替代项目: 组 ELSE . ls_stpo-ai_group = '!' . ENDIF . IF ls_tab-alprf <> '' . ls_stpo-ai_prio = ls_tab-alprf. " 优先级 ELSE . ls_stpo-ai_prio = '!' . ENDIF . IF ls_tab-alpst <> '' . ls_stpo-ai_strateg = ls_tab-alpst. " 替代项目:策略 ELSE . ls_stpo-ai_strateg = '!' . ENDIF . IF ls_tab-sanka <> '' . ls_stpo-rel_cost = ls_tab-sanka. "成本核算标识 ELSE . ls_stpo-rel_cost = '!' . ENDIF . * IF LS_STPO-AI_STRATEG EQ SPACE AND LS_STPO-AI_GROUP NE SPACE. * LS_STPO-AI_STRATEG = '2'. * ENDIF. * LS_STPO-USAGE_PROB = ls_tab-EWAHR. " 使用可能性按 % "优先级为1的默认100%,其他为空 IF ls_stpo-ai_group NE space. IF ls_stpo-ai_prio EQ '01'. ls_stpo-usage_prob = '100'. ELSE. ls_stpo-usage_prob = '0'. ENDIF. ENDIF. CONDENSE ls_stpo-usage_prob NO-GAPS. ls_stpo-item_text1 = ls_tab-potx1. " BOM项目文本1 ls_stpo-item_text2 = ls_tab-potx2. " BOM项目文本2 * LS_STPO-REL_PROD = ls_tab-SANFE. " 标识:与生产相关项目 IF ls_tab-sanka <> '' . ls_stpo-rel_cost = ls_tab-sanka. " 成本核算相关项目的标识符 ELSE . ls_stpo-rel_cost = '!' . ENDIF . * IF ls_tab-SANKA NE 'X' AND ls_tab-POSTP EQ 'L'. * LS_STPO-REL_COST = 'X'. * ENDIF. * IF ls_tab-POSTP EQ 'T'. * CLEAR: LS_STPO-REL_COST. * ENDIF. IF ls_tab-lgort <> '' . ls_stpo-issue_loc = ls_tab-lgort. " 生产订单的发货地点 ELSE . ls_stpo-issue_loc = '!' . ENDIF . * LS_STPO-BOM_ALT = LV_STLAL. "I_INPUT-stlal. " 可选的BOM ls_stpo-sortstring = ls_tab-sortf. " 排序字符串 * LS_STPO-CHANGE_NO = I_INPUT-AENNR. " 变更编号 ls_stpo-chg_no_to = i_input-aennr. " 变更编号 * LS_STPO-IDENTIFIER = LV_IDENT. "[MOD-01] 14.07.2022 10:42:52 YSX ls_stpo-identifier = ls_stpo-item_no. * CLEAR:lv_num. * lv_num = strlen( ls_tab-zwcha ). * PERFORM frm_string_to_tdline TABLES USING ls_tab-zwcha. CLEAR:lv_zcwb. lv_zcwb = ls_tab-zwcha. CALL FUNCTION 'ZFUNC_006' EXPORTING id_data = lv_zcwb TABLES lines = lt_lines. "考虑预留的2个标准文本字段,从第三行开始写入长文本 DO 2 TIMES. ls_ltx-identifier = ls_stpo-item_no. ls_ltx-object_id = '2'. ls_ltx-tdformat = '*'.. CASE sy-index. WHEN '1'. ls_ltx-tdline = ''. WHEN '2'. ls_ltx-tdline = ''. ENDCASE. APPEND ls_ltx TO lt_ltx. CLEAR ls_ltx. ENDDO. LOOP AT lt_lines INTO ls_lines.. MOVE-CORRESPONDING ls_lines TO ls_ltx. ls_ltx-identifier = ls_stpo-item_no. ls_ltx-object_id = '2'. ls_ltx-tdformat = '*'. APPEND ls_ltx TO lt_ltx. CLEAR ls_ltx. ENDLOOP. APPEND ls_stpo TO lt_stpo. * ENDIF . ENDLOOP. IF lt_stpox[] IS NOT INITIAL. LOOP AT lt_stpox INTO ls_stpox ."WHERE XLOEK = SPACE. CLEAR t_tab. CHECK ls_stpox-matkl <> '331001' . CHECK ls_stpox-matkl <> '191001' . * READ TABLE T_TAB WITH KEY IDNRK = LS_STPOX-IDNRK. READ TABLE t_tab WITH KEY posnr = ls_stpox-posnr . IF sy-subrc <> 0. CLEAR: ls_stpo. ls_stpo-item_categ = ls_stpox-postp. " 项目类别 ls_stpo-bom_no = ls_cstmat-stlnr. ls_stpo-component = ls_stpox-idnrk. ls_stpo-item_node = ls_stpox-stlkn. ls_stpo-item_count = ls_stpox-stpoz. ls_stpo-fldelete = 'X'. ls_stpo-change_no = i_input-aennr. " 变更编号 ls_stpo-identifier = ls_stpox-index . APPEND ls_stpo TO lt_stpo. ENDIF. ENDLOOP. ENDIF. CALL FUNCTION 'CALO_INIT_API' EXCEPTIONS log_object_not_found = 1 log_sub_object_not_found = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. * IF LT_STPO[] IS INITIAL . * E_OUTPUT-STA = 'E'. * E_OUTPUT-MESSAGE = '没有操作的行项目'. * ELSE . CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN' EXPORTING material = lv_material plant = i_input-werks bom_usage = lv_stlan "I_INPUT-stlan alternative = lv_stlal "I_INPUT-stlal valid_from = lv_datfm change_no = i_input-aennr i_stko = ls_stko fl_bom_create = lv_creat fl_new_item = 'X' fl_complete = 'X' fl_default_values = '' "add by lanjc 20211023 不按默认值取值 IMPORTING fl_warning = lv_flwarning TABLES t_stpo = lt_stpo t_ltx_line = lt_ltx EXCEPTIONS error = 1 OTHERS = 2. IF sy-subrc <> 0. 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 = lv_msg. IF sy-msgid EQ space. e_output-sta = 'E'. e_output-message = sy-msgid && ':' && sy-msgno && '未知系统错误!'. ELSE. * e_msg = lv_msg. CLEAR: lt_message, lt_message[]. CALL FUNCTION 'CALO_LOG_READ_MESSAGES' EXPORTING log_class = '4' language = sy-langu TABLES messages_and_parameters = lt_message EXCEPTIONS warning = 1 error = 2 OTHERS = 3. LOOP AT lt_message INTO ls_message WHERE ( msg_type = 'E' OR ( msg_type = 'I' AND msg_id EQ '29' AND msg_no EQ '854' ) ) AND msg_id NE 'CL'." OR msg_type = 'I'. e_output-message = e_output-message && ls_message-msg_txt. ENDLOOP. e_output-sta = 'E'. * APPEND LINES OF LT_MESSAGE TO ET_MESSAGE. ENDIF. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CLEAR: lt_message, lt_message[]. CALL FUNCTION 'CALO_LOG_READ_MESSAGES' EXPORTING log_class = '4' language = sy-langu TABLES messages_and_parameters = lt_message EXCEPTIONS warning = 1 error = 2 OTHERS = 3. LOOP AT lt_message INTO ls_message WHERE ( msg_type = 'E' OR ( msg_type = 'I' AND msg_id EQ '29' AND msg_no EQ '854' ) ) AND msg_id NE 'CL'. IF ls_message-msg_type EQ 'E' OR ls_message-msg_type EQ 'A'. e_output-sta = 'E'. ENDIF. e_output-message = e_output-message && ls_message-msg_txt. ENDLOOP. * APPEND LINES OF LT_MESSAGE TO ET_MESSAGE. IF e_output-sta NE space."有错误信息 CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. e_output-sta = 'S'. e_output-message = 'BOM创建/修改成功!'. ENDIF. ENDIF. * ENDIF . lv_msg = e_output-message . zmac-rfc-log-e e_output-sta lv_msg lv_material i_input-werks ''. ENDFUNCTION.
删除BOM(整个):CSAP_MAT_BOM_DELETE
FORM prm_delete_bom CHANGING ps_out LIKE gs_out. DATA: l_ecsin LIKE csin. DATA: lv_msg TYPE char200. DATA:lt_stpo TYPE TABLE OF stpo_api02, ls_stko TYPE stko_api02, ls_stko2 TYPE stko_api01, lv_flwarning TYPE capiflag-flwarning, lt_stpo2 TYPE TABLE OF stpo_api03, ls_stpo2 TYPE stpo_api03, lv_datum TYPE csap_mbom-datuv. IF ps_out-stlal IS INITIAL. ps_out-stlal = '01'. ENDIF. lv_datum = sy-datum. * SELECT COUNT(*) * FROM mast * WHERE matnr = ps_out-matnr * AND werks = ps_out-werks * AND stlan = ps_out-stlan * AND stlal = ps_out-stlal. * * IF sy-subrc <> 0. "不存在 * ps_out-msg = '删除成功!'. * ps_out-ICON = icon_green_light. * ps_out-TYPE = 'S'. * EXIT.. * ENDIF. SET UPDATE TASK LOCAL. * CALL FUNCTION 'CSAP_MAT_BOM_DELETE' * EXPORTING * material = ps_out-matnr * plant = ps_out-werks * bom_usage = ps_out-stlan * alternative = ps_out-stlal * fl_commit_and_wait = 'X' * EXCEPTIONS * error = 1 * OTHERS = 2. "打开 BOM CALL FUNCTION 'CSAP_MAT_BOM_OPEN' EXPORTING material = ps_out-matnr plant = ps_out-werks bom_usage = ps_out-stlan alternative = ps_out-stlal valid_from = lv_datum IMPORTING o_stko = ls_stko TABLES t_stpo = lt_stpo EXCEPTIONS error = 1 OTHERS = 2. IF sy-subrc <> 0. CLEAR: lv_msg. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg. ps_out-msg = '删除失败:' && lv_msg. ps_out-icon = icon_green_light. ps_out-type = 'S'. EXIT. ELSE. SORT lt_stpo BY item_no. READ TABLE lt_stpo INTO DATA(ls_stpo) WITH KEY item_no = ps_out-posnr BINARY SEARCH. IF sy-subrc EQ 0. "打删除标记 ls_stpo-fldelete = 'X'. CLEAR:ls_stko2. MOVE-CORRESPONDING ls_stko TO ls_stko2. CLEAR:lt_stpo2,ls_stpo2. MOVE-CORRESPONDING ls_stpo TO ls_stpo2. APPEND ls_stpo2 TO lt_stpo2. "BOM更新 CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN' EXPORTING material = ps_out-matnr plant = ps_out-werks bom_usage = ps_out-stlan "I_INPUT-stlan alternative = ps_out-stlal "I_INPUT-stlal valid_from = lv_datum change_no = ls_stpo-change_no i_stko = ls_stko2 * fl_bom_create = lv_creat * fl_new_item = 'X' * fl_complete = 'X' * fl_default_values = '' "add by lanjc 20211023 不按默认值取值 IMPORTING fl_warning = lv_flwarning TABLES t_stpo = lt_stpo2 * t_ltx_line = lt_ltx EXCEPTIONS error = 1 OTHERS = 2. IF sy-subrc NE 0. CLEAR: lv_msg. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg. ps_out-msg = '删除失败:' && lv_msg. ps_out-icon = icon_green_light. ps_out-type = 'S'. EXIT. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ps_out-msg = '删除成功!'. ps_out-icon = icon_green_light. ps_out-type = 'S'. EXIT. ENDIF. ENDIF. ENDIF. ENDFORM.