Hi Ankit,
Generally This error fires with primary key violation.
If document is master data form,header level primary key is code and line level primary key is code+LineId.
Some check points may helpful for you.
- please make sure lineid bonded in matrix or not.
- "code" field value in header is new or not.
- code in the header and line level should be same.
- if any other unique keys are there check them also.