ABAP:CO11N,CO13保存前增强
SE18:WORKORDER_CONFIRM
METHOD if_ex_workorder_confirm~at_save. DATA: s_vornr TYPE RANGE OF resb-vornr . DATA: lv_vornr LIKE LINE OF s_vornr. DATA:lv_gmnga TYPE afru-gmnga, lv_menge TYPE mseg-menge, lv_menge_sum TYPE mseg-menge. DATA:lv_matnr TYPE mara-matnr. DATA:lv_string TYPE string, lv_message TYPE bapi_msg. DATA:lt_mara TYPE TABLE OF mara, ls_mara LIKE LINE OF lt_mara. "[MOD-01] 07.02.2023 13:05:48 YSX 部分财务人员调账不需要执行齐套检查。 AUTHORITY-CHECK OBJECT 'ZPP004' ID 'ZFLG_QX' FIELD 'X'. IF sy-subrc <> 0 AND sy-tcode EQ 'CO11N'. SELECT COUNT(*) FROM aufk WHERE aufnr = is_confirmation-aufnr AND auart NOT IN ( 'ZC04', 'ZC07', 'ZD04', 'ZD07', 'ZY04', 'ZY07' ). IF sy-subrc = 0. IF is_confirmation-werks = '8020'. lv_vornr-sign = 'I'. lv_vornr-option = 'EQ'. lv_vornr-low = is_confirmation-vornr. APPEND lv_vornr TO s_vornr. CLEAR lv_vornr. ENDIF. SELECT bdmng, aufnr, matnr, charg, rsnum, werks, rspos, rsart, enmng FROM resb INTO TABLE @DATA(lt_resb) WHERE aufnr = @is_confirmation-aufnr AND vornr IN @s_vornr AND rgekz = '' AND xloek = '' AND dumps = '' AND schgt = '' AND kzear = '' AND shkzg <> 'S' AND bdmng > 0 AND dbskz <> 'E'. IF lt_resb IS NOT INITIAL. SELECT aufnr, wemng, psmng FROM afpo INTO TABLE @DATA(lt_afpo) WHERE aufnr = @is_confirmation-aufnr. SELECT SINGLE SUM( gmnga ) FROM afru INTO @DATA(lv_gmnga_a) WHERE aufnr = @is_confirmation-aufnr AND vornr = @is_confirmation-vornr AND stzhl = ''. SELECT SINGLE SUM( gmnga ) FROM afru INTO @DATA(lv_gmnga_b) WHERE aufnr = @is_confirmation-aufnr AND vornr = @is_confirmation-vornr AND stzhl <> ''. CLEAR lv_gmnga. lv_gmnga = lv_gmnga_a - lv_gmnga_b. LOOP AT lt_resb ASSIGNING FIELD-SYMBOL(<ls_resb>). CLEAR lv_menge. READ TABLE lt_afpo ASSIGNING FIELD-SYMBOL(<ls_afpo>) WITH KEY aufnr = <ls_resb>-aufnr. IF sy-subrc = 0. IF <ls_afpo>-psmng <> 0. SELECT SINGLE SUM( menge ) FROM mseg INTO @DATA(lv_menge_261) WHERE rsnum = @<ls_resb>-rsnum AND rspos = @<ls_resb>-rspos AND bwart = '261'. SELECT SINGLE SUM( menge ) FROM mseg INTO @DATA(lv_menge_262) WHERE rsnum = @<ls_resb>-rsnum AND rspos = @<ls_resb>-rspos AND bwart = '262'. lv_menge = lv_menge_261 - lv_menge_262. CLEAR:lv_menge_261,lv_menge_262. lv_menge_sum = ( lv_gmnga + is_confirmation-lmnga + is_confirmation-xmnga ) * <ls_resb>-bdmng / <ls_afpo>-psmng. IF lv_menge_sum > lv_menge. * lv_type = 'E'. ls_mara-matnr = <ls_resb>-matnr. APPEND ls_mara TO lt_mara. CLEAR ls_mara. * CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' * EXPORTING * input = <ls_resb>-matnr * IMPORTING * output = lv_matnr. * es_return-type = 'E'. * PERFORM frm_alpha_output(zpub_f01) IF FOUND CHANGING <ls_resb>-matnr. * es_return-msg = '此工单未发料齐套!请检查发料' && <ls_resb>-matnr. ENDIF. ENDIF. ENDIF. ENDLOOP. ENDIF. ENDIF. IF lt_mara IS NOT INITIAL. LOOP AT lt_mara INTO ls_mara. CONCATENATE lv_string ls_mara-matnr ';' INTO lv_string. ENDLOOP. "此工单未发料齐套!请检查发料' && <ls_resb>-matnr. MESSAGE e005(zpp) DISPLAY LIKE 'E' WITH lv_string . ENDIF. ENDIF. *****ADD BY ZJ 20230519 S 外协工序报工检查 AUTHORITY-CHECK OBJECT 'ZPP004' ID 'ZFLG_QX' FIELD 'X'. IF sy-subrc <> 0. IF sy-tcode EQ 'CO11N' AND ( is_confirmation-werks EQ '8000' OR is_confirmation-werks EQ '8010' OR is_confirmation-werks EQ '8020' ). SELECT COUNT(*) FROM afko AS a INNER JOIN afvc AS b ON a~aufpl EQ b~aufpl WHERE a~aufnr EQ is_confirmation-aufnr AND b~steus EQ 'ZP02'. IF sy-subrc EQ 0. DATA:lv_menge2 TYPE eket-menge. "GMNGA数据 SELECT SINGLE SUM( CASE stzhl WHEN '00000000' THEN gmnga ELSE gmnga * -1 END ) FROM afru INTO @DATA(lv_gmnga2) WHERE aufnr = @is_confirmation-aufnr AND vornr = @is_confirmation-vornr. "XMNGA数据 SELECT SINGLE SUM( CASE stzhl WHEN '00000000' THEN xmnga ELSE xmnga * -1 END ) FROM afru INTO @DATA(lv_xmnga) WHERE aufnr = @is_confirmation-aufnr AND vornr = @is_confirmation-vornr. "查询EBAN是否下发采购订单 SELECT c~ebeln FROM afko AS a INNER JOIN afvc AS b ON a~aufpl EQ b~aufpl INNER JOIN eban AS c ON b~banfn EQ c~banfn AND b~bnfpo EQ c~bnfpo INTO TABLE @DATA(lt_eban) WHERE a~aufnr EQ @is_confirmation-aufnr AND b~steus EQ 'ZP02'. "如果存在EBELN为空的数据 READ TABLE lt_eban TRANSPORTING NO FIELDS WITH KEY ebeln = ''. IF sy-subrc EQ 0. MESSAGE '工单外协工序收料不齐套' TYPE 'E'. ELSE. "查询EKET数据 SELECT c~menge,c~wemng FROM afko AS a LEFT JOIN afvc AS b ON a~aufpl EQ b~aufpl LEFT JOIN eket AS c ON b~banfn EQ c~banfn AND b~bnfpo EQ c~bnfpo LEFT JOIN ekpo AS d ON d~banfn EQ c~banfn AND d~bnfpo EQ c~bnfpo INTO TABLE @DATA(lt_eket) WHERE a~aufnr EQ @is_confirmation-aufnr AND b~steus EQ 'ZP02' AND d~loekz NE 'L' AND d~retpo NE 'X'. LOOP AT lt_eket INTO DATA(ls_eket). lv_menge2 = lv_menge2 + ls_eket-wemng. CLEAR:ls_eket. ENDLOOP. lv_gmnga2 = lv_gmnga2 + lv_xmnga + is_confirmation-lmnga + is_confirmation-xmnga. IF lv_gmnga2 > lv_menge2. MESSAGE '工单外协工序收料不齐套' TYPE 'E'. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. *****ADD BY ZJ 20230519 E 外协工序报工检查 ENDMETHOD.