REPORT Z_PO_CREATE.
tables: zsdgm_table_23 .
data: begin of upload_line,
doc_type like bapimepoitem-trackingno, "采购类型
purch_org like bapimepoheader-purch_org, "采购组织
pur_group like bapimepoheader-pur_group, "采购组
comp_code like bapimepoheader-comp_code, "公司代码
vendor like bapimepoheader-vendor, "供应商代码
name like bapimepoaddrvendor-name, "供应商名称
material like bapimepoitem-material, "物料号
short_text like bapimepoitem-short_text, "物料描述
quantity like bapimepoitem-quantity, "订单数量
batch like bapimepoitem-batch, "批次
po_unit like bapimepoitem-po_unit, "采购单位
delivery_date like bapimeposchedule-delivery_date, "交货日期
fa_code(20) type c, "发票号码
net_price like bapimepoitem-net_price, "净价
currency like bapimepoheader-currency, "货币
price_unit like bapimepoitem-price_unit, "价格单位
tax_code like bapimepoitem-tax_code, "税码
plant like bapimepoitem-plant, "工厂
trackingno like bapimepoitem-trackingno, "需求跟踪号
preq_name like bapimepoitem-preq_name, "申请者
ref_1 like bapimepoheader-ref_1, "你的参考号
end of upload_line.
data: upload_itab like upload_line occurs 0 with header line.
field-symbols: like upload_line.
data: bapimepoheader like bapimepoheader,
bapimepoheaderx like bapimepoheaderx,
bapimepoitem like bapimepoitem occurs 0 with header line,
bapimepoitemx like bapimepoitemx occurs 0 with header line,
bapimeposchedule like bapimeposchedule occurs 0 with header line,
bapimeposchedulx like bapimeposchedulx occurs 0 with header line,
bapimepoaccount like bapimepoaccount occurs 0 with header line,
bapimepoaccountx like bapimepoaccountx occurs 0 with header line,
bapiret2 like bapiret2 occurs 0 with header line,
bapiret_line like bapiret2.
data: begin of kostl_line,
bukrs like zsdgm_table_23-bukrs,
kostl like zsdgm_table_23-kostl,
end of kostl_line.
data: kostl_itab like kostl_line occurs 0 with header line.
data: po_item like bapimepoitem-po_item,
sched_line like bapimeposchedule-sched_line,
serial_no like bapimepoaccount-serial_no.
data: begin of result_line,
result_info(220) type c,
end of result_line.
data: result_itab like result_line occurs 0 with header line.
selection-screen begin of block b1 with frame title text-001.
parameters: p_po like rlgrap-filename obligatory.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters: p_header radiobutton group gro1,
p_nohead radiobutton group gro1.
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-003.
parameters: p_front radiobutton group gro2,
p_end radiobutton group gro2 default 'X'.
selection-screen end of block b3.
initialization.
at selection-screen on value-request for p_po.
perform get_filepath.
start-of-selection.
perform get_data.
perform operation_data.
perform output_info.
*&---------------------------------------------------------------------*
*& Form GET_FILEPATH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_filepath .
call function 'WS_FILENAME_GET'
exporting
def_filename = p_po
def_path = 'C:\'
mask = ',*.dat.'
mode = 'O'
title = 'Select PO Upload Excel File'
importing
filename = p_po
* RC =
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
endform. " GET_FILEPATH
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
data: l_doctype like bapimepoitem-trackingno,
l_trackingno like bapimepoitem-trackingno.
refresh: kostl_itab[], result_itab[].
clear: kostl_itab, result_itab.
call function 'WS_UPLOAD'
exporting
filename = p_po
filetype = 'DAT'
tables
data_tab = upload_itab
exceptions
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
others = 10.
if p_header eq 'X'.
delete upload_itab index 1.
endif.
loop at upload_itab assigning .
clear:l_doctype, l_trackingno.
l_doctype = -doc_type.
l_trackingno = -trackingno.
-doc_type = l_trackingno.
-trackingno = l_doctype.
endloop.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form ADD_BAPIMEPOHEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form add_bapimepoitem.
po_item = po_item + 10.
bapimepoitem-po_item = po_item.
bapimepoitem-material = upload_line-material.
bapimepoitem-quantity = upload_line-quantity.
bapimepoitem-batch = upload_line-batch.
bapimepoitem-po_unit = upload_line-po_unit.
bapimepoitem-net_price = upload_line-net_price.
bapimepoitem-price_unit = upload_line-price_unit.
bapimepoitem-tax_code = 'JA'.
bapimepoitem-plant = upload_line-plant.
bapimepoitem-trackingno = upload_line-doc_type.
bapimepoitem-preq_name = upload_line-preq_name.
bapimepoitemx-po_item = po_item.
bapimepoitemx-po_itemx = 'X'.
bapimepoitemx-material = 'X'.
bapimepoitemx-quantity = 'X'.
bapimepoitemx-batch = 'X'.
bapimepoitemx-po_unit = 'X'.
bapimepoitemx-net_price = 'X'.
bapimepoitemx-price_unit = 'X'.
bapimepoitemx-tax_code = 'X'.
bapimepoitemx-plant = 'X'.
bapimepoitemx-trackingno = 'X'.
bapimepoitemx-preq_name = 'X'.
if upload_itab-batch eq 'L0' or upload_itab-batch eq '90'.
bapimepoitem-acctasscat = 'K'.
bapimepoitemx-acctasscat = 'X'.
clear kostl_line.
read table kostl_itab into kostl_line with key bukrs = upload_itab-comp_code binary search.
serial_no = serial_no + 1.
bapimepoaccount-po_item = po_item.
bapimepoaccount-serial_no = serial_no.
bapimepoaccount-costcenter = kostl_line-kostl.
bapimepoaccount-gl_account = '6666053002'.
bapimepoaccountx-po_item = po_item.
bapimepoaccountx-serial_no = serial_no.
bapimepoaccountx-po_itemx = 'X'.
bapimepoaccountx-serial_nox = 'X'.
bapimepoaccountx-costcenter = 'X'.
bapimepoaccountx-gl_account = 'X'.
append: bapimepoaccount, bapimepoaccountx.
clear: bapimepoaccount, bapimepoaccountx.
endif.
append: bapimepoitem, bapimepoitemx.
clear: bapimepoitem, bapimepoitemx.
sched_line = sched_line + 10.
bapimeposchedule-po_item = po_item.
bapimeposchedule-sched_line = sched_line.
bapimeposchedule-delivery_date = upload_line-delivery_date.
bapimeposchedulx-po_item = po_item.
bapimeposchedulx-sched_line = sched_line.
bapimeposchedulx-po_itemx = 'X'.
bapimeposchedulx-sched_linex = 'X'.
bapimeposchedulx-delivery_date = 'X'.
append: bapimeposchedule, bapimeposchedulx.
clear: bapimeposchedule, bapimeposchedulx.
endform. " ADD_BAPIMEPOHEADER
*&---------------------------------------------------------------------*
*& Form EXEC_BAPI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form exec_bapi .
call function 'BAPI_PO_CREATE1'
exporting
poheader = bapimepoheader
poheaderx = bapimepoheaderx
importing
expheader = bapimepoheader
tables
return = bapiret2
poitem = bapimepoitem
poitemx = bapimepoitemx
poschedule = bapimeposchedule
poschedulex = bapimeposchedulx
poaccount = bapimepoaccount
poaccountx = bapimepoaccountx.
clear bapiret_line.
loop at bapiret2 into bapiret_line where type eq 'A' or type eq 'E'.
concatenate '跟踪号' bapimepoitem-trackingno ':' bapiret_line-message space into result_itab-result_info.
append result_itab.
clear result_itab.
endloop.
if sy-subrc eq 0.
call function 'BAPI_TRANSACTION_ROLLBACK'.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
clear bapiret_line.
read table bapiret2 into bapiret_line with key type = 'S'.
concatenate '跟踪号' bapimepoitem-trackingno ':' bapiret_line-message into result_itab-result_info.
append result_itab.
clear result_itab.
endif.
endform. " EXEC_BAPI
*&---------------------------------------------------------------------*
*& Form OUTPUT_INFO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form output_info .
loop at result_itab.
write:/ result_itab-result_info.
endloop.
endform. " OUTPUT_INFO
*&---------------------------------------------------------------------*
*& Form OPERATION_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form operation_data .
select bukrs kostl into table kostl_itab
from zsdgm_table_23
for all entries in upload_itab
where bukrs eq upload_itab-comp_code.
sort upload_itab by doc_type.
loop at upload_itab.
move upload_itab to upload_line.
at new doc_type.
clear: bapimepoheader, bapimepoheaderx.
refresh: bapimepoitem[], bapimepoitemx[], bapimeposchedule[], bapimeposchedulx[], bapimepoaccount[], bapimepoaccountx[].
clear: bapimepoitem, bapimepoitemx, bapimeposchedule, bapimeposchedulx, bapimepoaccount, bapimepoaccountx, po_item, sched_line, serial_no.
bapimepoheader-doc_type = upload_line-trackingno.
bapimepoheader-purch_org = upload_line-purch_org.
bapimepoheader-pur_group = upload_line-pur_group.
bapimepoheader-comp_code = upload_line-comp_code.
bapimepoheader-vendor = upload_line-vendor.
bapimepoheader-currency = 'CNY'.
bapimepoheader-ref_1 = upload_line-ref_1.
bapimepoheaderx-doc_type = 'X'.
bapimepoheaderx-purch_org = 'X'.
bapimepoheaderx-pur_group = 'X'.
bapimepoheaderx-comp_code = 'X'.
bapimepoheaderx-vendor = 'X'.
bapimepoheaderx-currency = 'X'.
bapimepoheaderx-ref_1 = 'X'.
endat.
perform add_bapimepoitem.
at end of doc_type.
perform exec_bapi.
endat.
endloop.
endform. " OPERATION_DATA
阅读(1682) | 评论(0) | 转发(1) |