2023 Feb 27 8:05 AM
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.
2023 Feb 27 8:31 AM
2023 Feb 27 8:32 AM
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).
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.
2023 Feb 27 8:58 AM
Why do you think it should return a single line? The primary key of VBFA is not made of VBELN only.
2023 Feb 27 9:22 AM
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'
2023 Feb 27 10:16 AM
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.
2023 Mar 01 5:10 AM
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.