Skip to Content
Author's profile photo Former Member

Sending mail in tabular format

Dear SCN members ,

Recently I have worked on a requirement of sending mail in a tabular format using mail package .I want to share my knowledge on this as it took longer time for me to fine tune the code ,hope it might be useful for others to quickly develop interfaces with similar functionality .

Functionality: PI will receive employee pension reports in the form of IDocs from SAP ECC .PI need to send these details in mail (tabular format) to concerned parties .

I have used two mappings to achieve the above functionality

1)Mapping1 (Graphical Mapping) :To capture the employee pension report details from IDoc and put those in a temporary structure .

2)Mapping2 (XSLT Mapping) :To send the above details in tabular format to concern business parties .

Mapping1:

Mapping1.JPG

Mapping2:(Mapping1 O/P will be given as input to Mapping2)


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:ns0="YourNameSpace">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:variable name="break">&lt;br&gt;</xsl:variable>
  <xsl:variable name="tableB">&lt;table BORDER="5"&gt;</xsl:variable>
  <xsl:variable name="tableE">&lt;/table&gt;</xsl:variable>
  <xsl:variable name="trB">&lt;tr&gt;</xsl:variable>
  <xsl:variable name="trE">&lt;/tr&gt;</xsl:variable>
  <xsl:variable name="tdB">&lt;td&gt;</xsl:variable>
  <xsl:variable name="tdE">&lt;/td&gt;</xsl:variable>
  <xsl:variable name="nbsp"> </xsl:variable>
  <xsl:variable name="thB">&lt;tr BGCOLOR="#CCCC99"&gt;</xsl:variable>
<xsl:template match="/">
<ns1:Mail xmlns:ns1="http://sap.com/xi/XI/Mail/30">
  <Subject>Error Report of XYZ interface</Subject>
<From>
  <xsl:value-of select="ns0:PensionErrorReports/FROM"/>
  </From>
<To>
  <xsl:value-of select="ns0:PensionErrorReports/TO"/>
  </To>
  <Content_Type>text/html</Content_Type>
<Content>
<b><xsl:text>Hi Team,</xsl:text></b>
<xsl:value-of select="$break" />
<xsl:value-of select="$break" />
<b><xsl:text>There was an error from SAP ECC while processing IDOC for the interface XYZ. Below are the details. Please take required action immediately.</xsl:text></b>
  <xsl:value-of select="$break" />
  <xsl:value-of select="$break" />
  <xsl:value-of select="$tableB" />
  <xsl:value-of select="$thB" />
  <xsl:value-of select="$tdB" />
<b>
  <xsl:text>Payroll number</xsl:text>
  </b>
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
<b>
  <xsl:text>Name</xsl:text>
  </b>
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
<b>
  <xsl:text>Formatted Name of Emp(or)Applicant</xsl:text>
  </b>
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
<b>
  <xsl:text>COMMENT</xsl:text>
  </b>
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
<b>
  <xsl:text>Date of Transfer</xsl:text>
  </b>
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$trE" />
<xsl:for-each select="ns0:PensionErrorReports/Pension_ErrorReports">
  <xsl:value-of select="$trB" />
  <xsl:value-of select="$tdB" />
  <xsl:value-of select="PayrollNumber" />
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
  <xsl:value-of select="EMPLOYEE_INITIALS" />
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
  <xsl:value-of select="EDIT_NAME" />
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
  <xsl:value-of select="COMMENT" />
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$tdB" />
  <xsl:value-of select="DateOfTransfer" />
  <xsl:value-of select="$nbsp" />
  <xsl:value-of select="$tdE" />
  <xsl:value-of select="$trE" />
  </xsl:for-each>
  <xsl:value-of select="$tableE" />
  <xsl:value-of select="$break" />
  <xsl:value-of select="$break" />
  <xsl:value-of select="$break" />
  <xsl:value-of select="$break" />
  <b><xsl:text>Regards</xsl:text></b>
  <xsl:value-of select="$break" />
  <b><xsl:text>Appsupport Team</xsl:text></b>
  </Content>
  </ns1:Mail>
  </xsl:template>
  </xsl:stylesheet>



Zip and import the above .xsl file as a imported archive in PI.Now create the operation mapping as below

Source:IDoc

Target:Service Interface for standard Mail Package

Here I’m using From,To parameters to get From and To mail id’s dynamically.

OM.JPG

Now Create the ID objects as below. (You can also use ICO if you are using IDOC_AAE)

ID.JPG

Test Cases:


Input IDoC XML payload: PI received 2 IDocs in a package


Test1.JPGTest2.JPG



Output Mail generated :


output1.JPG



While doing this scenario a common doubt will be raised ,i.e “What if the length of the text is more ,does it gets skipped or will be populated ?”


Here is the answer:It automatically gets adjusted and populates the text .


output2.JPG



Assigned tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Bhargava krishna Talasila
      Bhargava krishna Talasila

      Great blog 🙂

      Author's profile photo Mahesh C
      Mahesh C

      Thanks for sharing.. Keep up the good work.

      Author's profile photo Naveen Kumar Reddy chichili
      Naveen Kumar Reddy chichili

      Good to see this info... Thanks for the blog

      Regards,

      Naveen    

      Author's profile photo Former Member
      Former Member

      Hi Venkat,

      Great Blog. Thanks a lot.

      is there any specific reason to use XSLT as 2nd map? cant we do it inside a UDF?

      Regards,

      Gavaksh

      Author's profile photo Avinash Ayanala
      Avinash Ayanala

      Hi Venkat,

      It is really a good info. great!

      Author's profile photo Monikandan Panneerselvam
      Monikandan Panneerselvam

      Nice work Venkat!!