Thursday, August 2, 2012

SAP PI - Dynamic File Name generation



In some cases the requirements of the file being dropped by PI requires to be certain specific formats. For e.g. Date or sequence numbers required. Even though there is a date stamp privided by the File adapter, it is not very flexible in terms of format. Thus the below method is quite helpful. Everything happens in the message mapping.

There is one config required in the File Receiver in the Integration Directory:




The next thing to configure is the message mapping in the ESR, create a UDF in the message mapping as follows:


The reason why I am imported the Seeburger functions are because in this particular case, the file name required a sequence number which increments for each customer. Thus it creates a seeburger variable and gets the next sequence number. Also this UDF should be called once only in the mapping. It should basically have the following code to make the file name be as per what you define:

 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= "OTI_I_18_"+customerGLN + "_" + customerNumber +"_" +".txt";

conf.put(key, filename1);

The above should do the trick for a special date formatted file name.

2 comments:

  1. Hello, excellent post.
    one quick question, how can i use the resulting filename1, as my attachment name on a mail adapter?

    ReplyDelete