Skip to end of metadata
Go to start of metadata

If you want to convert a Text file into another format like xml, pdf, excel, doc etc we have 2 options. We have Content

Conversion Parameters. If you are familier and conformatable with Java then Java Mapping is the best approach.

Here I am presenting the Sample  Java Mapping Code for Conversion.

My Text File will contains the structure like this..

empno,empname,address

Vasu,007,Tirupati ;
Chandra,008,Tirupati ;
Sabarish,009,Tirupati ;
Vinod,010,Tirupati ;

Here the fieldSeperator is "," and the endSeperator is ";"

The java Code is like this...

import java.io.*;
import java.util.Map;
import com.sap.aii.mapping.api.*;

public class sampleJavaMappingCode implements StreamTransformation {

public static void main(Strings[] args) {

try

Unknown macro: {     InputStream inputstream = new FileInputStream(new File("inputfile.txt}

catch (Exception e)  

Unknown macro: {     outputstream.write("Error }

 }

 public void execute(InputStream inputstream, OutputStream output) throws StreamTransformationException  {

  outputstream.write("<?xml version = '1.0' encoding = 'utf-8'>".getBytes());
  outputstream.write(<ns0:outputinfo ns0=\urn:xyz\File_File\>".getBytes());

  String newline=null;

  BufferedReader br = new BufferedReader(new InputStreamReader(inputstream));
 
  StringBuffer sb = new StringBuffer();
  
  while(newline = br.readLine())!=null)
  {

   String empno=null;
   String empname=null;
   String native=null;

   char[] chr = new char[100];
   chr = newline.toCharArray();

   String[] data = new String[10];

   int a = 0;
   int b = 2;

   for(int i=0;i<newline.length(); i++)
   {
    
    if(chr[i]==',') 

Unknown macro: {       data[a]=newline.substring(b,i);       a=a+1;       b=i+1;   }

    empno=data[0];
    empname=data[1];
    native=data[2];

    outputstream.write("<Data>".getBytes());
    outputstream.write("<Record>".getBytes());
    outputstream.write(("<EmpNo>"empno"</Empno>").getBytes()); 
    outputstream.write(("<EmpName>"empname"</Empname>").getBytes());
    outputstream.write(("<Native>"native"</Native>").getBytes());
    outputstream.write(("</Record>".getBytes());
    outputstream.write("</Data>".getBytes());

   }
   outputstream.write("</ns0:outputinfo>".getBytes());
  }
  catch(Exception e)
  

Unknown macro: {    outputstream.write("Error }

  br.close();
  inputstream.close();
  outputstream.close();
 }
}

Compile the Java Code and create a Jar File and create a Jar File using the command

jar -cvf  sampleJavaMappingCode.jar  sampleJavaMappingCode.class

And import the jar file in the imported Archeve and in the Interface Mapping select the source and target Message types and

give the MessageMapping as  sampleJavaMappingCode.jar and give the jar file in the Interface Mapping.

1 Comment

  1. Anonymous

    Hi Vasu

     Good Work..

    Regards

    Vinod..