on 08-14-2009 10:15 PM
Hi, Guys,
I used file content conversion in receive FCC. My data type is like this:
<TextFromSAP_DT>
<FileName>
<FileName>abc.txt</FileName>
</FileName>
<Record>
<TEXT>dasfafaf</TEXT>
</Record>
<Record>
<TEXT>qqqqqqqq</TEXT>
</Record>
<Record>
<TEXT>fgfffff</TEXT>
</Record>
</TextFromSAP_DT>
I need to get file name from <FileName> and output a flat file with the value in <TEXT>. But I always got an empty line at the file beginning. And I tried to move <FileName> to the end. And I got an empty line at the file end. My custom said they are having trouble to read the file with the empty line no matter it is in the beginning or end.
I followed sample as link below but does not work.
Does any body can give a help?
Thanks a lot!
Meiying
Edited by: Meiying Yang on Aug 14, 2009 11:16 PM
Try to use the dynamic conf. which should easily help u - /people/shabarish.vijayakumar/blog/2009/03/26/dynamic-configuration-vs-variable-substitution--the-ultimate-battle-for-the-file-name
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Shabarish,
Thanks for the response and the link. I followed your blog and changed my target message type like this (deleted FileName field):
<target_mt>
<Record>
<text>dsfafsa</text>
</record>
<Record>
<text>fffffffff</text>
</record>
</target_mt>
Then I mapped <record> and <text> from source to target separately . Then I created an UDF called FName. Imports: FileName. Cache: Value. Argument: a, type: String. And put the following code into the UDF:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create(u201Chttp://sap.com/xi/XI/System/Fileu201D,u201CFileNameu201D);
conf.put(key, a);
And then I mapped this Fname to Root Node" target_mt". When I activate this mapping, I got error say "Mapping not sufficiently defined". Please give further advice. Thanks.
Meiying
Then I created an UDF called FName. Imports: FileName
Your UDF should not import FileName.....it should import JAVA packages.
Have the below JAVA package names in the import section:
com.sap.aii.mapping.api.*; com.sap.aii.mapping.lookup.*; java.io.*; java.lang.reflect.*; java.util.*
Regards,
Abhishek.
Yang,
Create a value UDF and name it as GetFileName and take one input argument a.
Imports: java.*;
Add this code:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create(u201Chttp://sap.com/xi/XI/System/Fileu201D,u201CFileNameu201D);
conf.put(key, a);
return "";
Then you pass the input field to the udf, which will store the file name in the dynamic configuration field FileName.
Regards,
---Satish
Hi, Satish,
Let me clarify all the value of UDF.
Label: GetFileName
Cache: Value
Argument: Name: a, Java Type: String
Imports: java.*;
Codes:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create(u201Chttp://sap.com/xi/XI/System/Fileu201D,u201CFileNameu201D);
conf.put(key, a);
return "";
Does the above correct? If so, where do you see a get the value of field FileName from source? Thanks.
Meiying
Yang,
You will not get any value in Filename. You will get only with the variable 'a' which you get your input value. Then you are putting the value 'a' into key with the code conf.put(key, a) and this key is what is assigned to your FileName. For the file adapter there are few inbuilt dynamic configuration keys which is your FileName one of them. So dont worry about it. Please do it and run it and test.
Regards,
---Satish
Hi, Satish,
Thank you for sticking me on. Here are my source and target mt structure
source_mt
FileName, Type: string, Occurence: 1
Record, Type: blank, Occurence: 1...unbounded
TEXT, Type:string, Occurence: 1
XML will be like this
<source_mt>
<FileName>abc.txt </FileName>
<Record>
<TEXT>aaaaaaaaaaaa</TEXT>
</Record>
<Record>
<TEXT>bbbbbbbbbbbb</TEXT>
</Record>
</source_mt>
target_mt
Record, Type: blank, Occurence: 1...unbounded
TEXT, Type:string, Occurence: 1
XML:
<target_mt>
<Record>
<TEXT> aaaaaaaaaaa</TEXT>
</Record>
<Record>
<TEXT> bbbbbbbbbbb</TEXT>
</Record>
</target_mt>
I would like to output the value of fields "TEXT" to a flat file with the file name as the value of field "FileName" (here is abc.txt).
Thanks.
Meiying
Edited by: Meiying Yang on Aug 17, 2009 6:42 PM
Hi Meiying;
I see your structures, and the map is only in Record nodes (include TEXT node) and i suppose you use the user defined function that Satish wrote u, and so the mapping could be like
<fileName Node> -
> <UDF>------><target_DT>
To know if is everything is ok, you can put message mapping --> check....i hope this have the message "No errors identified during check"......because i construct your structures and it is ok for me....
After that in your receiver communication dont forget to go on the "Advance Tab"
and check
- Use Adapter-Specific Message Attributes &
- File Name
That's all that u need....let us know if it works...
Hi Yang,
You create the value udf GetFileName with one input value say a. Add this code:
Imports: java.*;
Add this code:
//write your code here
DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http:" + "/" + "/" + "sap.com/xi/XI/System/File", "FileName");
conf.put(key, a);
return "";
Map like this:
FileName --> GetFileName(udf) --> target_mt
Map other fields like:
Record --> Record
TEXT ---> TEXT
Save it and activate it. When you test in mapping you will get an error so dont worry. I go the error like:
RuntimeException in Message-Mapping transformation: Runtime exception during processing target field mapping /ns0:Target_MT. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._TestFileName_ method file1$[abc.txt, com.sap.aii.mappingtool.tf3.rt.Context@32dcebf1]
Dont worry about this activate and do the rest of the configuration.
In your receiver communication channel for file name put as FileName and check the file name in adapter specific message attributes. Then test it and it should work and you will get the file with file name abc.txt. I tested the whole end to end scenario and I am getting the file name abc.txt and the output what you want. If you still could not get it send me a m ail to my i d from my business card. I will send you the screen shots.
Regards,
---Satish
Hi,
>>>>I need to get file name from <FileName> and output a flat file with the value in <TEXT>. But I always got an empty line at the file beginning.
remove the filename from the XML data type
and set it in the mapping only (ASMA)
there is no need to keep it in XML
Regards,
Michal Krawczyk
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.