Handling Multiple Attachments Using Java Mapping - SAP PI
This document describes the steps for creating the PI java mapping to handle multiple attachments and create multimapping structure combining each attachment. This also covers use of IOStream to download attachments to application server.
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
75%(4)75% found this document useful (4 votes)
3K views23 pages
Handling Multiple Attachments Using Java Mapping - SAP PI
This document describes the steps for creating the PI java mapping to handle multiple attachments and create multimapping structure combining each attachment. This also covers use of IOStream to download attachments to application server.
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 23
Page | 1
Handling Multiple Attachments using
Java Mapping
Version 1.0
Page | 2
Document Information
Document Name Handling multiple attachments using Java mapping Component Description This document describes the steps for creating the PI java mapping to handle multiple attachments and create multimapping structure combining each attachment. This also covers use of IOStream to download attachments to application server. SAP Component Used SAP PI 7.4 , SAP Netweaver Development Studio 7.3
Version History Version Author Issue Purpose Date 1.0 Ankit Soni Initial Version 24/06/14
Page | 3
Table of Contents 1. General Description ........................................................................................................................... 4 2. Dependencies ..................................................................................................................................... 5 2.1 Dependent Tools ........................................................................................................................ 5 2.2 Jar Files Dependency ................................................................................................................ 5 3. User Guidelines .................................................................................................................................. 6 3.1 Implementation Steps ................................................................................................................ 6 3.1.1 Create a new Java Project in NWDS .............................................................................. 6 3.1.2 Include External Jars in Project so that Java class can be compiled ......................... 9 3.1.3 Create a Java Class ......................................................................................................... 11 3.1.4 Enter the Code MultipleAttachment Class .................................................................... 14 3.1.5 Compile and create JAR file ........................................................................................... 17 3.1.6 Add the Java mapping in OM ......................................................................................... 19 3.1.7 Testing the Mapping ........................................................................................................ 20 3.2 Troubleshooting & Error Handling ......................................................................................... 23 4. Reference Code ............................................................................................................................... 23
Page | 4
1. General Description
Invoices from external parties are sent as attachments in email to middleware system PI. PI is required to read all the attachments and download them to application server and then create an INVOIC.INVOIC02 IDOC from each XML file and send the path where the XML file was written to a field in IDOC. Currently with standard feature, we cannot handle multiple attachments using mail adapter also file receiver adapter does not have feature to write attachments. This requirement has been achieved by writing a java mapping which reads all attachment from email and generates the multi-mapping structure which is then used in second message mapping to generate IDOCs. Java APIs for PI have been used to access the attachments & set the name of the attachments. IOStream Java classes are used to download the attachments.
SUPPLIERS SAP PI SAP ECC Mail(Multiple attachments) One INVOIC02 IDOC per attachment
Page | 5
2. Dependencies 2.1 Dependent Tools
Before using this technical component the following tools need to be installed and configured. SAP Netweaver Development Studio 7.3
2.2 Jar Files Dependency
In order to develop the module locally on the NW Developer Studio, some PI libraries will be required. These libraries must be included in the external libraries during development.
A Mail to IDOC scenario should be created first. PI would read mail from the Mail server and create multi mapping structure from the attachments. This document does not list down details for configuring the scenario; it concentrates more on the steps to build the logic for the java mapping. However it should be ensured that the keep attachments option is ticked in the mail sender adapter and also in the operational mapping. This would enable that mail attachments are read and sent as attachments through PI.
3.1.1 Create a new Java Project in NWDS
In SAP NW Developer Studio, follow the below steps: Create a new project by using menu: File New Project Select Java Project. Click Next
Page | 7
Page | 8
Assign project name to Java Project. Java Project Name: MultipleAttachment. Click Next. Page | 9
3.1.2 Include External Jars in Project so that Java class can be compiled
Add External Jars required Go to Libraries tab. Click on Add External JARs. Select the jar files from directory which we extracted. Click Finish. Page | 10
Page | 11
3.1.3 Create a Java Class
Create a Java class extending AbstractTransformation class Right click on src and select New Class Page | 12
Assign name to package and Class and select parent class as AbstractTransformation package name: com.sap.multipleattachment class name: MultipleAttachment Click on Browse for Superclass Select AbstractTransformation class from the list and click OK. Click Finish. Page | 13
Page | 14
3.1.4 Enter the Code MultipleAttachment Class
Double click MultipleAttachment.java The Java program will be displayed on the right hand panel. Following screenshot shows the code to be written in the java file. Save the file.
Page | 15
Page | 16
Page | 17
3.1.5 Compile and create JAR file
Compile the code and create JAR file. Click on File Export Select JAR file and click Next. Select the files to be exported. Provide the name for JAR file and click Finish.
Page | 18
Page | 19
3.1.6 Add the Java mapping in OM
Create an Imported archive and add java mapping as first step in OM. Below are the screenshot of OM and second step message mapping after multi-mapping structure is available after java mapping.
Page | 20
3.1.7 Testing the Mapping
Testing Steps: Step1 A Mail containing three attachments is sent. Page | 21
Step2 Mail and three attachments is received by PI System.
The screenshot below shows XML message in PI. Page | 22
Step3 Java mapping reads all attachment and download it to application server and generates a multi- mapping structure. Below screenshot shows files for attachments created on target directory which was passed as parameter to Java mapping.
Step4 Java mapping creates a node for each XML in multi-mapping structure each of which creates one INVOIC.INVOIC02 IDOC
Page | 23
3.2 Troubleshooting & Error Handling
Following is the list of possible error scenarios and steps to handle them. Type Error Description Troubleshooting/Resolution Steps Exception IOException If any exception occurs in the IO stream Code to download attachments, the exception raised in the mapping can be seen in the Message Log. These logs can be viewed for troubleshooting the issue. Exception Mapping Exception The message log can viewed for any exception occurring in the mapping.
4. Reference Code
The code used in java mapping has been provided below as an attachment.