Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member1
Active Participant

This blog will help in creating an application to send the IDoc from JAVA to ERP System.

JCO 3.0 & SAP IDoc Library 3.0 provides 2 ways in which the IDoc can be sent to the ERP System

  1. Sending an IDOC as IDOCDocument
    • In this the user can manually create an IDOC Document and can send it to the ERP System
  2. Creating an IDOC as XML and sending as Document List
    • In this User can generate XML and then can send the XML as IDocDocumentList

Prerequisite:

  • JDK/JRE 5,6,7
  • sapjco3.jar
  • sapidoc3.jar

sapjco3.jar & sapidoc3.jar can be downloaded from http://service.sap.com/connectors

If the version of Java 1.3 or 1.4 then user should use JCO 2.1. Class structure is different in that and is not covered in this blog

This blog provides the step by step process to send an IDOC using JCO 3.0 and Java IDOC Class Library 3.0.

The Class BaseIDocInboundWrapper (Step 1) & IDocInboundWrapper (Step 2) can be reused for all the IDoc Types

Step1. Create a Class BaseIDocInboundWrapper

Sample Class Code for BaseIDocInboundWrapper

package com.idoc.sender;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.idoc.IDocFactory;
import com.sap.conn.idoc.IDocRepository;
import com.sap.conn.idoc.jco.JCoIDoc;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
/**
* Base Class to send the IDoc to the ERP System
* This class creates the connection to the ERP System
* This class also prepares to send the IDoc Files to the ERP System 
* This Class Throws JCO Exception
*
* @author Saxena, Anish - mailto:anish.saxena@gmail.com
*
*/
public class BaseIDocInboundWrapper {
          //FIXME:READ GLOBAL ATTRIBUTES FROM PROPERTIES FILE
          //Name of the Destination File
          private static final String DESTINATION_NAME                     = "SampleDestination";
          //Connection Attributes for SAP ERP System
          private static final String JCO_AS_HOST_NAME          = "HOST_NAME";
          private static final String JCO_SYSTEM_NR                = "SYSTEM_NR";
          private static final String JCO_CLIENT_NR                   = "CLIENT_NR";
          private static final String JCO_USER_NAME                               = "USER_NAME";
          private static final String JCO_PASSWORD                               = "PASSWORD";
          private static final String JCO_LANGUAGE                               = "LANGUAGE"; //EN OR DE etc...
          protected static JCoDestination JCO_DESTINATION;
          protected static IDocRepository IDOC_REPOSITORY;
          protected static String TID;
          protected static IDocFactory IDOC_FACTORY;
          /**
           * This method initializes the class and also connects to the ERP System
           * @throws JCoException
           */
          public BaseIDocInboundWrapper() throws JCoException {
                    connectionProperties();
                    prepareERPForIDoc();
          }
          /**
           * Create Destination Data File for the Connection
           * @param l_oConnectionProperties
           */
          private static void createDestinationDataFile(final Properties l_oConnectionProperties){
                    File destCfg = new File(DESTINATION_NAME+".jcoDestination");
                    try{
                              FileOutputStream fos = new FileOutputStream(destCfg, false);
                              l_oConnectionProperties.store(fos, "for tests only !");
                              fos.close();
                    } catch (Exception e) {
                              throw new RuntimeException("Unable to create the destination files", e);
                    }
          }
          /**
           * This method is initialized from the Constructor
           * This method creates the connection properties file and then stores is in the default location
           */
          private static void connectionProperties(){
                    Properties connectionProperties = new Properties();
                    connectionProperties.setProperty(DestinationDataProvider.JCO_ASHOST,JCO_AS_HOST_NAME);
                    connectionProperties.setProperty(DestinationDataProvider.JCO_SYSNR, JCO_SYSTEM_NR);
                    connectionProperties.setProperty(DestinationDataProvider.JCO_CLIENT, JCO_CLIENT_NR);
                    connectionProperties.setProperty(DestinationDataProvider.JCO_USER, JCO_USER_NAME);
                    connectionProperties.setProperty(DestinationDataProvider.JCO_PASSWD, JCO_PASSWORD);
                    connectionProperties.setProperty(DestinationDataProvider.JCO_LANG, JCO_LANGUAGE);
                    createDestinationDataFile(connectionProperties);
          }
          /**
           * This method is initialized from the Constructor
           * This method creates the connection to the ERP System and prepares to send IDoc to ERP System
           * @throws JCoException
           */
          private static void prepareERPForIDoc() throws JCoException{
                    // get the JCo destination
                    JCO_DESTINATION = JCoDestinationManager.getDestination(DESTINATION_NAME);
                    // Create repository
                    IDOC_REPOSITORY = JCoIDoc.getIDocRepository(JCO_DESTINATION);
                    TID = JCO_DESTINATION.createTID();
                    IDOC_FACTORY = JCoIDoc.getIDocFactory();
          }
}

Step 2. Create a Class IDocInboundWrapper that will extend BaseIDocInboundWrapper created above

Sample Code for IDocInboundWrapper

package com.idoc.sender;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import com.sap.conn.idoc.IDocDocument;
import com.sap.conn.idoc.IDocDocumentList;
import com.sap.conn.idoc.IDocFactory;
import com.sap.conn.idoc.IDocIllegalTypeException;
import com.sap.conn.idoc.IDocMetaDataUnavailableException;
import com.sap.conn.idoc.IDocParseException;
import com.sap.conn.idoc.IDocSegment;
import com.sap.conn.idoc.IDocSyntaxException;
import com.sap.conn.idoc.IDocXMLProcessor;
import com.sap.conn.idoc.jco.JCoIDoc;
import com.sap.conn.jco.JCoException;
/**
* Class to Send the IDoc to the ERP System
* It is a GENERIC Class for ALL Types of IDocs
* This class implements 2 Ways of sending IDoc to ERP System
* Option1: Create IDoc Document and Send to ERP System. A new IDocDocument can also be fetched from this class
* Option2: Read IDoc XML and Send to ERP System  
* When the class is initialized connection to the ERP System is created.
* This Class Throws JCO Exception
*
* @author Saxena, Anish - mailto:anish.saxena@gmail.com
*
*/
public class IDocInboundWrapper extends BaseIDocInboundWrapper{
          /**
           * This method initializes the class and also connects to the ERP System
           * @throws JCoException
           */
          public IDocInboundWrapper() throws JCoException {
                    super();
          }
          /**
           * Creates an Empty IDocDocument for the connected Repository/ERP and returns the IDocDocument
           * The value has to be stored in this IDocDocument 
           * @param p_sIDocType
           * @return IDocDocument
           * @throws IDocMetaDataUnavailableException
           */
          public IDocDocument getNewIDocDocument(String p_sIDocType) throws IDocMetaDataUnavailableException{
                    IDocDocument l_oIDocDocument = IDOC_FACTORY.createIDocDocument(IDOC_REPOSITORY, p_sIDocType);
                    return l_oIDocDocument;
          }
          /**
           * This method takes the IDocDocument as the input parameter
           * and sends it to the ERP System
           * On Success, it returns true else throws corresponding Exception
           * @see getNewIDocDocument() for getting an Empty IDoc for setting the Data.
           * @param p_oIDocDocument
           * @return boolean
           * @throws IDocSyntaxException
           * @throws IDocMetaDataUnavailableException
           * @throws JCoException
           */
          public boolean sendIDocAsIDocDocument(IDocDocument p_oIDocDocument) throws IDocSyntaxException, IDocMetaDataUnavailableException, JCoException{
                    p_oIDocDocument.checkSyntax();
                    JCoIDoc.send(p_oIDocDocument, IDocFactory.IDOC_VERSION_DEFAULT, JCO_DESTINATION, TID);  
                    JCO_DESTINATION.confirmTID(TID);
                    return true;
          }
          /**
           * This method takes the XML Location and XML FileName as the input parameter
           * Reads the XML File and sends it to the ERP System
           * On Success, it returns true else throws corresponding Exception
           * p_sFileName is the name of the file with the extension
           * @param p_sLocation
           * @param p_sFileName
           * @return boolean
           * @throws IOException
           * @throws IDocParseException
           * @throws JCoException
           * @throws IDocSyntaxException
           * @throws IDocMetaDataUnavailableException
           */
          public boolean sendIDocAsIDocXML(String p_sLocation, String p_sFileName) throws IOException, IDocParseException, JCoException, IDocSyntaxException, IDocMetaDataUnavailableException{
                    String l_sIDocXML = this.readIDocXML(p_sLocation+"\\"+p_sFileName);
              IDocXMLProcessor l_oIDocXMLProcessor = IDOC_FACTORY.getIDocXMLProcessor();
        IDocDocumentList l_oIDocDocumentList = l_oIDocXMLProcessor.parse(IDOC_REPOSITORY, l_sIDocXML);
        for(int i=0; i<l_oIDocDocumentList.size(); i++){
                  IDocDocument l_oIDocDocument = l_oIDocDocumentList.get(i);
                  l_oIDocDocument.checkSyntax();
        }
        JCoIDoc.send(l_oIDocDocumentList, IDocFactory.IDOC_VERSION_DEFAULT, JCO_DESTINATION, TID);
        JCO_DESTINATION.confirmTID(TID);
        return true;
          }
          /**
           * This method takes Fully Qualified FileName along with Path as the input parameter.
           * It reads the file from the Location and returns the string value of the XML
           * @param p_sFullQualifiedFileName
           * @return String
           * @throws IOException
           */
          private String readIDocXML(String p_sFullQualifiedFileName) throws IOException{
                    String l_sIDocXML = null;
                    FileReader l_oFileReader;
                    l_oFileReader = new FileReader(p_sFullQualifiedFileName);
                    BufferedReader l_oBufferedReader = new BufferedReader(l_oFileReader);
                    StringBuffer l_oStringBuffer = new StringBuffer();
                    String l_sLine;
                    while ((l_sLine = l_oBufferedReader.readLine()) != null){
                              l_oStringBuffer.append(l_sLine);
                    }
                    l_sIDocXML = l_oStringBuffer.toString();
                    l_oBufferedReader.close();
                    l_oFileReader.close();
                    return l_sIDocXML;
          }
          /**
           * Main Method
           * Sample Method shows how to test this class
           * @param args
           */
          public static void main(String[] args){
                    /*
                     * WAY 1 SENDING AN IDOC AS IDOCDOCUMENT
                     */
                    try {
                              IDocInboundWrapper l_oIDocInboundReceiptWrapper = new IDocInboundWrapper();
                              IDocDocument l_oIDocDocument = l_oIDocInboundReceiptWrapper.getNewIDocDocument("WPUBON01");
                              IDocSegment l_oIDocSegment = l_oIDocDocument.getRootSegment();
                              l_oIDocSegment = l_oIDocSegment.addChild("E1WPB01");
                              // and so on. User can refer the IDoc Specification for creating the IDoc Structure
                              @SuppressWarnings("unused")
                              boolean l_oResponse = l_oIDocInboundReceiptWrapper.sendIDocAsIDocDocument(l_oIDocDocument);
                              //IF l_oResponse is true then the send was successful
                    } catch (IDocIllegalTypeException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocIllegalTypeException has occured :: "+ oX.getMessage());
                    } catch (IDocSyntaxException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocSyntaxException has occured :: "+ oX.getMessage());
                    } catch (IDocMetaDataUnavailableException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocMetaDataUnavailableException has occured :: "+ oX.getMessage());
                    } catch (JCoException oX) {
                              oX.printStackTrace();
                              System.out.println("A JCoException has occured :: "+ oX.getMessage());
                    }
                    /*
                     * WAY 2 SENDING AN IDOC AS IDOCXML
                     */
                    try {
                              IDocInboundWrapper l_oIDocInboundReceiptWrapper = new IDocInboundWrapper();
               String l_sLocation = "C:\\Anish_Documents\\SAMPLE_IDOC_XML\\INBOUND";
                              @SuppressWarnings("unused")
                              boolean l_oResponse = l_oIDocInboundReceiptWrapper.sendIDocAsIDocXML(l_sLocation, "TestSalesOrder.xml");
                              //IF l_oResponse is true then the send was successful
                    } catch (IDocSyntaxException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocSyntaxException has occured :: "+ oX.getMessage());
                    } catch (IDocParseException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocParseException has occured :: "+ oX.getMessage());
                    } catch (IDocMetaDataUnavailableException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocMetaDataUnavailableException has occured :: "+ oX.getMessage());
                    } catch (IOException oX) {
                              oX.printStackTrace();
                              System.out.println("An IOException has occured :: "+ oX.getMessage());
                    } catch (JCoException oX) {
                              oX.printStackTrace();
                              System.out.println("A JCoException has occured :: "+ oX.getMessage());
                    }
          }
}

The above Step 1 and Step 2 code is generic for all the IDoc Type.

The main method in the above class demonstrates how this class can be used to send IDOC to the ERP System. There are 2 Ways in which the IDOC can be sent.

WAY 1: The user can create the custom structure of the IDOC and then can send the IDOC as IDocDocument.

WAY 2: The user can generate the XML File for the IDOC in a particular structure and then can parse the IDOC as IDocDocumentList.

Step 3. In this step I will be showing the WAY 2 for sending an XML File as IDOC for the IDOC Type. This step has to be performed individually for each IDOC Type

Before proceeding with this step, Create the beans with the same structure as that of IDOC Type that has to be sent to ERP System as this will be referenced in the Class that we will create in this step. The structure of the corresponding IDOC can be found by logging on ERP and with T-Code WE20.

Create a Class IDocReceiptXMLInboundWrapper

Sample Code for IDocReceiptXMLInboundWrapper for IDOC TYPE "WPUBON01" (Sales Document / Receipt)

package com.idoc.sender;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import com.idoc.helper.EDI_DC40;
import com.idoc.helper.salesdocs.E1WPB01;
import com.idoc.helper.salesdocs.E1WPB02;
import com.idoc.helper.salesdocs.E1WPB03;
import com.idoc.helper.salesdocs.E1WPB04;
import com.idoc.helper.salesdocs.E1WPB05;
import com.idoc.helper.salesdocs.E1WPB06;
import com.idoc.helper.salesdocs.E1WPB07;
import com.idoc.helper.salesdocs.E1WXX01;
import com.idoc.helper.salesdocs.IDOC;
import com.idoc.helper.salesdocs.WPUBON01;
import com.sap.conn.idoc.IDocMetaDataUnavailableException;
import com.sap.conn.idoc.IDocParseException;
import com.sap.conn.idoc.IDocSyntaxException;
import com.sap.conn.jco.JCoException;
/**
* Wrapper Class for Sending the Sales Docs (Receipts) to the ERP System
* This class Creates the XML Format for the Sales Docs (Receipts)
* It stores the XML Format and then sends the stored XML to the ERP System
*
* @author Saxena, Anish - mailto:anish.saxena@gmail.com
*
*/
public class IDocReceiptXMLInboundWrapper{
          //FIXME:READ GLOBAL ATTRIBUTES FROM PROPERTIES FILE
          private static final String LOCATION = "C:\\Anish_Documents\\SAMPLE_IDOC_XML\\INBOUND";
          //FIXME:REMOVE FILE_NAME AND MAKE IT DYNAMIC BASED ON RECEIPT ID OR SO
          private static final String FILE_NAME = "RECEIPT_TEST.XML";
          /**
           * This method will create the IDoc Structure as Object
           * It will internally call corresponding objects to form the IDoc Object
           * @return WPUBON01
           */
          private WPUBON01 getWPUBON01(){
                    WPUBON01 l_oWPUBON01 = new WPUBON01();
                    l_oWPUBON01.setIDOC(getIDOC());
                    return l_oWPUBON01;
          }
          /**
           * @return IDOC
           */
          private IDOC getIDOC(){
                    IDOC l_oIDOC = new IDOC();
                    l_oIDOC.setBEGIN("1");
                    l_oIDOC.setEDI_DC40(getEDI_DC40());
                    l_oIDOC.setE1WPB01s(getE1WPB01s());
                    return l_oIDOC;
          }
          /**
           * This will return the Header Information of the IDoc as Object
           * This is common for all the IDocs. Setters with setSND* can be ignored
        * Direct shows its incoming or outgoing
           * as it is filled when Idoc is sent from ERP.
           * @return EDI_DC40
           */
          private EDI_DC40 getEDI_DC40(){
                    EDI_DC40 l_oEDI_DC40 = new EDI_DC40();
                    l_oEDI_DC40.setSEGMENT("1");
                    l_oEDI_DC40.setTABNAM("EDI_DC40");
                    l_oEDI_DC40.setMANDT("");
                    l_oEDI_DC40.setDOCNUM("");
                    l_oEDI_DC40.setDOCREL("");
                    l_oEDI_DC40.setSTATUS("");
                    l_oEDI_DC40.setDIRECT("");
                    l_oEDI_DC40.setOUTMOD("");
                    l_oEDI_DC40.setIDOCTYP("WPUBON01");
                    l_oEDI_DC40.setMESTYP("WPUBON");
                    l_oEDI_DC40.setSNDPOR("");
                    l_oEDI_DC40.setSNDPRT("");
                    l_oEDI_DC40.setSNDPRN("");
                    l_oEDI_DC40.setRCVPOR("");
                    l_oEDI_DC40.setRCVPRT("");
                    l_oEDI_DC40.setRCVPRN("");
                    l_oEDI_DC40.setCREDAT("");
                    l_oEDI_DC40.setCRETIM("");
                    l_oEDI_DC40.setSERIAL("");
                    return l_oEDI_DC40;
          }
          /**
           * List of Sales Documents / Receipts
           * @return List<E1WPB01>
           */
          private List<E1WPB01> getE1WPB01s(){
                    List<E1WPB01> l_oE1WPB01s = new ArrayList<E1WPB01>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WPB01 l_oE1WPB01 = new E1WPB01();
                    l_oE1WPB01.setSEGMENT("1");
                    l_oE1WPB01.setPOSKREIS("");
                    l_oE1WPB01.setKASSID("");
                    l_oE1WPB01.setVORGDATUM("");
                    l_oE1WPB01.setVORGZEIT("");
                    l_oE1WPB01.setBONNUMMER("");
                    l_oE1WPB01.setQUALKDNR("");
                    l_oE1WPB01.setKUNDNR("");
                    l_oE1WPB01.setKASSIERER("");
                    l_oE1WPB01.setCSHNAME("");
                    l_oE1WPB01.setBELEGWAERS("");
                    l_oE1WPB01.setE1WPB02s(getE1WPB02());
                    l_oE1WPB01.setE1WPB05s(getE1WPB05s());
                    l_oE1WPB01.setE1WPB07s(getE1WPB07s());
                    l_oE1WPB01.setE1WPB06s(getE1WPB06s());
                    l_oE1WPB01s.add(l_oE1WPB01);
                    return l_oE1WPB01s;
          }
          /**
           * List of Materials in Receipts
           * @return
           */
          private List<E1WPB02> getE1WPB02(){
                    List<E1WPB02> l_oE1WPB02s = new ArrayList<E1WPB02>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WPB02 l_oE1WPB02 = new E1WPB02();
                    l_oE1WPB02.setSEGMENT("1");
                    l_oE1WPB02.setVORGANGART("");
                    l_oE1WPB02.setQUALARTNR("");
                    l_oE1WPB02.setARTNR("");
                    l_oE1WPB02.setSERIENNR("");
                    l_oE1WPB02.setVORZEICHEN("-");
                    l_oE1WPB02.setMENGE("");
                    l_oE1WPB02.setVERKAEUFER("");
                    l_oE1WPB02.setAKTIONSNR("");
                    l_oE1WPB02.setREFBONNR("");
                    l_oE1WPB02.setE1WPB03s(getE1WPB03s());
                    l_oE1WPB02.setE1WPB04s(getE1WPB04s());
                    l_oE1WPB02.setE1WXX01s(getE1WXX01s());
                    l_oE1WPB02s.add(l_oE1WPB02);
                    return l_oE1WPB02s;
          }
          /**
           * Information about Material
           * @return List<E1WPB03>
           */
          private List<E1WPB03> getE1WPB03s(){
                    List<E1WPB03> l_oE1WPB03s = new ArrayList<E1WPB03>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WPB03 l_oE1WPB03 = new E1WPB03();
                    l_oE1WPB03.setSEGMENT("1");
                    l_oE1WPB03.setVORZEICHEN("");
                    l_oE1WPB03.setKONDITION("");
                    l_oE1WPB03.setKONDVALUE("");
                    l_oE1WPB03.setCONDID("");
                    l_oE1WPB03.setCONDID20("");
                    l_oE1WPB03.setQUALCONDID("");
                    l_oE1WPB03.setBBYNR("");
                    l_oE1WPB03s.add(l_oE1WPB03);
                    return l_oE1WPB03s;
          }
          /**
           *
           * @return List<E1WPB04>
           */
          private List<E1WPB04> getE1WPB04s(){
                    List<E1WPB04> l_oE1WPB04s = new ArrayList<E1WPB04>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WPB04 l_oE1WPB04 = new E1WPB04();
                    l_oE1WPB04.setSEGMENT("1");
                    l_oE1WPB04.setMWSKZ("");
                    l_oE1WPB04.setMWSBT("");
                    l_oE1WPB04s.add(l_oE1WPB04);
                    return l_oE1WPB04s;
          }
          /**
           *
           * @return List<E1WXX01>
           */
          private List<E1WXX01> getE1WXX01s(){
                    List<E1WXX01> l_oE1WXX01s = new ArrayList<E1WXX01>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WXX01 l_oE1WXX01 = new E1WXX01();
                    l_oE1WXX01.setSEGMENT("1");
                    l_oE1WXX01.setFLDGRP("");
                    l_oE1WXX01.setFLDNAME("");
                    l_oE1WXX01.setFLDVAL("");
                    l_oE1WXX01s.add(l_oE1WXX01);
                    return l_oE1WXX01s;
          }
          /**
           * Discount Information
           * @return List<E1WPB05>
           */
          private List<E1WPB05> getE1WPB05s(){
                    List<E1WPB05> l_oE1WPB05s = new ArrayList<E1WPB05>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WPB05 l_oE1WPB05 = new E1WPB05();
                    l_oE1WPB05.setSEGMENT("1");
                    l_oE1WPB05.setVORZEICHEN("");
                    l_oE1WPB05.setRABATTART("");
                    l_oE1WPB05.setRABSATZ("");
                    l_oE1WPB05.setRABVALUE("");
                    l_oE1WPB05.setCONDID("");
                    l_oE1WPB05.setCONDID20("");
                    l_oE1WPB05.setQUALCONDID("");
                    l_oE1WPB05.setBBYNR("");
                    l_oE1WPB05s.add(l_oE1WPB05);
                    return l_oE1WPB05s;
          }
          /**
           * Tax Data for Receipt
           * @return List<E1WPB07>
           */
          private List<E1WPB07> getE1WPB07s(){
                    List<E1WPB07> l_oE1WPB07s = new ArrayList<E1WPB07>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WPB07 l_oE1WPB07 = new E1WPB07();
                    l_oE1WPB07.setSEGMENT("1");
                    l_oE1WPB07.setTAXCODE("");
                    l_oE1WPB07.setTAXVALUE("");
                    l_oE1WPB07s.add(l_oE1WPB07);
                    return l_oE1WPB07s;
          }
          /**
           * Payment For the Receipt
           * @return List<E1WPB06>
           */
          private List<E1WPB06> getE1WPB06s(){
                    List<E1WPB06> l_oE1WPB06s = new ArrayList<E1WPB06>();
                    //FIXME:ADD THE FOR LOOP HERE
                    E1WPB06 l_oE1WPB06 = new E1WPB06();
                    l_oE1WPB06.setSEGMENT("1");
                    l_oE1WPB06.setVORZEICHEN("");
                    l_oE1WPB06.setZAHLART("");
                    l_oE1WPB06.setSUMME("");
                    l_oE1WPB06.setCCINS("");
                    l_oE1WPB06.setWAEHRUNG("");
                    l_oE1WPB06.setKARTENNR("");
                    l_oE1WPB06.setKARTENFNR("");
                    l_oE1WPB06.setGUELTAB("");
                    l_oE1WPB06.setGUELTBIS("");
                    l_oE1WPB06.setKONTOINH("");
                    l_oE1WPB06.setBANKLZ("");
                    l_oE1WPB06.setKONTONR("");
                    l_oE1WPB06.setAUTORINR("");
                    l_oE1WPB06.setTERMID("");
                    l_oE1WPB06.setTRTIME("");
                    l_oE1WPB06.setZUONR("");
                    l_oE1WPB06.setREFERENZ1("");
                    l_oE1WPB06.setREFERENZ2("");
                    l_oE1WPB06.setCCBEG("");
                    l_oE1WPB06.setCSOUR("");
                    l_oE1WPB06.setSETTL("");
                    l_oE1WPB06.setAUTRA("");
                    l_oE1WPB06.setLOCID("");
                    l_oE1WPB06.setREACT("");
                    l_oE1WPB06.setFLGAU("");
                    l_oE1WPB06.setCONDID("");
                    l_oE1WPB06.setCONDID20("");
                    l_oE1WPB06.setCARDGUID("");
                    l_oE1WPB06.setENCTYPE("");
                    l_oE1WPB06s.add(l_oE1WPB06);
                    return l_oE1WPB06s;
          }
          /**
           * Create Receipt IDoc XML and Stores it at the location with the file name
           * @param p_sFileName
           * @throws JAXBException
           */
          private void createReceiptIDocXML(String p_sFileName) throws JAXBException{
                    File l_oFile = new File(LOCATION+"\\"+p_sFileName);
                    JAXBContext l_oJAXBContext = JAXBContext.newInstance(WPUBON01.class);
                    Marshaller l_oJAXBMarshaller = l_oJAXBContext.createMarshaller();
                    l_oJAXBMarshaller.marshal(getWPUBON01(), l_oFile);
                    //TO PRETTY PRINT OUTPUT
                    l_oJAXBMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
                    //FIXME: TO REMOVE THIS l_oJAXBMarshaller.marshal(getWPUBON01(), System.out);
                    l_oJAXBMarshaller.marshal(getWPUBON01(), System.out);
          }
          /**
           * Send the Receipt to ERP. On Success returns true else throws exception
           * @return boolean
           * @throws JAXBException
           * @throws JCoException
           * @throws IDocSyntaxException
           * @throws IDocParseException
           * @throws IDocMetaDataUnavailableException
           * @throws IOException
           */
          public boolean sendReceipt() throws JAXBException, JCoException, IDocSyntaxException, IDocParseException, IDocMetaDataUnavailableException, IOException{
                    //FIXME: ADD A RECEIPT LOOP HERE
                    this.createReceiptIDocXML(FILE_NAME);
                    IDocInboundWrapper l_oIDocInboundReceiptWrapper = new IDocInboundWrapper();
                    boolean l_oResponse = l_oIDocInboundReceiptWrapper.sendIDocAsIDocXML(LOCATION, FILE_NAME);
                    return l_oResponse;
          }
          /**
           * Main Method
           * Sample Method shows how to use this class
           * @param args
           */
          public static void main(String[] args){
                    try {
                              IDocReceiptXMLInboundWrapper l_oIDocReceiptXMLInboundWrapper = new IDocReceiptXMLInboundWrapper();
                              boolean l_oResponse = l_oIDocReceiptXMLInboundWrapper.sendReceipt();
                              if(l_oResponse)
                                        System.out.println("Sales Doc (Receipt) Successfully Sent");
                    } catch (IDocSyntaxException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocSyntaxException has occured :: "+ oX.getMessage());
                    } catch (IDocParseException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocParseException has occured :: "+ oX.getMessage());
                    } catch (IDocMetaDataUnavailableException oX) {
                              oX.printStackTrace();
                              System.out.println("An IDocMetaDataUnavailableException has occured :: "+ oX.getMessage());
                    } catch (JAXBException oX) {
                              oX.printStackTrace();
                              System.out.println("A JAXBException has occured :: "+ oX.getMessage());
                    } catch (JCoException oX) {
                              oX.printStackTrace();
                              System.out.println("A JCoException has occured :: "+ oX.getMessage());
                    } catch (IOException oX) {
                              oX.printStackTrace();
                              System.out.println("An IOException has occured :: "+ oX.getMessage());
                    }
          }
}

Fill in the Values in the setter methods in each get... methods in the Class. This can be done by changing the method signature to accept parameters.

The main method describes how IDocReceiptXMLInboundWrapper Class can be executed. IDocReceiptXMLInboundWrapper  will internally call the classes created in Step 2 and Step 1.

For Converting the Object to XML, JAXB is used. 

After the program is executed with success message, Log in to ERP System and go to T-Code WE05. The IDoc should be visible there.

6 Comments
Labels in this area