Skip to Content
0
May 25 at 08:07 AM

SAP CPI - Merge two Line Item to Single Row

99 Views

Hi All,

From source payload I am getting two line item i.e. one as main Item and another as Tax for each item. My requirement is to merge the Item with tax and produce single row in target using message mapping.

Input Payload :

<LineItems>
	<item>
		<AdjustedCostInERPPrecision>
			<Amount>100.00000</Amount>
		</AdjustedCostInERPPrecision>
		<NumberInCollection>1</NumberInCollection>
		<custom>
			<CustomString name="LineType">Item</CustomString>
			<CustomString name="UnitofMeasure">EA</CustomString>
		</custom>
	</item>
	<item>
		<AdjustedCostInERPPrecision>
			<Amount>10.00000</Amount>
		</AdjustedCostInERPPrecision>
		<NumberInCollection>2</NumberInCollection>
		<Parent>
			<NumberInCollection>1</NumberInCollection>
		</Parent>
		<custom>
			<CustomString name="LineType">Tax</CustomString>
			<CustomString name="UnitofMeasure">EA</CustomString>
		</custom>
	</item>
</LineItems>


Output :

<LineItems>
	<item>
		<AdjustedCostInERPPrecision>
			<Amount>100.00000</Amount>
		</AdjustedCostInERPPrecision>
		<NumberInCollection>1</NumberInCollection>
		<TaxAmount>10</TaxAmount>
		<custom>
			<CustomString name="LineType">Item</CustomString>
			<CustomString name="UnitofMeasure">EA</CustomString>
		</custom>
	</item>
</LineItems>

We can get multiple line item in source payload and each item will have two line one as item and other as Tax.

Would appreciate suggestion to achieve this functionality to message mapping ?