Skip to Content

Customer open item clearing Z report

Hello Expert

We have createdZ reports to clear foreign customer open items by using BAPI “BAPI_ACC_DOCUMENT_POST”. In which exchange rate taken through structure BAPIACCR09 covers field EXCH_RATE.

Exchange rate taken from standardtable i.e. TCURR.

The clearing program uses the wrong currency rate which creates Difference between Sales invoice booked and documents creates through program.

Our requirement is that in Z Program exchange rate determine through sales invoices and exchange rate should be populated at line item level instead of Header (like FB01). How to provide logic to ABAP Team to taken the exchange rate from Sales invoices

We using Table BKPF and BSEG.

***Structure for posting the open
TYPES: BEGIN OF ty_data,
bukrs TYPE bukrs, " Company Code
kunnr TYPE kunnr, " Customer Number
gjahr TYPE gjahr, " Fiscal Year
belnr TYPE belnr_d, " Accounting Document Number
buzei TYPE buzei, " Number of Line Item Within Accounting Document
budat TYPE budat, " Posting Date in the Document
bldat TYPE bldat, " Document Date in Document
waers TYPE waers, " Currency Key
blart TYPE blart, " Document Type
* MS001 INS begin
shkzg TYPE shkzg, " Debit/Credit
* MS001 INS end
* MS002 INS begin
gsber TYPE gsber,
* MS002 INS end
dmbtr TYPE dmbtr , " Amount in Local Currency
WRBTR TYPE WRBTR , " Amount in document currency "np001
xref2 TYPE vbeln_va, " Business partner reference key
bktxt TYPE bktxt, " Document Header Text
saknr TYPE saknr, " G/L Account Number
obj_key TYPE belnr_d, " Obj key
error TYPE c,
END OF ty_data.

TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
augru TYPE augru,
vkorg TYPE vkorg,
kunnr TYPE kunag,
END OF ty_vbak.

TYPES: BEGIN OF ty_bkpf,
belnr TYPE belnr_d,
bktxt TYPE bktxt,
xblnr TYPE char16,
gjahr TYPE gjahr,
END OF ty_bkpf.

TYPES: BEGIN OF ty_bseg,
belnr TYPE belnr_d,
saknr TYPE saknr,
END OF ty_bseg.

TYPES: BEGIN OF ty_key,
obj_key TYPE awkey,
END OF ty_key.

****Structure for Succes/Failure Documents
TYPES: BEGIN OF ty_error,
record_no TYPE i,
bukrs TYPE bukrs,
kunnr TYPE kunnr,
xref2 TYPE vbeln_va,
belnr TYPE belnr_d,
error TYPE c,
mess TYPE char255,
line_color TYPE char4, "Used to store row color attributes
END OF ty_error.

TYPES: BEGIN OF ty_clear1,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
blart TYPE blart,
budat TYPE budat,
END OF ty_clear1.

TYPES: BEGIN OF ty_clear2,
bukrs TYPE bukrs,
gjahr TYPE gjahr,
belnr TYPE belnr_d,
buzei TYPE buzei,
END OF ty_clear2.

CONSTANTS: c_rv TYPE char2 VALUE 'RV', " Document Type : Customer Invoice SD
c_z04 TYPE char3 VALUE 'Z04',
c_z05 TYPE char3 VALUE 'Z05',
c_x TYPE c VALUE 'X'.

TYPE-POOLS: slis.

TABLES: bkpf,bseg.

DATA : it_data TYPE TABLE OF ty_data,
wa_data TYPE ty_data,
it_error TYPE TABLE OF ty_error,
wa_error TYPE ty_error,
f_count TYPE i, " Count the document numbers which are posted
s_count TYPE i. " Count the document numbers which are not posted

DATA: wa_docmentheader LIKE bapiache09,
it_gl TYPE TABLE OF bapiacgl09, "G/L
wa_gl LIKE LINE OF it_gl,
it_receivable TYPE TABLE OF bapiacar09, "Customer
wa_receivable LIKE LINE OF it_receivable,
it_currencyamount TYPE TABLE OF bapiaccr09,
wa_currencyamount LIKE LINE OF it_currencyamount,
it_return TYPE TABLE OF bapiret2,
wa_return LIKE LINE OF it_return.

DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF it_fieldcat.

DATA: it_clear1 TYPE TABLE OF ty_clear1,
wa_clear1 TYPE ty_clear1,
it_clear2 TYPE TABLE OF ty_clear2,
wa_clear2 TYPE ty_clear2.
** Added on 9/3/2015 by Varsha:start
DATA: it_bkpf TYPE TABLE OF bkpf,
wa_bkpf TYPE bkpf.
DATA: lit_bkpf TYPE TABLE OF ty_bkpf,
lwa_bkpf TYPE ty_bkpf,
lit_vbak TYPE TABLE OF ty_vbak,
lwa_vbak TYPE ty_vbak.

Thanks

YOG K

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Jun 03, 2019 at 01:01 PM

    Hi,

    Exchange rate is an attribute of document header. If you have different exchange rates to apply, you have to create several documents.

    Regards,

    Eli

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.