Application Development and Automation 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: 
Read only

Link between VBAP (Sales docs) and VBRK (Billing)

luis_rod
Participant
0 Likes
7,071

Hi, I need to get the VBRK data that corresponds to a particular VBAP record. The logical path would be accessing vbrk.vbeln using the VBRP table (vbrp.aubel = vbap.vbeln , vbrp.aupos = vbrp.posnr).

My problem is that, at least in our system, we don’t have an index with AUBEL/AUPOS, so a search as the above described results in a full table scan…

An additional issue is that I can have several vbrk.vbeln documents (cancelled or not) for a particular vbap.vbeln/vbap.posnr record, so the VBFA table is (I think) of not help here.

Any ideas?

Thanks in advance,

Luis

17 REPLIES 17
Read only

Former Member
0 Likes
5,310

Hi,

Yes use VBFA, vbfa-vbelv = vbap-vbeln & vbtyp_n = 'M' & vbtyp_v = 'C.

You will get the invoice in VBFA-VBELN.

Read only

0 Likes
5,310

Sunil,

Thanks for your answer.

My problem is that I have two or more records with the same aubel/aupos in VBRP, corresponding to two or more VBRK(vbeln).

If I use VBFA I get only one record. In this case, the "valid" (not canceled) document. Nevertheless, I need to access all the vbeln records (canceled (fksto = 'X') ) or not.

Thanks again,

Luis

Read only

Former Member
0 Likes
5,310

Hi

If you need to get the bills generated from a certain sales order, so your research needs to start from sales order, you need to use VBFA table (you can use fm  RV_ORDER_FLOW_INFORMATION)

In VBFA table you should find cancelled bill too

Max

Read only

0 Likes
5,310

Max,

Thanks for your post.  I'm afraid that, as far as I have been able to verify, the VBFA table shows only one record (the "valid" one).

For example, in VBAP I have:

VBELN = 6100627040, POSNR = 1

in VBFA I have:

VBELV = 6100627040, POSNV = 000001, VBELN = 8010100038, VBTYP_N  =  M

Nevertheless, if I check VBRP, I get two(2) differnt VBELNs for AUBEL = 6100627040 and AUPOS = 1

8010100035 (FKSTO = 'X')

8010100038 (FKSTO = space)

My problem is that VBRP is missing an AUBEL/AUPOS index, so the search is VERY slow.

Regards,

Luis

Read only

0 Likes
5,310

Hi

I don't know your flow, but I suppose it depends on how you're looking for in VBFA: try to check how bill 8010100035 is inserted in VBFA table

Read only

0 Likes
5,310

Hi Luis,

Not sure why you want to go to VBRP and fetch records from VBRP for sales order using AUBEL/SUPOS.

Fetch the billing documents from VBFA for both invoice and cancellation invoice (vbtyp_n = M, N) and validate those billing documents from VBRK and details from VBRP for entires in VBRK.

You also get cancelled invoices from VBFA as well so compare those from VBRK and get the corresponding details from VBRP for all entries in VBRK.

Read only

0 Likes
5,310

Sunil,

Our users want to query the sales documents (VBRK.VBELN) using the vbak.bstnk field (Customer purchase order number) . So far, so good...So we link these to the VBAP table (to check the sales document detail) and, as we need some additional data from the invoices (such as FKSTO (canceled status) and some Z-fields), we need the VBRK.VBELN value.


As I wrote before, if I check the VBFA table I get only one VBELN. If I use the VBRP table I may get two (or more). One (or more) of them may be canceled, a info that our users may find important.


Regards,


Luis


Read only

0 Likes
5,310

Max,

The bill 8010100035 appears in the VBELV table,pointing to the "canceling" bill (9910016265) , But the point here is that I need to get both 8* numbers from the single VBAP record, which I haven't been able to do without resorting to use the VBRP table (which is a big no-no in performance terms).


Regards,


Luis


Read only

0 Likes
5,310

HI Luis,

Yo should get all the invoices from VBFA , use VBTYP_N = (M & N)  for single order and item if there are any cancellations you might get here as well.

Read only

Juwin
Active Contributor
0 Likes
5,310

VBFA should give you all the links as mentioned above. But, if you think you are getting extra entries from that table, you can always double check that with another VBRP query. This time, when you query VBRP, pass the VBELN and POSNN retrieved from VBFA query, to quicken the results.

Thanks,

Juwin

Read only

0 Likes
5,310

Juwin,

Thanks for your post.

The problem is not extra entries from VBFA, is not ENOUGH entries. As I wrote in other posts, there are some vbrp.vbeln entries that do not appear in vbfa.

Googling around I have found several posts that advise against creating extra indexes for VBRP. In fact, our table is quite large, and I can understand the reasons for avoiding an additional index...

Regards,

Luis

Read only

Juwin
Active Contributor
0 Likes
5,310

Can post some screenshots of what you are seeing in VBFA vs VBRP?

Thanks,

Juwin

Read only

0 Likes
5,310

This can be achieved via SQVI Table Join VBAK, VBAP, VBRK & VBRP.  Discuss with your functional resource if you are a technical resource and not aware of SQVI functionality. 

G. Lakshmipathi

Read only

0 Likes
5,310

Juwin,

Thanks for ypur post. Here is (I hope 🙂 ) the data you requested...

Regards,

Luis

Read only

0 Likes
5,310

Thanks for your post.

I am aware of what SQVI is, and its functionality. Nevertheless, this is part of something that goes beyond of a simple query. Also, as I have posted before, the main problem here is that the VBRP query times are very slow where using only AUBEL/AUPOS.

Regards,

Luis

Read only

Juwin
Active Contributor
0 Likes
5,310

What were your selection parameters for VBFA select? Did you just input the order number? If yes, then I feel that, there is some issue with the document flow. Is this behavior specific to this document number or other cancelled documents also?

Can you also post a document flow diagram for this order, from VA03?

Thanks,

Juwin

Read only

0 Likes
5,310

Juwin,

VBFA was accessed using VBFA.VBELV = VBAP.VBELN and VBFA.POSNV = VBAP.POSNR.

If I check VA03 I get :

Order No. 6200206871 -> Delivery (sales inquiry) 7200214135 -> Billing No. 8010100038

And that's exactly what I would expect it to be for a valid order. The same results I get if I query the VBFA table using VBAP.VBELN.

There seem to be several other documents with the same behavior.

What bugs me is that the only references I can get to the canceled order are in VBRP and in VBAK..

I think I will have to bite the bullet and ask our DB people to create an index for VBRP.

Thanks for your help and interest in this case...

Regards,

Luis