Skip to Content

Dynamic filename SFTP receiver

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 02, 2016 at 03:14 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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