This an option to easy read an EDI 850 File,

In this case you need no to implement a complex java to read the file.

When you need to deal with EDI 850 Purchase order. If there are no option to get SAP B2B Addon.

You don’t need to write a complex code to read the segments and structures.

This is the easy way, you use this class to get an XML with the information of an EDI File, then you can use message mapping, and the set of powerful tools provided by SAP Process Orchestration.

 

This is a sample using com.berryworks.edireader.EDIReader.

 

From EDI to XML using Java Mapping

Why to Write Java Map:

In one client projects there was few inbound EDI interface, then client like not to invest in SAP B2B Addon. Then java map is used to achieve EDI to XML.

 

 

This is the imput file sample:

ISA*00* *00* *ZZ*0011223456 *ZZ*999999999 *990320*0157*U*00300*000000015*0*P*~$
GS*PO*0011223456*999999999*950120*0147*5*X*003040$
ST*850*000000001$
BEG*00*SA*95018017***950118$
N1*SE*UNIVERSAL WIDGETS$
N3*375 PLYMOUTH PARK*SUITE 205$
N4*IRVING*TX*75061$
N1*ST*JIT MANUFACTURING$
N3*BUILDING 3B*2001 ENTERPRISE PARK$
N4*JUAREZ*CH**MEX$
N1*AK*JIT MANUFACTURING$
N3*400 INDUSTRIAL PARKWAY$
N4*INDUSTRIAL AIRPORT*KS*66030$
N1*BT*JIT MANUFACTURING$
N2*ACCOUNTS PAYABLE DEPARTMENT$
N3*400 INDUSTRIAL PARKWAY$
N4*INDUSTRIAL AIRPORT*KS*66030$
PO1*001*4*EA*330*TE*IN*525*VN*X357-W2$
PID*F****HIGH PERFORMANCE WIDGET$
SCH*4*EA****002*950322$
CTT*1*1$
SE*20*000000001$
GE*1*5$
IEA*1*000000015$

 

This is the Output XML sample:

 

    
00 SA 95018017 950118 SE UNIVERSAL WIDGETS 375 PLYMOUTH PARK SUITE 205 IRVING TX 75061 ST JIT MANUFACTURING BUILDING 3B 2001 ENTERPRISE PARK JUAREZ CH MEX AK JIT MANUFACTURING 400 INDUSTRIAL PARKWAY INDUSTRIAL AIRPORT KS 66030 BT JIT MANUFACTURING ACCOUNTS PAYABLE DEPARTMENT 400 INDUSTRIAL PARKWAY INDUSTRIAL AIRPORT KS 66030 001 4 EA 330 TE IN 525 VN X357-W2 F HIGH PERFORMANCE WIDGET 4 EA 002 950322 1 1

 

+++Important you need an aditional JAR: edireader-4.7.3.jar, it is esasy to find on Internet.

This is the source code for Java Mapping:

 import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import com.berryworks.edireader.EDIReader; import com.berryworks.edireader.error.EDISyntaxExceptionHandler; import com.berryworks.edireader.error.RecoverableSyntaxException; import com.sap.aii.mapping.api.AbstractTransformation; import com.sap.aii.mapping.api.StreamTransformationException; import com.sap.aii.mapping.api.TransformationInput; import com.sap.aii.mapping.api.TransformationOutput; public class EdiTransformer extends AbstractTransformation { boolean namespaceEnabled=true; boolean recover=true; // @Owverride public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException { this.execute(arg0.getInputPayload().getInputStream(), arg1 .getOutputPayload().getOutputStream()); } public void execute(InputStream in, OutputStream out) { try { XMLReader ediReader = new EDIReader(); // Tell the ediReader if an xmlns="https://..." is desired if (namespaceEnabled) { ((EDIReader) ediReader).setNamespaceEnabled(namespaceEnabled); } // Tell the ediReader to handle EDI syntax errors instead of aborting if (recover) { ((EDIReader) ediReader).setSyntaxExceptionHandler(new IgnoreSyntaxExceptions()); } // Establish the SAXSource //Reader inputReader = in.; InputSource inputSource = new InputSource(in); //getTrace().addWarning("prueba "+inputSource.toString()); SAXSource source = new SAXSource(ediReader, inputSource); // Establish a Transformer Transformer transformer = TransformerFactory.newInstance().newTransformer(); // Use a StreamResult to capture the generated XML output StreamResult result = new StreamResult(out); // Call the Transformer to generate XML output from the parsed input transformer.transform(source, result); } catch (TransformerConfigurationException e) { System.err.println("  Unable to create Transformer: " + e); } catch (TransformerException e) { System.err.println("  Failure to transform: " + e); System.err.println(e.getMessage()); } try { in.close(); } catch (IOException ignored) { } try { out.close(); } catch (IOException ignored) { } } static public void main(String[] args) { EdiTransformer parser = new EdiTransformer(); try { FileInputStream in = new FileInputStream("d:\edi_file_in.edi"); FileOutputStream out = new FileOutputStream("d:\xml_file_out.xml"); parser.execute(in, out); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } static class IgnoreSyntaxExceptions implements EDISyntaxExceptionHandler { public boolean process(RecoverableSyntaxException syntaxException) { System.out.println("Syntax Exception. class: " + syntaxException.getClass().getName() + " message:" + syntaxException.getMessage()); // Return true to indicate that you want parsing to continue. return true; } } } 

 

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !