Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

To get SD reference document number(XBL) for given accounting number(BELNR)

Former Member
0 Kudos
685

Hi All,

I have a requirement in which we have BELNR(accounting document number) and we need to get the corresponding XBLNR(SD reference doucment number). Is there any standard table or transaction which returns XBLNR value if BELNR value is given.

Please help me on this.

Regards,

Pranjali

11 REPLIES 11

raymond_giuseppi
Active Contributor
0 Kudos
303

Usually FI document contain a link to the application which created the document,

This information is stored

- BKPF-AWTYP Reference procedure

- BKPF-AWKEY Object key

Those field are more "technical" than XBLNR.

e.g. for a SD invoice, AWTYP = 'VBRK' and AWKEY is invoice number

For your "exact" question, answer could be READ_DOCUMENT_HEADER or FI_DOCUMENT_READ_SINGLE. Also remember you will also need BUKRS company and GJAHR year to get an unique identification of account document. (A single SELECT statement is usually enough)

Regards,

Raymond

0 Kudos
303

Hi Raymond,

Thanks for your reply. You have mentioned that we need BUKRS and GJAHR to get unique identification of account document. Can you please tell me how can I get the unique BUKRS and GJAHR values if I know BELNR only, because as per my understanding, FI customer invoice number is company code and fiscal year specific. Please help me on this.

Regards,

Pranjali

0 Kudos
303

You cannot, those fields are mandatory. One document number BELNR may give many documents in the system, many of those can be related to SD invoice, From where do you get this number, if it a user input, add company BUKRS and year GJAHR input, if it comes from a database read, those fields are also in the table read or in an header table. Check also with functionals for FI number range Customizing.

SELECT * FROM bkpf WHERE belnr = p_belnr. " 0-n records (multiple company and/or year)
  CASE bkpf-awtyp. " check table TTYP for structure awkey and FM for display 
    WHEN 'VBRK'. " no structure, FM AC_DOCUMENT_SENDER_VBRK
      l_VBELN = bkpf-awkey+0(10).
      SELECT SINGLE * FROM vbrk WHERE vbeln = l_vbeln.
  ENDCASE.
ENDSELECT.

Regards,

Raymond

0 Kudos
303

Hi Raymond,

I am working on lockbox functionality where I have invoice number(BELNR) in lockbox file. Now I want to find out that the invoice number in that file is valid or not(present in table BSID). But when I checked in table BSID, for some invoice numbers, there are more than one entry with different company codes and fiscal years. So I need to find the correct entry for that invoice number(with correct comapny code and fiscal year). When I asked functional consultant, he told me that SD invoice number is unique among company codes and does not repeat in different company codes or fiscal years , but FI customer invoice number is company code and fiscal year specific. So I am thinking to get the SD invoice number(XBLNR) for that FI invoice number(BELNR), so that I will get a unique entry in table BSID. Please guide me on this.

Regards,

Pranjali

0 Kudos
303

Then use

l_awkey+0(10) = <lockbox-invoice_number>.
SELECT * FROM BKPF 
  WHERE belnr EQ <lockbox-acounting_document_number> 
    AND awtyp = 'VBRK' and awkey = l_awkey.

if found (sy-subrc EQ 0) then the invoice number is correct. (Check that index BKPF~4 is active on your system, for performance)

Regards,

Raymond

0 Kudos
303

Hi Raymond,

Thanks for your reply. My program has accounting document number(BELNR) only. It does not have the lockbox file data, so we don't have the lockbox invoice number. Can we get the XBLNR without the lockbox invoice number?

Regards,

Pranjali

0 Kudos
303

No, you actually need more data. For one BELNR, you may (and will) get multiple XBLNR values in BKPF (one per year, company code) to get only one a SD invoice is a matter of luck, and not adviseable. Check if you have other data to choice the correct "unique" invoice (customer code or reference, date, bank reference ?)

Regards,

Raymond

Former Member
0 Kudos
303

You have both in table BKPF

Regards

Nicole

andreas_mann3
Active Contributor
0 Kudos
303

Nicole is right...

...or do you mean another reference like BSEG-XREF1, 2 or 3 ?

...or BSEG-VBELN or VBEL2 ?

grx

A.

Former Member
0 Kudos
303

solved myself

0 Kudos
303

what did you do to solve the problem?