cancel
Showing results for 
Search instead for 
Did you mean: 

count the number of segments used in payload.

Former Member
0 Kudos

Hi experts,

We have a received payload like :

Seg1 - header

seg2 - item

seg2 - item

seg2 - item

seg3 - footer

In the seg3 footer filed1 should have the value of number of segments used in payload,

for example in above payload the value of field1 should be 5.

How we can count these segments and place the value in field1 of seg3, in our receiver payload ?

Please help.

Regards,

Study SAP

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello ,

Use the count function for ITEM node the assign this count value to the receiver field , keep the ITEM context to header!

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

your source structure is like:

Seg1 - header

seg2 - item

seg2 - item

seg2 - item

seg3 - footer

So, seg1 and seg3 will occur only once and seg2 can have multiple occurances.

and you are tring to count number of all occuring segments.

So simply you count how many times seg2 is occuring and then add 2 with the result.(add 2 for single occurances of seg1 and seg3).

so your mapping will be:

item>Count>add-->field1

Constant[2]----


|

--Sankar Choudhury

Former Member
0 Kudos

Hi,

if you want you could try this xslt mapping:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>
  <xsl:template match="seg3">
    <xsl:copy>
      <xsl:element name="field1">
        <xsl:value-of select="count(//seg2)"/>
      </xsl:element>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

I have try with this similar xml as source:


<?xml version="1.0" encoding="UTF-8"?>
<segments>
  <seg1>header</seg1>
  <seg2>item1</seg2>
  <seg2>item2</seg2>
  <seg2>item3</seg2>
  <seg3>footer</seg3>
</segments>

And the result was:


<?xml version="1.0" encoding="UTF-8"?>
<segments>
  <seg1>header</seg1>
  <seg2>item1</seg2>
  <seg2>item2</seg2>
  <seg2>item3</seg2>
  <seg3>
    <field1>3</field1>
  </seg3>
</segments>

Maybe it could be useful for you.

Regards,

Emiliano

Former Member
0 Kudos

Hi

do the following

1) this is your source structure

Seg1 - header

seg2 - item

seg2 - item

seg2 - item

seg3 - footer

your target would be

Seg1 - header

seg2 - item

seg2 - item

seg2 - item

seg3 - footer

field 1

No map field with the STANDARD COUNT function from the SEG1 header line

Thanks

sudhir

Former Member
0 Kudos

hi,

At the end before mapping to the field add the additional standard function - 'count' and then map it to the field..

regards

chandra

Former Member
0 Kudos

Hi,

when I am doing this for count with Seg2 - Item,

it is giving me only value 1, and in the payload the value of seg2 is 3.

please give me clear idea to solve this problem.

Regards,

Study SAP

Former Member
0 Kudos

Hello ,

use below mapping :

seg2(context seg1)->Count-->Target Field.

Former Member
0 Kudos
when I am doing this for count with Seg2 - Item,

it is giving me only value 1, and in the payload the value of seg2 is 3.

please give me clear idea to solve this problem.

it means your items are under different contexts so add a removeContexts before count function.

so , item>removeContexts>Count

**Reward points if helpful.

--Sankar Choudhury