MM模块:
BAPI_PO_CREATE1
DATA:"PO BAPI参数 lv_ebeln TYPE ebeln, ls_poheader TYPE bapimepoheader, ls_poheaderx TYPE bapimepoheaderx, ls_potext TYPE bapimepotext, lt_poitem LIKE TABLE OF bapimepoitem WITH HEADER LINE, lt_poitemx TYPE TABLE OF bapimepoitemx WITH HEADER LINE, lt_potext TYPE TABLE OF bapimepotext, lt_poschedule TYPE TABLE OF bapimeposchedule WITH HEADER LINE, lt_poschedulex TYPE TABLE OF bapimeposchedulx WITH HEADER LINE, lt_pocond TYPE TABLE OF bapimepocond, lt_pocondx TYPE TABLE OF bapimepocondx, lt_pocomponents TYPE TABLE OF bapimepocomponent, lt_pocomponentsx TYPE TABLE OF bapimepocomponentx, "通用 lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE, lv_msg TYPE bapi_msg. LOOP AT p_gt_checkabox_po_header ASSIGNING FIELD-SYMBOL(<fs1>).. *&---------------------------------------------------------------------* * PO create CLEAR:lv_ebeln,l_labor,l_werks,l_lifnr,i_bukrs. SELECT SINGLE bukrs INTO i_bukrs FROM t001k WHERE bwkey = <fs1>-kunnr."公司代码 l_labor = <fs1>-labor." l_werks = <fs1>-kunnr..""门店,工厂 l_lifnr = <fs1>-lifnr."供应商 ls_poheader = VALUE #( doc_type = COND #( WHEN l_labor = '001' THEN 'ZTB' ELSE 'GB' )""采购凭证类型 * vendor = |{ ls_item-s_werks ALPHA = IN }| "ls_item-s_werks vendor = COND #( WHEN ls_poheader-doc_type = 'ZTB' THEN |0000010001| ELSE |{ <fs1>-lifnr ALPHA = IN } | ) purch_org = '1000' "采购组织 pur_group = '101' "采购组 comp_code = i_bukrs currency = 'CNY' doc_date = sy-datum "采购凭证日期 langu = sy-langu status = 'I' ). ls_poheaderx = VALUE #( doc_type = 'X' vendor = 'X' purch_org = 'X' pur_group = 'X' comp_code = 'X' currency = 'X' doc_date = 'X' langu = 'X' status = 'X' ). REFRESH: lt_poitem,lt_poitemx, lt_poschedule,lt_poschedulex,lt_return,lt_potext. CLEAR: lv_cnt,lv_cnt_item. LOOP AT p_gt_checkabox_po_items WHERE kunnr = <fs1>-kunnr AND zshdh = <fs1>-zshdh AND lifnr = <fs1>-lifnr.. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = p_gt_checkabox_po_items-matnr IMPORTING output = p_gt_checkabox_po_items-matnr. lv_cnt = lv_cnt + 1. lv_cnt_item = lv_cnt * 10. lt_poitem-po_item = lv_cnt_item. lt_poitem-material = p_gt_checkabox_po_items-matnr. lt_poitem-plant = l_werks. lt_poitem-stge_loc = 1000. lt_poitem-quantity = p_gt_checkabox_po_items-zcysl. lt_poitem-po_unit = p_gt_checkabox_po_items-meins."单位 lt_poitem-ret_item = 'X'. lt_poitem-net_price = p_gt_checkabox_po_items-zdj. APPEND lt_poitem . lt_poitemx-po_item = lv_cnt_item. lt_poitemx-material = 'X'. lt_poitemx-plant = 'X'. lt_poitemx-stge_loc = 'X'. lt_poitemx-quantity = 'X'. lt_poitemx-po_unit = 'X'. lt_poitemx-ret_item = 'X'. lt_poitemx-net_price = 'X'. APPEND lt_poitemx . lt_poschedule-po_item = lv_cnt_item. * lt_poschedule-delivery_date = p_gt_checkabox_po_items-zdbrq. lt_poschedule-delivery_date = sy-datum. APPEND lt_poschedule. lt_poschedulex-po_item = lv_cnt_item. * lt_poschedulex-delivery_date = p_gt_checkabox_po_items-zdbrq. lt_poschedulex-delivery_date = sy-datum.. APPEND lt_poschedulex. CLEAR: lt_poitem,lt_poitemx, lt_poschedule,lt_poschedulex. ls_potext-text_id = 'F01'. ls_potext-text_line = p_gt_checkabox_po_items-zshdh."退货单号 ls_potext-po_item = lv_cnt_item. APPEND ls_potext TO lt_potext. CLEAR:ls_potext. ENDLOOP. CALL FUNCTION 'BAPI_PO_CREATE1' EXPORTING poheader = ls_poheader poheaderx = ls_poheaderx IMPORTING exppurchaseorder = lv_ebeln * EXPHEADER = * EXPPOEXPIMPHEADER = TABLES return = lt_return poitem = lt_poitem poitemx = lt_poitemx * POADDRDELIVERY = poschedule = lt_poschedule poschedulex = lt_poschedulex potextitem = lt_potext. LOOP AT lt_return WHERE type CA 'AE'. ENDLOOP. IF sy-subrc EQ 0. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. e_type = 'E'. e_msg = |采购凭证 { lv_ebeln } 创建失败:{ lt_return-message } |. ELSE. e_type = 'S'. e_msg = |采购凭证 { lv_ebeln } 创建成功 !|.. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ENDIF. *-----------进行过账 DATA:l_flag TYPE char1. CLEAR:l_flag. IF lv_ebeln IS NOT INITIAL. DO 20 TIMES. CALL FUNCTION 'ENQUEUE_EMEKKOE' EXPORTING mode_ekko = 'E' mode_ekpo = 'E' mandt = sy-mandt ebeln = lv_ebeln EXCEPTIONS foreign_lock = 1 system_failure = 2 OTHERS = 3. IF sy-subrc = 0. l_flag = 'X'. EXIT. ENDIF. WAIT UP TO 1 SECONDS. ENDDO. IF l_flag = ''. e_type = 'E'. e_msg = |采购凭证 { lv_ebeln } 被锁定 !|. ENDIF. ENDIF. ENDLOOP.
BAPI_GOODSMVT_CREATE
DATA:l_lines TYPE ekpo-ebelp. DATA e_type TYPE bapi_mtype. DATA:e_msg TYPE bapi_msg. DATA:goodsmvt_header TYPE bapi2017_gm_head_01, goodsmvt_code TYPE bapi2017_gm_code, goodsmvt_headret TYPE bapi2017_gm_head_ret, goodsmvt_item TYPE bapi2017_gm_item_create OCCURS 0 WITH HEADER LINE, return TYPE bapiret2 OCCURS 0 WITH HEADER LINE. goodsmvt_header = VALUE #( pstng_date = sy-datum doc_date = sy-datum ). LOOP AT p_gt_checkabox_po_items WHERE kunnr = <fs1>-kunnr AND zshdh = <fs1>-zshdh. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = p_gt_checkabox_po_items-matnr IMPORTING output = p_gt_checkabox_po_items-matnr. l_lines = l_lines + 00010. goodsmvt_item = VALUE #( material = p_gt_checkabox_po_items-matnr stge_loc = '1000' "库存地点 move_type = '101' plant = p_gt_checkabox_po_items-kunnr entry_qnt = p_gt_checkabox_po_items-zcysl po_number = lv_ebeln po_item = l_lines entry_uom = p_gt_checkabox_po_items-meins mvt_ind = 'B' ). APPEND goodsmvt_item. ENDLOOP . goodsmvt_code = '01'. CALL FUNCTION 'BAPI_GOODSMVT_CREATE' EXPORTING goodsmvt_header = goodsmvt_header goodsmvt_code = goodsmvt_code * TESTRUN = ' ' * GOODSMVT_REF_EWM = IMPORTING goodsmvt_headret = goodsmvt_headret * MATERIALDOCUMENT = * MATDOCUMENTYEAR = TABLES goodsmvt_item = goodsmvt_item * GOODSMVT_SERIALNUMBER = return = return. IF goodsmvt_headret IS NOT INITIAL. e_type = 'S'. e_msg = |物料凭证{ goodsmvt_headret-mat_doc }创建成功;|. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. e_type = 'E'. * error_flag = 'X'. READ TABLE return WITH KEY type = 'E'. IF sy-subrc = 0. e_msg = |物料凭证创建失败,失败原因:{ return-message } |. ENDIF. ENDIF.
<style></style>
<style></style>