Есть функциональные модули COHU_ASSIGN_HU и COHU_HU_UPDATE.
METHOD hu_assign. " iv_aufnr TYPE aufnr " iv_exidv TYPE exidv " rv_error TYPE abap_bool DATA: lt_bereithu TYPE TABLE OF bereithu, lt_afvc TYPE TABLE OF afvc, lt_resb TYPE TABLE OF resb, ls_vekp TYPE vekp, lt_vepo TYPE TABLE OF vepo, lt_resb1 TYPE TABLE OF resb. FIELD-SYMBOLS: <fs_bereithu> LIKE LINE OF lt_bereithu, <fs_vepo> LIKE LINE OF lt_vepo, <fs_resb> LIKE LINE OF lt_resb. CHECK iv_aufnr IS NOT INITIAL AND iv_exidv IS NOT INITIAL. SELECT SINGLE * FROM vekp INTO ls_vekp WHERE exidv = iv_exidv. IF sy-subrc <> 0. " Не найдена ЕО rv_error = abap_true. RETURN. ENDIF. SELECT * FROM vepo INTO TABLE lt_vepo WHERE venum = ls_vekp-venum. IF sy-subrc <> 0. " ЕО не имеет позиций rv_error = abap_true. RETURN. ENDIF. SELECT resb~* FROM resb INNER JOIN afko ON resb~rsnum = afko~rsnum INTO TABLE lt_resb1 WHERE afko~aufnr = iv_aufnr. IF sy-subrc <> 0. " Резервирование для заказа не найдено rv_error = abap_true. RETURN. ENDIF. LOOP AT lt_vepo ASSIGNING <fs_vepo>. LOOP AT lt_resb1 ASSIGNING <fs_resb> WHERE matnr = <fs_vepo>-matnr. EXIT. ENDLOOP. IF sy-subrc = 0. INSERT INITIAL LINE INTO TABLE lt_bereithu ASSIGNING <fs_bereithu>. <fs_bereithu>-velin = '1'. <fs_bereithu>-aufnr = iv_aufnr. <fs_bereithu>-rspos = <fs_resb>-rspos. <fs_bereithu>-matnr = <fs_vepo>-matnr. <fs_bereithu>-werks = <fs_vepo>-werks. <fs_bereithu>-charg = <fs_vepo>-charg. <fs_bereithu>-lgort = <fs_vepo>-lgort. <fs_bereithu>-vornr = <fs_resb>-vornr. <fs_bereithu>-menge = <fs_vepo>-vemng. <fs_bereithu>-meins = <fs_vepo>-vemeh. <fs_bereithu>-erfmg = <fs_vepo>-vemng. <fs_bereithu>-erfme = <fs_vepo>-vemeh. <fs_bereithu>-vhilm = ls_vekp-vhilm. <fs_bereithu>-exidv_ob = ls_vekp-exidv. <fs_bereithu>-twflg = 'X'. * <fs_bereithu>-rsnum = <fs_resb>-rsnum. <fs_bereithu>-venum = <fs_vepo>-venum. <fs_bereithu>-vepos = <fs_vepo>-vepos. INSERT <fs_resb> INTO TABLE lt_resb. READ TABLE lt_afvc TRANSPORTING NO FIELDS WITH KEY aufpl = <fs_resb>-aufpl. IF sy-subrc <> 0. SELECT * FROM afvc APPENDING TABLE lt_afvc WHERE aufpl = <fs_resb>-aufpl. ENDIF. ENDIF. ENDLOOP. CALL FUNCTION 'COHU_HU_REFRESH'. CALL FUNCTION 'COHU_ASSIGN_HU' EXPORTING i_aufnr = iv_aufnr i_exidv = iv_exidv TABLES t_bereithu = lt_bereithu t_afvc = lt_afvc t_resb = lt_resb EXCEPTIONS error = 1 OTHERS = 2. IF sy-subrc = 0. CALL FUNCTION 'COHU_HU_UPDATE' EXPORTING i_aufnr = iv_aufnr * i_synchron = * i_check = * i_no_hu_update = ' ' * i_cancel = ' ' * i_pi_sheet = * IMPORTING * batch_data_only = TABLES t_resb = lt_resb t_afvc = lt_afvc EXCEPTIONS not_necessary = 1 error = 2 OTHERS = 3. IF sy-subrc = 0. " Успешно bapi_commit( ). ELSE. " Ошибка rv_error = abap_true. bapi_rollback( ). ENDIF. ELSE. " Ошибка rv_error = abap_true. bapi_rollback( ). ENDIF. CALL FUNCTION 'COHU_HU_REFRESH'. ENDMETHOD.
Комментариев нет:
Отправить комментарий