select * into corresponding fields of table it_bkpf from bkpf
where
"gjahr in p_gjahr and
bukrs = p_bukrs
and bstat = p_bstat
and budat in p_dt_la.
if sy-subrc = 0.
loop at it_bkpf into wa_bkpf.
if wa_bkpf-awtyp = 'RMRP' ."and dont is INITIAL.
*MM Invoices *************************
*
*
*---- Construcao da Chave de pesquisa ---- *
*
*
invoicedocnumber = wa_bkpf-awkey(10).
fiscalyear = wa_bkpf-awkey+10(4).
*
*
*---- Ir buscar os dados para a criacao ---- *
*
*
call function 'BAPI_INCOMINGINVOICE_GETDETAIL'
exporting
invoicedocnumber = invoicedocnumber
fiscalyear = fiscalyear
importing
headerdata = headdata_detail
tables
itemdata = itemdata_detail
return = return.
move-corresponding headdata_detail to headdata_create.
*
*
*Some Fields are not passed need to manual
headdata_create-gross_amount = headdata_detail-gross_amnt.
*
*
*Need to change To New Parameters
headdata_create-pstng_date = p_budat.
headdata_create-comp_code = p_b_dst .
clear: headdata_create-inv_doc_no,
*
*
*To Clean for the creation
headdata_create-dsct_days1,
headdata_create-dsct_days2,
headdata_create-dsct_pct1,
headdata_create-dsct_pct2
.
clear return.
*
*
*---- Mudanca dos itens ---- *
*
*
*
*
*The PO number may be different for each item
loop at itemdata_detail into wa_itemdetail.
*
*
*Get the number of the next PO
clear: is_valid,ebeln_sel.
select single ebeln from ekko into ebeln_sel
where unsez = wa_itemdetail-po_number
and bukrs = 'CST'.
if sy-subrc = 0.
***Need To read the detail of the PO
call function 'BAPI_PO_GETDETAIL1'
exporting
purchaseorder = ebeln_sel
account_assignment = 'X'
version = 'X'
services = 'X'
tables
return = return
pohistory = pohistory
poitem = poitem.
read table return with key type = 'E' transporting no fields.
if sy-subrc 0.
*
*
*---- Passa os dados dos itens para a nova estrutura de criacao ---- *
*
*
move-corresponding wa_itemdetail to wa_itemcreate.
*
*
*---- Verificacao se e um item com revisao de factura com base em entrada de mercadoria ---- *
*
*
read table poitem into wa_item with key po_item = wa_itemdetail-po_item.
if sy-subrc = 0.
if wa_item-gr_ind = 'X' and wa_item-gr_basediv = 'X' and wa_item-ir_ind = 'X'."Case 1 - Tem revisao de facturas baseada em
" entrada de material
move-corresponding wa_itemdetail to wa_itemcreate.
read table pohistory into wa_hist with key po_item = wa_itemdetail-po_item.
if sy-subrc = 0.
wa_itemcreate-ref_doc = wa_hist-ref_doc.
wa_itemcreate-ref_doc_it = wa_hist-matdoc_itm.
wa_itemcreate-po_number = ebeln_sel.
wa_itemcreate-ref_doc_year = wa_hist-doc_year.
" Os restantes casos nao precisam do documento de material
else.
if not w_hist is initial.
write at /1 wa_itemdetail-po_number.
write at ebeln_sel 20 .
endif.
endif.
endif.
else.
*
*Msg de Erro
endif.
append wa_itemcreate to itemdata_create.
endif.
else.
*is_valid = 'X'.
endif.
clear: wa_itemdetail, wa_hist, wa_itemcreate, wa_item.
endloop.
describe table itemdata_create lines lines.
if lines >= 1 and w_hist is initial.
clear return[].
***Theres no errors on the document, process the document
call function 'BAPI_INCOMINGINVOICE_PARK'
exporting
headerdata = headdata_create
importing
invoicedocnumber = invoicedocnumber_c
fiscalyear = fiscalyear_c
tables
itemdata = itemdata_create
return = return.
read table return with key type = 'E' transporting no fields.
if sy-subrc ne 0.
*it_out-old = .
*it_out-new = .
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.