When using MIRO, the system would propose line items for each GR reference item using the following fields: EKBE-LFGJA, EKBE-LFBNR and EKBE-LFPOS.
Message type INVOIC and the corresponding function module IDOC_INPUT_INVOIC_MRM were designed to provide the possibility for vendors to sent the invoice to the customer. Generally, within this business scenario, the vendor does not know the reference/goods receipt document details (EKBE-LFGJA, EKBE-LFBNR and EKBE-LFPOS), so the process instead identifies the corresponding goods receipt item based on the delivery note number (EKBE-XBLNR) and, if available, the purchase order (EKBE-EBELN) and item number (EKBE-EBELP). This is standard logic implemented in form MRM_GR_ASSIGN (LMRMHF0Q).
If the IDOC is filled with an incorrect information in its segments based on the logic explained above, the system will raise the error M8321 as was not possible determine the correct order item. It is usually casued per example when segment E1EDP02-ZEILE is not filled correctly.
AND I WANT TO ENHANCE IS PROBLEM USING user-exit EXIT_SAPLMRMH_011 OR EXIT_SAPLMRMH_013