cancel
Showing results for 
Search instead for 
Did you mean: 

Split Message based on attribute in HCI

0 Kudos

Hi Experts,

I am working on an integration (in HCI) that has to do a global query to get all employees for a country in SSFF. Then after transforming the data, it should produce one file per company (you can have many companies in the same country). The company is an attribute in the xml.

<?xml version="1.0" encoding="UTF-8"?>
<queryCompoundEmployeeResponse>
	<CompoundEmployee>
		<person>
			<action>NO CHANGE</action>
			<id>employee1</id>
			<employment_information>
				<action>NO CHANGE</action>
				<job_information>
					<action>CHANGE</action>
					<company>X</company>
				</job_information>
			</employment_information>
		</person>
	</CompoundEmployee>
	<CompoundEmployee>
		<person>
			<action>NO CHANGE</action>
			<id>employee2</id>
			<employment_information>
				<action>NO CHANGE</action>
				<job_information>
					<action>CHANGE</action>
					<company>X</company>
				</job_information>
			</employment_information>
		</person>
	</CompoundEmployee>
	<CompoundEmployee>
		<person>
			<action>NO CHANGE</action>
			<id>employee3</id>
			<employment_information>
				<action>NO CHANGE</action>
				<job_information>
					<action>CHANGE</action>
					<company>Y</company>
				</job_information>
			</employment_information>
		</person>
	</CompoundEmployee>
</queryCompoundEmployeeResponse>

Expected result shoud be, message1:

<?xml version="1.0" encoding="UTF-8"?>
<queryCompoundEmployeeResponse>
	<CompoundEmployee>
		<person>
			<action>NO CHANGE</action>
			<id>employee1</id>
			<employment_information>
				<action>NO CHANGE</action>
				<job_information>
					<action>CHANGE</action>
					<company>X</company>
				</job_information>
			</employment_information>
		</person>
	</CompoundEmployee>
	<CompoundEmployee>
		<person>
			<action>NO CHANGE</action>
			<id>employee2</id>
			<employment_information>
				<action>NO CHANGE</action>
				<job_information>
					<action>CHANGE</action>
					<company>X</company>
				</job_information>
			</employment_information>
		</person>
	</CompoundEmployee>

</queryCompoundEmployeeResponse>

Message 2

<?xml version="1.0" encoding="UTF-8"?>
<queryCompoundEmployeeResponse>
	<CompoundEmployee>
		<person>
			<action>NO CHANGE</action>
			<id>employee3</id>
			<employment_information>
				<action>NO CHANGE</action>
				<job_information>
					<action>CHANGE</action>
					<company>Y</company>
				</job_information>
			</employment_information>
		</person>
	</CompoundEmployee>

</queryCompoundEmployeeResponse>

Using filters is fairly simple to group the messages, but I think I would need to add one filter per company, and I am looking for a dynamic solution. I am struggling to find a way to do it with a splitter or iterator.

Anybody has any idea to tackle this problem?

Thanks in advance,

Antonio

Accepted Solutions (0)

Answers (6)

Answers (6)

Hi Antonio,

You can use XSLT to tackle this situation. Using the following script, you can group all the CompoundEmployees with the same company code. Using the funciton <xsl:for-each-group>, it will group every 'CompoundEmployee' (select attribute) based on the company value (group-by attribute). The grouped CompoundEmployees will be encapsulated by an xml node called '<group name="[company code]">'

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>


 <xsl:template match="/*">
     <queryCompoundEmployeeResponse>
      <xsl:for-each-group select="CompoundEmployee" group-by="person/employment_information/job_information/company">
       <group name="{current-grouping-key()}">
        <xsl:copy-of select="current-group()"/>
       </group>
      </xsl:for-each-group>
     </queryCompoundEmployeeResponse>
 </xsl:template>
</xsl:stylesheet>

The output of this XSLT script will be the following XML:

Kind Regards,

Christophe Deblock

jorgeh
Explorer

Antonio

With splitter you can create different data flows. First you should group employees with same company and them split. Flow after the splitter will be shared by different messages. For naming convention file you can create a property for company id and use in sftp channel.

Alternative is to use filter. I suggest this approach due to you will schedule companies in different timings. Create an external parameter for company and replícate interface as many companies you can have. Include in the iflow id the company id.

cweissheimer
Advisor
Advisor

You can do that with a Splitter, check the documentation and examples below as they are very similar to your case:

https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/83e2022f9c014bebab63cb933e6...

Best Regards,

Carlos

SudeepMenakuru1
Explorer
0 Kudos
<CompoundEmployee>
	<id></id>
	<person>
		<action>NO CHANGE</action>
		<personal_information>
			<action>CHANGE</action>
		</personal_information>
		<employment_information>
			<action>NO CHANGE</action>
			<job_information>
				<action>NO CHANGE</action>
			</job_information>
			<job_information>
				<action>CHANGE</action>
			</job_information>
			<compensation_information>
				<action>NO CHANGE</action>
			</compensation_information>
			<PaymentInformationV3>
				<action>NO CHANGE</action>
			</PaymentInformationV3>
		</employment_information>
		<national_id_card>
			<action>NO CHANGE</action>
		</national_id_card>
	</person>
</CompoundEmployee>
SudeepMenakuru1
Explorer
0 Kudos

Hi All,

But when we use the General Splitter, the nodes which are in next element to the configured element are not resulting in the output. Example below.

If we configure the Xpath to split on job_information, the compensation_information and PaymentInformationV3 is not coming out from the output of GeneralSplitter.

I read in SAP blog that this is the functionality of General Splitter, which is not useful anymore as we need to map the target with compensation_information and PaymentInformationV3 nodes as well.

Kindly suggest what can be done? Shall we ask SAP to introduce a splitter that can acheive the functionality that we are expecting?

0 Kudos

Thank you all for your answers. I could solve the problem using all inputs. With xslt, I grouped the xml and then I use the split to generate a file per group.