Skip to Content
0

Split Message based on attribute in HCI

Mar 06 at 06:05 PM

89

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Carlos Weissheimer
Mar 06 at 09:24 PM
1

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/83e2022f9c014bebab63cb933e625610.html?q=splitter

Best Regards,

Carlos

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 07 at 01:10 PM
1

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


Share
10 |10000 characters needed characters left characters exceeded
Jorge Hernandez Mar 06 at 09:56 PM
1

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.

Share
10 |10000 characters needed characters left characters exceeded
Antonio Anguita Mar 08 at 04:35 PM
0

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.


Share
10 |10000 characters needed characters left characters exceeded