DATA: poheader LIKE bapimepoheader,
poheaderx LIKE bapimepoheaderx,
poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
poitemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,
poschedule LIKE bapimeposchedule OCCURS 0 WITH HEADER LINE,
poschedulex LIKE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
pomepocond LIKE bapimepocond OCCURS 0 WITH HEADER LINE,
pomepocondx LIKE bapimepocondx OCCURS 0 WITH HEADER LINE,
potextitem LIKE bapiekpotx OCCURS 0 WITH HEADER LINE.
CLEAR: poheader, poheaderx, poitem, poitemx,
poschedule, poschedulex, pomepocond, pomepocondx, potextitem,
return.
REFRESH: poitem, poitemx, poschedule ,poschedulex, pomepocond, pomepocondx, potextitem, return.
DATA: t_ebelp LIKE ekpo-ebelp.
*****PO HEAD
poheader-comp_code = po_head-comp_code.
poheader-doc_type = 'Z3'.
poheader-vendor = po_head-lifnr.
poheader-purch_org = po_head-purch_org.
poheader-pur_group = po_head-pur_group.
poheader-doc_date = po_head-bedat. "凭证日期
poheaderx-comp_code = 'X'.
poheaderx-doc_type = 'X'.
poheaderx-vendor = 'X'.
poheaderx-purch_org = 'X'.
poheaderx-pur_group = 'X'.
poheaderx-doc_date = 'X'.
*-----PO item
CLEAR: t_ebelp.
LOOP AT po_item.
poitem-po_item = t_ebelp + '10'.
t_ebelp = poitem-po_item.
poitem-material = po_item-matnr.
poitem-plant = po_item-werks.
poitem-stge_loc = po_item-lgort.
poitem-quantity = po_item-menge.
poitem-po_unit = po_item-meins.
poitem-net_price = po_item-price.
poitem-price_unit = po_item-price_unit.
poitem-po_price = '1'.
poitem-info_rec = po_item-info_rec.
poitem-bras_nbm = po_item-sb_no.
poitem-val_type = po_item-lgort.
poitem-preq_name = po_item-afnam. "申请者
poitem-trackingno = po_item-trackingno.
poitem-plan_del = po_item-plan_del.
poitem-tax_code = po_item-tax_code. "税码
APPEND poitem.
CLEAR: poitem.
poitemx-po_item = t_ebelp.
poitemx-delete_ind = 'X'.
poitemx-material = 'X'.
poitemx-plant = 'X'.
poitemx-stge_loc = 'X'.
poitemx-quantity = 'X'.
poitemx-po_unit = 'X'.
poitemx-net_price = 'X'.
poitemx-price_unit = 'X'.
poitemx-po_price = 'X'.
poitemx-info_rec = 'X'.
poitemx-bras_nbm = 'X'.
poitemx-val_type = 'X'.
poitemx-preq_name = 'X'. "申请者
poitemx-trackingno = 'X'.
poitemx-plan_del = 'X'.
poitemx-tax_code = 'X'. "税码
APPEND poitemx.
CLEAR: poitemx.
poschedule-po_item = t_ebelp.
poschedule-sched_line = 1.
poschedule-quantity = po_item-menge.
poschedule-delivery_date = po_item-delivery_date.
APPEND poschedule.
CLEAR: poschedule.
poschedulex-po_item = t_ebelp.
poschedulex-sched_line = 1.
poschedulex-quantity = 'X'.
poschedulex-delivery_date = 'X'.
APPEND poschedulex.
CLEAR: poschedulex.
potextitem-po_item = t_ebelp.
potextitem-text_id = 'F01'.
potextitem-text_line = po_item-text_line.
APPEND potextitem.
CLEAR: potextitem.
*-------加税
pomepocond-itm_number = t_ebelp.
pomepocond-condition_no = '00001'.
pomepocond-cond_type = 'PBXX'.
pomepocond-cond_value = po_item-price.
pomepocond-cond_p_unt = po_item-price_unit.
pomepocond-currency = 'RMB'.
pomepocond-change_id = 'U'.
APPEND pomepocond.
CLEAR: pomepocond.
pomepocondx-itm_number = t_ebelp.
pomepocondx-condition_no = '00001'.
pomepocondx-cond_type = 'X'.
pomepocondx-cond_value = 'X'.
pomepocondx-cond_p_unt = 'X'.
pomepocondx-currency = 'X'.
pomepocondx-change_id = 'X'.
APPEND pomepocondx.
CLEAR: pomepocondx.
pomepocond-itm_number = t_ebelp.
pomepocond-condition_no = '00001'.
pomepocond-cond_type = 'ZVAT'.
pomepocond-cond_value = po_item-cond_value.
pomepocond-currency = '%'.
pomepocond-change_id = 'U'.
APPEND pomepocond.
CLEAR: pomepocond.
pomepocondx-itm_number = t_ebelp.
pomepocondx-condition_no = '00001'.
pomepocondx-cond_type = 'X'.
pomepocondx-cond_value = 'X'.
pomepocondx-currency = 'X'.
pomepocondx-change_id = 'X'.
APPEND pomepocondx.
CLEAR: pomepocondx.
ENDLOOP.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = poheader
poheaderx = poheaderx
memory_complete = flag_temp
IMPORTING
exppurchaseorder = ebeln
TABLES
return = return
poitem = poitem
poitemx = poitemx
poschedule = poschedule
poschedulex = poschedulex
pocond = pomepocond
pocondx = pomepocondx
potextitem = potextitem.
READ TABLE return WITH KEY type = 'E'.
IF sy-subrc = 0. "有出错信息
LOOP AT return WHERE type = 'E'.
CONCATENATE e_message ',' return-message INTO e_message.
CONDENSE e_message.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WAIT UP TO 2 SECONDS.
ENDIF.