cancel
Showing results for 
Search instead for 
Did you mean: 

Java mapping for Dynamic File name: stuctures?

Former Member
0 Kudos

Hi,

Scenario: Sender AS2 adapter --> PI --> Receiver File (NFS) Adapter. Just a file pass through, no mapping

Requirement: Want to have the receiver file name as C1.yymmdd.C2 where C1 and C2 are contants and yymmdd is current date.

I was told in sdn forum that I have to write java mapping and provided the sample code also. However, I am not sure how and where to use that sample code. Could you please help on following questions:

1) What is the source and target data type structures for mapping?

2) Where do I develop java mapping? How do I import to PI?

3) How do I get access to SAP Netweaver Developer Studio? Can I download it to my laptop? or if I dont have access, can I use any other tool to develop? ( NetBeans, Eclipse ??) and how?

4) what are the files and libraries that we need to import to java mapping? (e.g., Import aii_map_api.jar library)

5) How to generate .jar file?

If someone has already developed java mapping (.jar file) ready to import into PI, please provide the same.

Thanks in advance

- Riya Patil

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi again,

You can also achieve your file name by using variable substitution. Since you are not using the source file name as receiver therefore you can skip creating the UDF..

Just use currentDate funciton and mapit it some target fileld and as mentioned in this wiki just do exacely same

http://wiki.sdn.sap.com/wiki/display/XI/XIDateStampinFile+Name

In File Nmae Schema you just need to mention C1.%date%.C2, where date is the target filed name taken from your mapping.

Regards,

Sarvesh

Former Member
0 Kudos

Hi Sarvesh,

I tried to replace the code return SourceFileName; with conf.put(key, SourceFileName); it didn't work, UDF is throwing an exception.

Thanks for the link to wiki, however it didn't work for my requirement. We are picking up flat file (its is a pass through scenario, actually we receive file using sender AS2 adapter), not reading the data.

There is should be a way, but I am not sure. Irrespective of sender, just pass through scenatio (pick up the file, no reading), but on the receiver side we want specific file name with current date.

I think ASMP works only if you want same filename from a sender to a receiver file adapter. But in our requirement we have different sender file name and specific receiver file name.

Anyone please help on this. Thanks in advance.

- Riya Patil

Former Member
0 Kudos

Is so difficult to acheive in SAP PI? I hope I made the requirement clear.

Requirement: Irrespective of sender adapter in a file pass through scenatio where we wont read the file (payload just contains the flat file), I want to delivery the same file with the naming convention C1.yyMMdd.C2 where C1, C2 are constants and yyMMdd is cuurent date. So sum up, need to have current date in a file name on receiver side with out reading the payload.

Variable substituation works on if we are are receiving the variable value from the payload.

Looks like ASMP works only same filename from a sender to a receiver file adapter, because if you are not using sender adapter or using sender adapter without selecting ASMP - File Name, there no way you can receive DynamicConfiguration under SOAP Header.

What is the best possible solution?

- Riya Patil

Former Member
0 Kudos

Under the processing tab you have an option to run an OS command. I would suggest you to place the file in a constant name and just rename it by running the OS command. It's the simplest solution to your problem

Former Member
0 Kudos

> Is so difficult to acheive in SAP PI? I hope I made the requirement clear.

The UDF should work. At the end of code just add

return "";

Former Member
0 Kudos

Hi Sarvesh,

This is what I have in my UDF, it still doesn't work:

( The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._MM_Filename_ method DynamicConfiguration$[091221, com.sap.aii.mappingtool.tf3.rt.Context@7ae05e33 )

-


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

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

String SourceFileName = "C1." + a + ".C2";

conf.put(key, SourceFileName);

return "";

-


Well, even though if UDF works on its won, I am not sure how in combination of sender AS2, ASMP it would work.

Because when I de-select ASMP in sender file adapter, I was getting the following error:

The Adapter Message Property 'FileName' was configured as mandatory element, but there is no 'DynamicConfiguration' element in the XI Message header

So looks likes receiver file ASMP works only with/if you select ASMP for sender file adapter.

Correct me if I am worng.

- Riya Patil

Former Member
0 Kudos

You are correct. You have to select the ASMA setting in both places.

You can see in the payload under SOAP Header, when you set the ASMA setting then you get a new parameter called "DynamicConfiguration".

Second thing is the DynamicConfiguration works only at run time, so if you try to test in message mapping under test tab then you will get an error.

Former Member
0 Kudos

Hi Sarvesh,

Then we should not use ASMP in our case right? How and where to use the UDF then? How do we pass the value from UDF to file name schema of receiver file adapter?

- Riya Patil

Former Member
0 Kudos

> Then we should not use ASMP in our case right? How and where to use the UDF then? How do we pass the value from UDF to file name schema of receiver file adapter?

Have my message misguided you? hmmmm... Any way I will sum up all the points once again..

1. Use ASMA setting in BOTH Sender & Receiver adapter.

2. Create message mapping (1:1)

3. Create the UDF. Map the output of this UDF to any root node of target so that your mapping should be completed.

4. While configuring your Receiver adapter give any temp name or use %filename% under File Name Schema.

Regards,

Sarvesh

Former Member
0 Kudos

Hi Sarvesh,

Is this UDF work if I dont select ASMP on sender side? (We tested selecting ASMP on both sender & receiver file adapters, it works fine and it works without UDF also).

In my requirement I have to use sender AS2 adpter, please confirm if I can use this UDF without selecting ASMP on sender side.

I have done the following tests:

Test-1) Select ASMP with 'File Name' on both sender and receiver file adapters without any mapping (UDF)

It works great. No UDF or mapping required. It is just pass through of file having the receiver file name same as in sender channel.

Test-2) Select ASMP with 'File Name', only on receiver file adapter without any mapping (UDF)

It is obvious, it doesn't work. I am getting the following error:

Could not process due to error: com.sap.aii.adapter.file.configuration.DynamicConfigurationException: The Adapter Message Property 'FileName' was configured as mandatory element, but there is no 'DynamicConfiguration' element in the XI Message header

Test-3) Select ASMP with 'File Name', only on receiver file adapter with mapping (using DynamicConfiguratio UDF)

We are getting the following error message in SXMB_MONI:

Fatal Error: com.sap.engine.lib.xml.parser.Parser~

<SAP:Stack>com.sap.aii.utilxi.misc.api.BaseRuntimeException thrown during application mapping com/sap/xi/tf/_MM_Filename_: Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:Stack>

Here is the code we have in UDF:

-


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

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

String SourceFileName = "C1." + a + ".C2";

conf.put(key, SourceFileName);

return " ";

-


So looks like UDF is not working and it is failing in mapping. If I could make it work, I think there is good chance that I can see DynamicConfiguration under SOAP Header, which what required for the error we see in out test-2.

Can someone please help me to straighten this UDF and make it work.

Thanks in advance.

- Riya Patil

Former Member
0 Kudos

> Is this UDF work if I dont select ASMP on sender side? (We tested selecting ASMP on both sender & receiver file adapters, it works fine and it works without UDF also).

It will not work if you don't select the ASMA at sender side.

> In my requirement I have to use sender AS2 adpter, please confirm if I can use this UDF without selecting ASMP on sender side.

I haven't used AS2 adapter, so cannot see it's properties. Because base on that the UDF code will change slightly. May be somebody from fourum can help on this, but you have to use ASMA that is for sure.

> Test-1) Select ASMP with 'File Name' on both sender and receiver file adapters without any mapping (UDF)

> It works great. No UDF or mapping required. It is just pass through of file having the receiver file name same as in sender channel.

>

Definetly it will work if you set ASMA in BOTH adapters.

Former Member
0 Kudos

Hi Sarvesh,

Thanks for trying to help so far. Did the UDF work for you? It seems like it is failing in mapping from the below error from SXMB_MONI:

Fatal Error: com.sap.engine.lib.xml.parser.Parser~

<SAP:Stack>com.sap.aii.utilxi.misc.api.BaseRuntimeException thrown during application mapping com/sap/xi/tf/_MM_Filename_: Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:Stack>

Can you please check UDF, if it works for you?

- Riya Patil

Former Member
0 Kudos

I will try this and let you know.

As per the SDN rules you cannot ask same question in two threads, so plz close either one.

Update:

As you asked me " Can you please check UDF, if it works for you? "

So as promised, I check it and it works 100%. )

I used the same code, and generated the same file name. Check your UDF and mapping once again. Secondly UDF will not show any result in mapping under Test Tab, so test it end-to-end only.

Regards,

Sarvesh

Edited by: Sarvesh Singh on Dec 23, 2009 3:40 PM

Former Member
0 Kudos

Sarvesh,

I still have the same issue. How did you generate the same file name using this UDF? Please inform me about the setting/configuration you have done on both sender and receiver adapters, mapping with target field and other details ...anything that would help me to resove this issue.

- Riya Patil

Former Member
0 Kudos

Hi Sarvesh,

Could you please tell me how UDF has worked for you. I am still having issues.

Thanks in advance.

- Riya Patil

Former Member
0 Kudos

Hi Riya,

You are not returning target file name in your UDF.

===========================================================================================

//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");

String ourSourceFileName = "C1." + a + ".C2";

String ourTargetFileName = ourSourceFileName;

conf.put(key, ourTargetFileName);

return ourTargetFileName;

===========================================================================================

Also I have used dynamic configuration in IDOC to File scenario. In Sender IDOC scenario, we dont have sender communication channel and hence we can not set any ASMA parameters. Still scenario works perfctly fine. hence this should work for AS2 as well. However please check and confirm.

Regards,

Gouri

Former Member
0 Kudos

Riya,

It is really very strange if it is not working for you.

First I selected the ASMA settings then under that I selected File Name. This thing I did for both sender and receiver CC.

The udf code is same as I explained above.

When you run the scenario, just check in MONI under SOAP Header if there is a field "Dynamic Configuration". If you click on this you will see the file name and that means if your mapping is correct then you will get the file name in your mapping. So if you still get the error in MONI then definetly you are doing something wrong in your mapping.

Regards,

Sarvesh

Former Member
0 Kudos

Sarvesh,

I am testing sender file adapter without ASMA (bec we have to test this with sender AS2), dummy mapping with UDF and receiver file adapter with ASMA. And in SXMO_MONI, under SOAP header I dont see dynamic configuration.

Can you please check if it works in my scenario? Is it the UDF that I am failing at?

I have very same source n target structures with only one root node and one element node under it.

Data type: DT_Lockbox_Filename --> FIilenameIn

In mapping this is what I have for the both source and target: MT_Lockbox_Filename --> Filename

Please let me know.

Thanks,

Riya

Former Member
0 Kudos

Hi,

Since you are not getting the "Dynamic Configuration" in SOAP Header therefore I will say it will not be possible in case of AS2 adapter. If you simply use the file adapter (just for testing) then the same code will work.

So it's not your mapping problem.

Regards,

Sarvesh

Former Member
0 Kudos

Hi Sarvesh,

I tried dynamic configuration UDF with IDOC to File & XI Adapter to File both scenario where we dont have sender communication channel to set ASMA parameters. But still scenario works perfectly fine.

So for AS2 also it should work. Am I missing something as I have not worked on AS2 much?

-Gouri

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Riya,

Please try this solution

Please close multiple threads for same issue.

Former Member
0 Kudos

Closing the thread.

Former Member
0 Kudos

> Requirement: Want to have the receiver file name as C1.yymmdd.C2 where C1 and C2 are contants and yymmdd is current date.

Set ASMA settings as described in this blog.. /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14

Now create an UDF with one argument let's say 'a'. Use Current Date functions and set the desired date format e.g. yyMMdd by double clikcing the function. now map this date to UDF.

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

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

String SourceFileName = "C1." + a + ".C2";

return  SourceFileName;

CurrentDate->UDF-->Some RootNode.

Try this and let us know..

Regards,

Sarvesh

Former Member
0 Kudos

Hi Sarvesh,

The UDF works by itself in Test tab of message mapping, generates C1.091221.C2 and mapping it to a field called Filename in the target structure.

Followed the weblog and selected Adapter Specific Message Properties for both the sender and receiver file adapters and selected File Name.

I have a source file name as "Source_Filename" in sender adapter and selected * in File Name Schema of receiver file adapter.

I am getting the target file as the same filename from a sender, but thats not want I wanted.

I want to have source file name as "Source_Filename" and tager file name as C1.091221.C2 from the mapping UDF.

Do you know how to I achieve that?

Thank you for your help

- Riya Patil

Former Member
0 Kudos

Just replace the code return SourceFileName; with conf.put(key, SourceFileName);

and then try again.

Regards,

Sarvesh

rajasekhar_reddy14
Active Contributor
0 Kudos

> 1) What is the source and target data type structures for mapping?

No need of Java Mapping , you can achieve this using Dynamic Configuration UDF.But you need to develop dummy mapping for the same,without mapping its not possible to map UDF.

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

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

SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMdd");

String timestamp = dateformat.format(new Date());

String filename1="C1." + timestamp + "C2.";

conf.put(key, filename1);

return "";

Regards,

Raj

Former Member
0 Kudos

Hi Raj,

I have copied the same code you have given into UDF and it is throwing errors.

Source code has syntax error: /usr/sap/X6D/**/j2ee/cluster/server0/./temp/classpath_resolver/Mapa0069b10ee5211de888800144f443c9c/source/com/sap/xi/tf/_MM_Lockbox_Filename_.java:51: cannot resolve symbol symbol : class SimpleDateFormat location: class com.sap.xi.tf._MM_Filename_ SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMdd"); ^ /usr/sap/X6D/**/j2ee/cluster/server0/./temp/classpath_resolver/Mapa0069b10ee5211de888800144f443c9c/source/com/sap/xi/tf/_MM_Lockbox_Filename_.java:51: cannot resolve symbol symbol : class SimpleDateFormat location: class com.sap.xi.tf._MM_Filename_ SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMMdd"); ^ 2 errors

Can you please help to resove the issue? We want only time in yymmss format, no time yet all.

I have selected Cache as Value with Argument a.

Thanks in advance

- Riya Patil