When creating a Return delivery to vendor (movement type 122) via the Odata API_MATERIAL_DOCUMENT_SRV you are running into error message M7021 and the posting fails.
SAP S/4HANA Cloud All versions from CE2011
Reproducing the Issue
Post a 122 movement via API_MATERIAL_DOCUMENT_SRV
GR based IV case, missing the required reference fields in the payload.
If you have a regular Purchase Order Item with a stock material, you can post a 122 return via the API with reference to the Purchase Order.
If you have a regular Purchase Order Item with a stock material and with the 'GR Based IV flag' set, you can post a 122 return via the API but you must pass the assignment block reference as well as the Purchase Order.
In the payload, pass the corresponding assignment block fields:
"InvtryMgmtReferenceDocument" : "xxxxxxxxxxx", (mseg-lfbnr)
"ReferenceDocumentFiscalYear" : "xxxx", (mseg-lfbja)
"InvtryMgmtRefDocumentItem" : "xxxx", (mseg-lfpos)
Note: In Cloud release CE2008 the API does not fully support the GR Based IV processing, these reference fields are not available until CE2011
M7021, VFBL, EKPO-WEMNG, MB_FILL_EKPO_ENQUEUE_TABLE, FM07MEM0_MENGE_PRUEFEN, MB_CHECK_MATERIAL_STOCKS, WEBRE, GR to vendor, 122, Deficit of PU GR quantity , KBA , MM-IM-GR-PO , Goods Receipt from External Procurement , Problem