Invoice data is sent by the vendors in a text file and an inbound
*interface is required to create Vendor Invoices in SAP.
*The file contains the Purchase Order information, material quantity
*received from vendor along with the amount.
*Here the requirement becomes a little complex as there might be
*several ocuurences of same Purchase Order item in one invoice.
*Processing for header records of data file.
*set up header data for BAPI call.
*Check whwther it's an Incoice or Credit Memo.
*And populate Invoice indicator accordingly.
*---------------------------------------------------------------------*
* Executa a BAPI MIRO
*----------------------------------------------------------------------*
FORM f_bapi_miro USING p_ent.
* Dados locais
DATA: st_header_miro LIKE bapi_incinv_create_header,
it_return_miro LIKE bapiret2
OCCURS 0 WITH HEADER LINE,
vc_docto_miro LIKE bapi_incinv_fld-inv_doc_no,
vc_year_miro LIKE bapi_incinv_fld-fisc_year.
*
DATA: v_regio TYPE t001w-regio,
v_taxcode TYPE vfkp-mwskz,
v_inco1 TYPE likp-inco1,
v_fkart TYPE vfkk-fkart,
v_meins TYPE lips-meins,
v_ntgew TYPE lips-ntgew,
v_aux TYPE lips-ntgew,
v_ekorg TYPE ekko-ekorg,
v_count(6) TYPE n,
v_valor TYPE vfkp-netwr.
SELECT lblni
fknum
fkpos
mwskz
netwr
mwsbp
knumv
INTO TABLE it_vfkp
FROM vfkp
WHERE rebel = it_saida-tknum
AND lblni = it_saida-lblni
AND fkpty <> 'Z022'.
SELECT SINGLE regio INTO st_lfa1-regio
FROM lfa1
WHERE lifnr = it_saida-tdlnr.
SELECT SINGLE ekpo~j_1bmatuse
ekpo~j_1bindust
t001w~regio
t001w~land1
ekpo~mwskz
INTO st_ekpo
FROM ekpo
JOIN t001w ON t001w~werks = ekpo~werks
WHERE ekpo~ebeln = it_saida-ebeln
AND ekpo~ebelp = it_saida-ebelp.
SELECT SINGLE likp~vbeln
likp~kunnr
kna1~regio
kna1~land1
kna1~txjcd
INTO st_likp
FROM likp
JOIN kna1 ON kna1~kunnr = likp~kunnr
WHERE likp~vbeln = it_saida-vbeln.
* Busca condiзгo
SELECT SINGLE ekorg
INTO v_ekorg
FROM ekko
WHERE ebeln = it_saida-ebeln.
SELECT SINGLE zterm
INTO st_header_miro-pmnttrms
FROM lfm1
WHERE lifnr = it_saida-tdlnr
AND ekorg = v_ekorg.
IF st_header_miro-pmnttrms IS INITIAL.
st_header_miro-pmnttrms = '30DD'.
ENDIF.
* Preenche os itens da MIRO
v_count = 0.
* Cada item representa um custo
LOOP AT it_vfkp.
READ TABLE it_doc WITH KEY fknum = it_vfkp-fknum
fkpos = it_vfkp-fkpos.
IF sy-subrc EQ 0.
v_taxcode = st_ekpo-mwskz.
v_regio = st_likp-txjcd.
IF st_lfa1-regio = st_ekpo-regio.
DATA: wa_a612 TYPE a612.
* Substituiзгo tributбria
SELECT SINGLE * INTO wa_a612
FROM a612
WHERE regioz = st_lfa1-regio.
IF sy-subrc = 0.
SELECT SINGLE inco1 INTO v_inco1
FROM likp
JOIN vfsi ON likp~vbeln = vfsi~vbeln
JOIN vfkp ON vfsi~knumv = vfkp~knumv
WHERE vfkp~fknum = it_vfkp-fknum
AND likp~inco1 = 'CIF'.
IF sy-subrc = 0.
v_taxcode = 'P0'.
ELSE.
v_taxcode = 'P1'.
ENDIF.
ENDIF.
* ELSE.
* CONCATENATE 'Y' it_doc-regio INTO v_regio.
ENDIF.
* Verifica o FKART
SELECT SINGLE fkart INTO v_fkart
FROM vfkk
WHERE fknum = it_vfkp-fknum.
IF it_saida-lfart NE 'NL'. " Quando VENDA gerar um sу registro
READ TABLE it_item_miro WITH KEY po_number = it_aux-ebeln
po_item = it_aux-ebelp.
IF sy-subrc EQ 0.
ADD it_aux-netwr TO it_item_miro-item_amount.
ADD v_ntgew TO it_item_miro-quantity.
MODIFY it_item_miro INDEX sy-tabix.
ELSE.
it_item_miro-item_amount = it_aux-netwr. "Preзo liq
it_item_miro-quantity = v_ntgew. "Quantidade
APPEND it_item_miro.
ENDIF.
ENDIF.
" Transferкncia or o primeiro registro de venda
IF it_saida-lfart EQ 'NL'. " Transferкncia
it_item_miro-item_amount = it_aux-netwr. "Preзo liq
it_item_miro-quantity = v_ntgew. "Quantidade
APPEND it_item_miro.
ENDIF.
IF NOT vc_docto_miro IS INITIAL.
* Se gerou o documento dou o commit work
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
* ATUALIZAЗГO FEITA PARA QUE DURANTE A VISUALIZAЗГO DA FATURA SEJA
* POSSIVEL A VISUALIZAЗГO DA NOTA FISCAL.
* POR SER LOCALIZAЗГO BRASIL ESTE CAMPO NГO ESTБ NA BAPI E NГO TEM
* OUTRA FORMA DE ATUALIZA-LO.
UPDATE rbkp SET j_1bnftype = vc_type
WHERE belnr = vc_docto_miro AND
gjahr = vc_year_miro.
IF sy-subrc NE 0.
vc_flag_erro = 'X'.
* ERRO ATUALIZAЗГO J_1BNFTYPE. DOCTO &
PERFORM atribui_erro USING 'ZVGMM'
'027'
'J_1BNFTYPE' vc_docto_miro '' .
MOVE-CORRESPONDING it_saida TO wa_ztlog.
PERFORM monta_log USING '214' sy-msgty 'MIRO'.
p_mensagem = '01'.
EXPORT p_mensagem TO MEMORY ID 'Z_214'.
MOVE-CORRESPONDING it_saida TO wa_ztlog.
wa_ztlog-docmiro = vc_docto_miro.
log_registro = wa_ztlog.
PERFORM gravar_log_interface USING p_ent 'MIRO'.
COMMIT WORK AND WAIT.
ELSE.
PERFORM f_altera_erekz USING vc_docto_miro
p_ent.
PERFORM f_aprovacao_fiscal.
IF sy-subrc = 0.
CLEAR v_valor.
IF it_saida-lfart NE 'NL'. " Venda
v_valor = it_vfkp-netwr + it_vfkp-mwsbp.
ENDIF.
PERFORM f_altera_nf USING vc_docto_miro
vc_year_miro
v_valor.
ENDIF.
ENDIF.
ELSE.
LOOP AT it_return_miro WHERE type = 'E'.
vc_flag_erro = 'X'.
* Tratamento log de erros para ztlog
PERFORM atribui_erro USING it_return_miro-id
it_return_miro-number
it_return_miro-message_v1
it_return_miro-message_v2
it_return_miro-message_v3.
MOVE-CORRESPONDING it_saida TO wa_ztlog.
PERFORM monta_log USING '214' sy-msgty 'MIRO'.
p_mensagem = '01'.
EXPORT p_mensagem TO MEMORY ID 'Z_214'.
MOVE-CORRESPONDING it_saida TO wa_ztlog.
wa_ztlog-docmiro = vc_docto_miro.
log_registro = wa_ztlog.
PERFORM gravar_log_interface USING p_ent 'MIRO'.
COMMIT WORK AND WAIT.
ENDLOOP.
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.