cancel
Showing results for 
Search instead for 
Did you mean: 

Get filename and directory name during runtime

Former Member
0 Kudos

Hi guys,

I am developing a file to file interface without content conversion, just a simple file transfer from one ftp server to another. I have to read the same filename (invent.txt) from multiple folders (mstransfer/M01/IN1, mstransfer/M02/IN1, mstransfer/M03/IN1....) that represent different stores and transfer it as it is with the same name to exactly the same directory name in the target ftp location.

My problem is found inside a dummy mapping that I have created in order to specify the target directory and the name of the file. I am doing the following:

A) A Java UDF to specify the filename

trace = container.getTrace();

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

String filename = conf.get(key);

trace.addWarning("filename = "+filename);

conf.put(key, filename);

return "";

//return filename;

B) A Java UDF to specify the directory name

//write your code here

trace = container.getTrace();

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");

String directory = conf.get(key);

trace.addWarning("directory before = "+directory);

directory = "/usr/sap/trans"+directory;

trace.addWarning("directory after = "+directory);

conf.put(key, directory);

return "";

//return "/usr/sap/trans"+directory;

In receiver file adapter I do not specify neither a filename nor a target directory.

When I am testing it, I always get a mapping runtime error.

Any ideas?

--Evaggelos

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

When you test this in the message mapping you will get an error because there is no filename stored in XI yet since there has been no transfer of data?

Former Member
0 Kudos

As you mentioned you are getting error in testing. Is that,

1. end to end testing like let the FTP adapter pick the file up and another FTP adapter deliver the file to Target

OR

2. you are mentioning testing in Message Mapping or Interface Mapping where you just load the test data and hit the execure test button.

If it is Second scenario then you will get that error because there is no DYNAMIC CONFIG while testing from message Mapping or Interface mapping from IR.

To resolve that you can always hardcode some values temporarily for output of DYNAMIC CONFIG.

Thanks.

-Adrean.

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

No need for any UDF in this case. and no need for any mapping.

In both the sender and receiver file adapters , select Adapter Specific Identifiers and File Name and Directory.

In the receiver file adapter give some dummy value for file name and directory.

In the runtime, not the source file name and directory will be used as the target file name and directory.

You need not use any UDF or a mapping here

Regards

Bhavesh

justin_santhanam
Active Contributor
0 Kudos

Eva,

Did u checked(check box) the ASMA option Filename and Directory in both comm.channels

Best regards,

raj.

Former Member
0 Kudos

Yes I did, I can also see these properties filled with values in SOAP header message.

--Evaggelos

bhavesh_kantilal
Active Contributor
0 Kudos

Just had a look at your Directory code and realised that you are adding some prefix to the directory . Guess you will need a mapping in this case.

What is the error that you are getting in runtime? Where / how are you calling this UDF?

The best way to do this, would be to write the code in the Java Section of your message mapping ( either Intialization or Destrcution ) section. You do not need a UDF as such and also can make sure that the directoy value is getting set dynamically.

Refer to this blog for Java Section,

/people/sap.user72/blog/2005/10/01/xi-new-features-in-sp14

Regards

Bhavesh

justin_santhanam
Active Contributor
0 Kudos

Eva,

Why u need two Java UDF's, you can achieve it in single function.

trace = container.getTrace();

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");

String filename = conf.get(key);

trace.addWarning("filename = "+filename);

conf.put(key, filename);

String directory = conf.get(key1);

trace.addWarning("directory before = "+directory);

directory = "/usr/sap/trans"+directory;

trace.addWarning("directory after = "+directory);

conf.put(key1, directory);

return "";

Try this and let us know.

Best regards,

raj.

Former Member
0 Kudos

Guys,

First of all, I am doing an end to end testing, i.e. I let the FTP adapter pick the file up and another FTP adapter delivers the file to target folder. I am definitely not testing the mapping in mapping editor.

I get the error in Request message mapping (pipeline step, which I can see in SXMB_MONI transaction) which is a dummy mapping between two message types that I have created and are based on two data types with two fields each.

The UDF's that I have created go in-between the source and target fileds of the message types/data types.

The error that I see in the trace section of the XML message in SXMB_MONI is the following:

"<Trace level="1" type="T">RuntimeException during appliction Java mapping com/sap/xi/tf/_MM_G_SRS_FileTransfer_MNS_</Trace>

<Trace level="1" type="T">java.lang.NullPointerException at com.sap.aii.mappingtool.tf3.AMappingProgram.exceptionCaught$(AMappingProgram.java:59) at com.sap.aii.mappingtool.tf3.Transformer.checkParserException(Transformer.java:182) at com.sap.aii.mappingtool.tf3.Transformer.start(Transformer.java:149) at com.sap.aii.mappingtool.tf3.AMappingProgram.execute(AMappingProgram.java:102) at com.sap.aii.ibrun.server.mapping.JavaMapping.executeStep(JavaMapping.java:64) at com.sap.aii.ibrun.server.mapping.Mapping.execute(Mapping.java:91) at com.sap.aii.ibrun.server.mapping.MappingHandler.run(MappingHandler.java:90) at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleMappingRequest(MappingRequestHandler.java:95) at"

I have included some trace.addWarning() lines in Java code to help me debug my code, but I cannot see them anywhere inside the trace to be getting executed.

I will try Bhavesh's idea and I will write the code in the Java Section of my message mapping ( either Intialization or Destrcution ) section.

Former Member
0 Kudos

Bhavesh,

In neither Intialization section nor Destruction I have access to the container abstract class that is the default input variable in all UDF's.

--Evaggelos

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

you would just need to tweak the code as follows,

DynamicConfiguration conf=(DynamicConfiguration)getParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

Regards

Bhavesh

Former Member
0 Kudos

I tried it. However, I am still getting the same error in message mapping:

java.lang.NullPointerException at com.sap.aii.mappingtool.tf3.AMappingProgram.exceptionCaught$(AMappingProgram.java:59) at com.sap.aii.mappingtool.tf3.Transformer.checkParserException(Transformer.java:182) at com.sap.aii.mappingtool.tf3.Transformer.start(Transformer.java:149)...

Any ideas?

As I told you I am using a dummy message mapping between the same message types that have two fields, so I am doing field to field mapping and I have added the code that changes the filename and the directory path in the Initialization section of the Java editor.

Is there a way in the intialization section to initialize the trace variable for printing instead of using: trace = container.getTrace() ??

bhavesh_kantilal
Active Contributor
0 Kudos

Test this in the runtime. Do not test the messsage mapping

regards

Bhavesh

Former Member
0 Kudos

I still get the same error when I am testing in runtime.