The error message V1331 occurs most often in sales order processing and you can find threads about here in the SCN Forum. However, if custom own coding is programmed wrongly, then it can pop up as well, when you try to create an invoice via transaction VF01:
Image may be NSFW.
Clik here to view.
The root cause of the error is most often an accidental manipulation of the sales order number VBAK-VBELN in pricing user-exit
USEREXIT_PRICING_PREPARE_TKOMK of include RV60AFZZ.
Here in this exit the sales order header structure VBAK is available. If now a wrong select on VBAK is programmed, the number could be changed. One example for erroneous coding:
SAPLV60A / RV60AFZZ
FORM / USEREXIT_PRICING_PREPARE_TKOMK
...
IF ( vbrk-vkorg = '3000' OR vbrk-vkorg = '5000' ) AND ( sy-tcode = 'VF01' OR sy-tcode = 'VF04' ).
SELECT * FROM vbak
WHERE vbeln = vbrk-zuonr.
ENDSELECT.
When VBRK-ZUONR is not filled with the sales order number currently involved, then VBAK-VBELN is changed wrongly, and the sales order numbers differ thereafter between header information VBAK and item VBAP:
Image may be NSFW.
Clik here to view.
In the processing of the status, this inconsistency is detected and as the item VBAP structure FXVBAP does not contain the same VBELN number as in VBAK present, the check fails:
Image may be NSFW.
Clik here to view.
And the error message is issued when returning to function module RV_XVBUP_MAINTAIN_FKGSA:
Image may be NSFW.
Clik here to view.
Conclusion: Be very careful with your modifications and assure that VBAK information is not changed wrongly!