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: 

SQL Select Issue in VBFA

walkerist
Participant
0 Kudos

I'm currently encountering an issue where in multiple data were selected in table VBFA. While the parameter is unique which is LIKP-VBELN which equates to Delivery Document Number. However, when the program passes this code, it is showing multiple sales delivery with same delivery document. How does that happen?

      SELECT vbelv
vbeln
matnr
FROM vbfa
INTO TABLE it_vbfa
WHERE vbeln = it_likp-vbeln.
6 REPLIES 6

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos

It is possible that the data in the VBFA table has been updated with multiple entries that have the same delivery document number (VBELN). This could happen if the data has been updated manually or if a program was used to update the data. Additionally, it is possible that the entries in the VBFA table were created with the same delivery document number.

yogananda
Product and Topic Expert
Product and Topic Expert

It is possible that the query you have written is not correctly restricting the result set to a single delivery document. There might be multiple entries in the VBFA table for the same delivery document number (LIKP-VBELN).


To make sure the query returns only one delivery document, you should add a condition to the WHERE clause to make sure only one row is returned:
SELECT vbelv
vbeln
matnr
FROM vbfa
INTO TABLE it_vbfa
WHERE vbeln = it_likp-vbeln
AND rownum = 1;
This will ensure that only one row is returned in the result set.

Sandra_Rossi
Active Contributor

Why do you think it should return a single line? The primary key of VBFA is not made of VBELN only.

raymond_giuseppi
Active Contributor

Call transaction VL03N and check the document flow, it's possible that multiple sales orders or sales order items are processed within a single delivery.

Also you could add more criteria in the select (e.g. delivery item number) if you don't require item numbers or use a DISTINCT clause.

      SELECT DISTINCT vbelv,
             vbeln,
             matnr
        FROM vbfa
        INTO TABLE it_vbfa
       WHERE vbeln   = it_likp-vbeln
	     AND vbtyp_n = c_delivery " 'J'
	     AND vbtyp_v = c_order. " 'C'

shantraj
Explorer
0 Kudos

Try below.

SELECT a~vbelv
       a~vbeln
       a~matnr
  FROM vbfa as a
  inner Join likp as b
  WHERE vbeln = b~vbeln.
  INTO TABLE it_vbfa.

jack_graus2
Active Contributor
0 Kudos

From a data point of view table VBFA is to be used when selecting subsequent documents. For instance selecting delivery document items for sales order items. Then the source document, like sales order, is in VBFA-VBELV and the subsequent document, like delivery, is in VBFA-VBELN.

Here you are selecting preceding documents for a delivery. Then you better use table LIPS delivery item. Source document, delivery, is in LIPS-VBELN and the preceding document, like sales order, is in LIPS-VGBEL.

Same result can be applied by below code. However that could still result in multiple lines.

SELECT
vgbel
vbeln
matnr
FROM lips
INTO TABLE it_vbfa
WHERE vbeln = it_likp-vbeln.