cancel
Showing results for 
Search instead for 
Did you mean: 

Java map needed for text input file

former_member183906
Active Contributor
0 Kudos

Java map needed for text input file. The 1st line of text file will always come once. The 2nd line,3rd line given in example may have 4th and 5th dynamic lines,but length of characters will be same in the line

text input is like below -

081517693      TEST

03500701      TEST2

03500713      TEST3

text output should be like this -

H 081517693      TEST

D 03500701      TEST2

D 03500713      TEST3

i need exact java code to achieve this

Accepted Solutions (1)

Accepted Solutions (1)

Muniyappan
Active Contributor
0 Kudos

Hi,

can you try reading the files by lines and add the H and D in the message mapping?

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

I can understand that you need to this structure so that you can go for content conversion.

Does your file have only one header and multiple detail lines or it can have multiple header and multiple line items like below

H 081517693      TEST

D 03500701      TEST2

D 03500713      TEST3

H 081517456      TEST

D 03500701      TEST2

D 03500713      TEST3

D 03500713      TEST3


Since it's simple file, why don't you read this file and create your target structure directly in java mapping instead of creating intermediate structure.

former_member183906
Active Contributor
0 Kudos

Hi,

There will be only 1 header line always.. detail line items can be many..

I need the java mapping for it..

for converting main input to the desired output- java mapping i can use.Do you have any reference link for d same wid programs..

Former Member
0 Kudos

Hi

Try this code. This will give you the desired output


package com.sap;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

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 AddURIPrefix extends AbstractTransformation {

  public void transform(TransformationInput arg0, TransformationOutput arg1)

  throws StreamTransformationException {

  this.execute(arg0.getInputPayload().getInputStream(), arg1

  .getOutputPayload().getOutputStream());

  }// end of transform

  public void execute(InputStream in, OutputStream out)

  throws StreamTransformationException {

  try {

  BufferedReader br = null;

  try {

  // read this file into InputStream

  

  br = new BufferedReader(new InputStreamReader(in));

  int count = 0;

  

  StringBuilder sb = new StringBuilder();

  

  String line;

  while ((line = br.readLine()) != null ) {

  if( count == 0){

  sb.append("H "+line);

  sb.append("\n");

  }

  else{

  sb.append("D "+line);

  sb.append("\n");

  }

  count++;

  }

  

  out.write(sb.toString().getBytes());

  

  } catch (IOException e) {

  e.printStackTrace();

  }

  } catch (Exception e) {

  e.printStackTrace();

  }

  } // end of execute

}