236038144-handling-multiple-attachments-using-java-mapping-sap-pi.pdf

Upload: robertofaccini64

Post on 02-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    1/23

    Page | 1

    Handling Multiple Attachments usingJava Mapping

    Version 1.0

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    2/23

    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 tohandle multiple attachments and create multimapping structurecombining each attachment. This also covers use of IOStream todownload 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

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    3/23

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    4/23

    Page | 4

    1. General Description

    Invoices from external parties are sent as attachments in email to middleware system PI. PI is required toread all the attachments and download them to application server and then create an INVOIC.INVOIC02IDOC 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 filereceiver adapter does not have feature to write attachments.

    This requirement has been achieved by writing a java mapping which reads all attachment from email andgenerates the multi-mapping structure which is then used in second message mapping to generateIDOCs. 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.

    SUPPLIERSSAP PI SAP ECC

    Mail(Multiple attachments) One INVOIC02 IDOC per attachment

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    5/23

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    6/23

    Page | 6

    3. User Guidelines

    3.1 Implementation Steps

    A Mail to IDOC scenario should be created first. PI would read mail from the Mail server and create multimapping structure from the attachments. This document does not list down details for configuring thescenario; 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 andalso in the operational mapping. This would enable that mail attachments are read and sent asattachments 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

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    7/23

    Page | 7

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    8/23

    Page | 8

    Assign project name to Java Project.

    Java Project Name: MultipleAttachment.

    Click Next.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    9/23

    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.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    10/23

    Page | 10

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    11/23

    Page | 11

    3.1.3 Create a Java Class

    Create a Java class extending AbstractTransformation class

    Right click on src and select NewClass

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    12/23

    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

    SelectAbstractTransformationclass from the list and click OK.

    Click Finish.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    13/23

    Page | 13

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    14/23

    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.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    15/23

    Page | 15

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    16/23

    Page | 16

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    17/23

    Page | 17

    3.1.5 Compile and create JAR file

    Compile the code and create JAR file.

    Click on File Export

    Select JARfile and click Next.

    Select the files to be exported.

    Provide the name for JAR file and click Finish.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    18/23

    Page | 18

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    19/23

    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 OMand second step message mapping after multi-mapping structure is available after java mapping.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    20/23

    Page | 20

    3.1.7 Testing the Mapping

    Testing Steps:

    Step1A Mail containing three attachments is sent.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    21/23

    Page | 21

    Step2Mail and three attachments is received by PI System.

    The screenshot below shows XML message in PI.

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    22/23

    Page | 22

    Step3Java 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.

    Step4Java mapping creates a node for each XML in multi-mapping structure each of which creates

    one INVOIC.INVOIC02 IDOC

  • 8/10/2019 236038144-Handling-Multiple-Attachments-Using-Java-Mapping-SAP-PI.pdf

    23/23

    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 downloadattachments, the exception raised in the mapping can be

    seen in the Message Log. These logs can be viewed fortroubleshooting the issue.

    Exception Mapping Exception The message log can viewed for any exception occurring inthe mapping.

    4. Reference Code

    The code used in java mapping has been provided below as an attachment.