on 12-30-2014 12:26 PM
My requirement to pick the text file in that comments field comes to multiple lines. What is the way to use the FCC parameters for this requirement.
Text file looks
New Material Comments
| 093846 Line1: Welcome
Line2:SAP PI
Line3:Netweaver
| 093847 Line1: Hello
| 093848 Line1: Hai
Line3, Line 2 is blank
Line4
Line5
| 093849 eeeee
e
e
eee
ee
| 093850 Hi
Reulst comes to Comments should be line wise
Line1: Welcome
Line2: SAP PI
Line3:Netweaver
Thanks
Ashok
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ashok,
1) Please follow steps in ESR and ID, mentioned in this wiki.
2) Use below java mapping. If needed, tweak section b and c.
package javaapplication1;
import java.io.OutputStream;
import java.io.InputStream;
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 JavaApplication1 extends AbstractTransformation {
@Override
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException {
try {
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
// a) Copy Input file content to a String
byte[] b = new byte[inputstream.available()];
inputstream.read(b);
String inputContant = new String(b);
// b) Remove first line. // Tweak to match first line.
inputContant = inputContant.replace("New MaterialNumber Comment\n", "");
// c) Remove all |, space, word, space.
inputContant = inputContant.replaceAll("\\|\\s+\\w+\\s+", "");
// d) Write to output steam.
outputstream.write(inputContant.getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
Ashok,
This requirement can also be achieved using FCC as mentioned by Former Member (above).
File (FCC) -> PI (Graphical mapping) -> RFC (XML).
1) In sender file channel use FCC. FCC will convert flat file into XML (each line as a element), ignore first line of file in FCC.
2) In message mapping develop UDF with logic used in Java mapping (replaceAll("^\\|\\s+\\w+\\s+", "")).
Hi Raghu,
We change the requirement as a starting delimiter to ending delimiter in a record creating single text file, and we write a UDF to pick the material number and remaining as internal comments.
UDF Material:
==========
String material = "";
for (int i=0;i<var1.length;i++)
{
if (var1[i].startsWith("|")) {
result.addValue(var1[i].substring(2,10));
material = var1[0].substring(2,10);
}
else {
result.addValue(material);
}
}
UDF Internal Comments:
==================
for (int i=0; i<var1.length;i++)
{
if (var1[i].startsWith("|")) {
result.addValue(var1[i].substring(11,var1[i].length()));
}
else
{
result.addValue(var1[i]);
}
}
Thanks
Ashok
Sender Text file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Read each line into one field and during the mapping write a UDF to get the substring based on your requirement.(indexOf("Line")) something similar.
Refer to Greg's suggestion in the below thread to read each line into a string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ashok,
I think the logic is a bit complicated to do it with FCC. In my opinion you can pick the entire file and to deal with the problem at mapping level. Also you can try with a shell batch OS file to execute before, but i think the logic can be difficult as well, Check this thread http://scn.sap.com/thread/1083737
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.