cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic filename SFTP receiver

former_member269988
Participant
0 Kudos

Hi Dear,

I create XML file in SFTP from SAP PI, but i need set the name : XXX_DATETIME.XML

The format of date is YYYYMMDD and time HHMMSS.

Several ways but nothing worked and I can only write a file that is named 'newfile' and is always overwritten, even with the flag not being marked. (UDF, mapping....)

Communication channel receiver using SAP PI 7.30.

Accepted Solutions (0)

Answers (1)

Answers (1)

Andrzej_Filusz
Contributor
0 Kudos

Hi,

You have checked "Use Adapter Specific Message Attributes" option. But have you ever put any values there in your UDF or java mapping?

Here is an example from my UDF:

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters() .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);  
DynamicConfigurationKey fileNameKey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System","FileName"); 
if (conf != null) { 
   conf.put(fileNameKey, fileName); 
} else 
   throw new StreamTransformationException("your exception message!"); 
return " ";

Make sure you have used the same namespaces in your CC and java code.

Other option is to use "Add timestamp to filename" option (uncheck ASMA option in that case). But you have to decide which method you want to use.

Best regards,

Andrzej

former_member269988
Participant
0 Kudos

Hi Andrzej,

thanks for your response.

I try insert my UDF in function of my mapping, it's correct right?

Andrzej_Filusz
Contributor

Hi,

Yes, you can implement the logic of creating file names in your UDF in your mapping. Don't forget to invoke that UDF in your mapping (attach it to the root tag of your target message, for example).

Andrzej

former_member269988
Participant
0 Kudos

Andrzej,

Can you send a print of your UDF in MM ?

Do you using a module to convert in communication module?

Andrzej_Filusz
Contributor
0 Kudos

1. Create an UDF with 1 parameter.

2. Write your code that creates file name in the format you need, for example:

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;

String datePattern = "yyyyMMddHHmmss";
TimeZone timeZone = TimeZone.getTimeZone("Europe/Warsaw");
Locale locale = new Locale("pl", "PL");
SimpleDateFormat dateFormatter = new SimpleDateFormat(datePattern, locale);
Calendar calDate = Calendar.getInstance(timeZone, locale);	
String fileName = dateFormatter.format(calDate.getTime());
// copy & paste here the code I wrote above 🙂

Make sure you changed a timezone and locale to yours.

3. Click on the root tag of your target message and map it using your UDF.

If I have to convert the content of my message, then yes, I use a module.

BTW, the standard timestamp has the following format: yyyyMMdd-HHmmss-SSS. Are you sure that you can't use it? If it doesn't meet your requirements, then use UDF.

Andrzej