cancel
Showing results for 
Search instead for 
Did you mean: 

Removing the empty line during Receiver FCC!

Former Member
0 Kudos

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.

https://wiki.sdn.sap.com/wiki/display/profile/2007/07/30/Removing%20the%20empty%20line%20during%20Re...!

Does any body can give a help?

Thanks a lot!

Meiying

Edited by: Meiying Yang on Aug 14, 2009 11:16 PM

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

former_member200962
Active Contributor
0 Kudos

Your UDF should contain one more statement --->

return "";

the above return statement should be included at the end of your UDF logic.....check and confirm...before activating save the mapping and press F7 to check if there is any error in the mapping

Regards,

Abhishek.

Former Member
0 Kudos

Hi, Abhishek,

Thanks for the reply. I added return " "; to the end of UDF codes and still got same error.

Meiying

former_member200962
Active Contributor
0 Kudos
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.

Former Member
0 Kudos

Then, how I can get the import parameter "FileName" from source? Look at Shabaris' s blog: imports: a - Field PONumber.

Meiying

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi, Satish,

Then how the argument a get the value from the field FileName in source massage? Thanks.

Meiying

Former Member
0 Kudos

Yang,

Here you are passing <FileName>abc.txt</FileName> as your input which is variable 'a' to your input. So at the end your FileName would be abc.txt.

Regards,

---Satish

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Ok. I have saved it and still map it to root node "target_mt". But I still get the same error "Mapping not sufficiently defined" and won't let me activate it. And I still don't understand how the value "abc.txt" pass to argument "a".

Meiying

Former Member
0 Kudos

Yang,

I think we both are missing somethign here. Mapping not sufficiently means some mandatory fields might not be populated. Can you please your target structure and source structure here, so that somebody can help you out?

Regards,

---Satish

Former Member
0 Kudos

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

Former Member
0 Kudos

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...

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks Satish. It works very well.

Meiying

Answers (1)

Answers (1)

MichalKrawczyk
Active Contributor
0 Kudos

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