cancel
Showing results for 
Search instead for 
Did you mean: 

Mail receiver with HTML table

Former Member
0 Kudos

Hi all,

I've created a RFC to MAIL interface. Now I want to display the whole payload into the e-mail in HTML table format.

The incoming RFC is as simple as this:

<RFC>

     <table>

          <value1>1</value1>

          <value2>2</value2>

          <value3>3</value3>

     </table>

     <table>

          <value1>1</value1>

          <value2>2</value2>

          <value3>3</value3>

     </table>

</RFC>

This has to be mapped to the HTML table. As following:

<table>

     <tr>

          <td>1</td>

          <td>2</td>

          <td>3</td>

     </tr>

     <tr>

          <td>1</td>

          <td>2</td>

          <td>3</td>

     </tr>

</table>

How can this be done. Do I have to create a UDF and loop trough the record in the payload?

Thanks,

Koen

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi Schouten,

Also, you could use an XSL to do this mapping.

Example,

The XML

<?xml version="1.0" encoding="UTF-8"?>

<ns1:RFC xmlns:ns1="http://test">

    <table>

        <value1>1</value1>

        <value2>2</value2>

        <value3>3</value3>

    </table>

    <table>

        <value1>1</value1>

        <value2>2</value2>

        <value3>3</value3>

    </table>

</ns1:RFC>

The XSL:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://test">

    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">

        <table>

            <xsl:for-each select="./ns1:RFC/table">

                <tr>

                    <xsl:for-each select="./child::*">

                        <td>

                            <xsl:value-of select="."/>

                        </td>

                    </xsl:for-each>

                </tr>

            </xsl:for-each>

        </table>

    </xsl:template>

</xsl:stylesheet>

The output:

<table xmlns:ns1="http://test">

    <tr><td>1</td><td>2</td><td>3</td>

    </tr>

    <tr><td>1</td><td>2</td><td>3</td>

    </tr>

</table>

Personally, i'd rather to use a XSL because you have the sources inside the PI and you don't need an external tool as Java need to make the .class

Regards.

Former Member
0 Kudos

Thanks,

It's a bit more clear now. I've imported the XSL and configured it into my Operation Mapping. If I test the interface I get the following error:

- "Could not compile stylesheet"

There's obviously something wrong in my XSL sheet. The sender adapter is a RFC in my case. If my RFC name is "ZTEST", the XSL would be like this?:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="urn:test">

    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">

                <table>

                    <xsl:for-each select="rfc:ZTEST/table">

                        <tr>

                            <td>

                                <xsl:value-of select="rfc:ZTEST/table/item"/>

                            </td>

                        </tr>

                    </xsl:for-each>

                </table>

    </xsl:template>

</xsl:stylesheet>

iaki_vila
Active Contributor
0 Kudos

Hi Schoouten,

That is a syntax error, you must to define the namespace rfc in

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="urn:test"> tag

I you are importing an RFC from R/3, this namespace should be urn:sap-com:document:sap:rfc:functions

You could see it in the RFC imported.

Regards.

Answers (1)

Answers (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

The conversion is not simple approach. I would use java mapping and retrieve each value from the table tag and move it in <TR> segment respectively.  Also at the beginning you need to add <html> tags and <Body> tags around the table tag.  Please remember this will be displayed as html table only if you view the mail in the browser.

Former Member
0 Kudos

Thanks for the quick reply!

So, I can use the SplitByValue function to concat all the records to each other? Is there a example of this method available?

If I set the ContentType to "text/html", the user will see the table in his email right?

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You can use xml parsers in the java mapping to read the data for evcry node and retrieve individual field elements value easily. If you want splitbyvalue function..  please read below

http://www.saptechnical.com/Tutorials/XI/NodeFunctions/Page7.htm

If I set the ContentType to "text/html", the user will see the table in his email right?

I believe so. Provided your email client also should support this.

Former Member
0 Kudos

Ok, and how do I "read the data for every node"? With an UDF?