One of the more common mistakes I came across again and again in my own work as an SAP Support Engineer is caused by modifications in user-exits. In the include RV60AFZZ (transaction SE38) several exits are available, which are executed during invoice creation. Of those, two are quite popular, which are relevant to influence the pricing functionality. Everybody does have some own requirements in the pricing area.
In FORM USEREXIT_PRICING_PREPARE_TKOMK additional custom-own fields can be filled for TKOMK, which is the header level.
And the user-exit for the item level (TKOMP) is FORM USEREXIT_PRICING_PREPARE_TKOMP.
Both are called at the start of the pricing processing in include LV60AA58, FORM PREISFINDUNG_VORBEREITEN. First the header one, thereafter the one of the item fields at the very end:
351 PERFORM userexit_pricing_prepare_tkomk.
785 PERFORM userexit_pricing_prepare_tkomp.
Now the usual way here is to simply fill own z-fields as is suggested:
TKOMK-zzfield = xxxx–zzfield2.
But what happens if you perform here a LOOP command on the internal table XVBRK? Then no errror message will be the result, as in my previous post , but instead the created invoice could be inconsistent.
In a recent case, which I investigated, two deliveries, with entirely different payers, had been created combined together in transaction VF01. In the TKOMK user-exit such a LOOP command was executed:
Now in this case an invoice split has to be performed, due to different partner data, and in XVBRK two entries exist. At the point before the LOOP command the second invoice is processed by the system and visible in the debugger as the currently processed line.
After the LOOP is executed, this line is changed, and now instead of the second invoice, the first one is the one to be processed further:
The undesired result of this manipulation: the second invoice will get the wrong partner data! It will receive the same partners as the first invoice!
So such a direct LOOP must be avoided. If data of XVBRK should be used, then a custom own table ZVBRK would have to be used, and the data moved to there. Then on the Z-table the LOOP will not cause a change in the processing line of the XVBRK.
In other cases, when the LOOP is performed on XVBRP, in the other exit USEREXIT_PRICING_PREPARE_TKOMP, then error message VF004 “Reference document & & (Error during INSERT)” could be the result, if more than one item will have to be invoiced.
Again with the LOOP command the current processing line is changed, and then the inserting of the second item will fail, because the system thinks it is the first one, which is already present in XVBRP:
So my suggestion would be to strictly refrain from such LOOP commands on internal SAP tables which are processed by the system.