DATA:lt_bom TYPE TABLE OF typ_out. DATA: lv_datum TYPE sy-datum, lv_message TYPE char128, lv_date TYPE csap_mbom-datuv. DATA: ls_stko TYPE stko_api01, ls_warning TYPE capiflag-flwarning, ls_stko2 TYPE stko_api02. lv_datum = sy-datum . IF sy-batch IS NOT INITIAL. LOOP AT gt_out INTO gs_out. IF gs_out-stktx < lv_datum AND gs_out-stktx IS NOT INITIAL. APPEND gs_out TO lt_bom. CLEAR gs_out. ENDIF. ENDLOOP. ELSE. LOOP AT gt_out INTO gs_out WHERE cbox = 'X'. IF gs_out-stktx < lv_datum AND gs_out-stktx IS NOT INITIAL. APPEND gs_out TO lt_bom. CLEAR gs_out. ENDIF. ENDLOOP. ENDIF. LOOP AT lt_bom ASSIGNING FIELD-SYMBOL(<fs_bom>). CLEAR: ls_stko,lv_date,lv_message. ls_stko-base_quan = <fs_bom>-bmeng. ls_stko-alt_text = <fs_bom>-stktx. ls_stko-bom_status = '02'. * lv_date = <fs_bom>-datuv. * lv_date = sy-datum. WRITE SY-DATUM TO lv_date. CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN' EXPORTING material = <fs_bom>-matnr plant = <fs_bom>-werks bom_usage = <fs_bom>-stlan alternative = <fs_bom>-stlal valid_from = lv_date i_stko = ls_stko fl_commit_and_wait = 'X' fl_default_values = 'X' IMPORTING fl_warning = ls_warning o_stko = ls_stko2 EXCEPTIONS error = 1 OTHERS = 2. 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_message. IF sy-subrc <> 0. gs_out-type = 'E'. gs_out-msg = '更新失败:' && lv_message. MODIFY gt_out FROM gs_out TRANSPORTING type msg WHERE matnr = <fs_bom>-matnr AND werks = <fs_bom>-werks. ELSE. SEARCH lv_message FOR 'changed'. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. gs_out-type = 'S'. gs_out-stlst = '02'. gs_out-msg = '更新成功:'&& lv_message . MODIFY gt_out FROM gs_out TRANSPORTING type stlst msg WHERE matnr = <fs_bom>-matnr AND werks = <fs_bom>-werks. ELSE. gs_out-type = 'E'. gs_out-msg = '更新失败:' && lv_message. MODIFY gt_out FROM gs_out TRANSPORTING type msg WHERE matnr = <fs_bom>-matnr AND werks = <fs_bom>-werks. ENDIF. ENDIF. ENDLOOP.
标签:sy,gs,批量,CS02,ls,stko,lv,BOM,out From: https://www.cnblogs.com/Anyohh233/p/18307539