Skip to Content
avatar image
Former Member

Date and time stamp for the file

Hi Experts,

My Requirement is to create a csv file with the name testfile_date&timestamp.

If i select add time stamp in the receiver file communication channel the file be as testfile_yyyymmdd_hhmmss_XXX.

The XXX is message id which comes by default by selecting add timestamp option.

but, i don't want the message id displayed in the file name.As i know from the blogs we can reach this requirement as per Michels blog

/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14

I am not clear in the mapping. after writing the udf, to which filed i need to map with that udf.

can you please tell me stel by step how how to do mapping and how to achieve the requirement. request you to send the code forthe udf.

Thanks

Rahul

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 29, 2010 at 04:50 PM

    Hi

    Map the UDf to the root of the message.

    public String getFileName(Container container) throws StreamTransformationException{

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

    //For getting filename

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

    // Retrieve the filename

    String FileName = conf.get(key);

    return FileName;}

    The above code works only if you have set the ASMA parameters.

    Choose file and directory in the sender and again choose file and directory in receiver as shown in the blog.

    Addtionally choose timestamp in the reciever adapter. Possibly this message id cannot be removed.

    Regards

    Monika

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks Gouri, Rithu, Harin and Mounica...

      i followed as you people advised. now i am getting the correct file name. Thanks a lot

      Rahul.

  • avatar image
    Former Member
    Nov 29, 2010 at 12:04 PM

    Hi,

    Use below code for UDF. here field "a" is your input to UDF. in your case its a constant value. So take constant "testfile_" and concatenate this with required date and time stamp values. Out put of this concatenation pass to UDF.

    UDF output should be given to first Node from target message type in mapping as this will make sure your UDF is getting executed.

    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    
    String ourSourceFileName = a;
    
    String ourTargetFileName = ourSourceFileName;
    conf.put(key, ourTargetFileName);
    return ourTargetFileName;  
    

    Make sure File parameter is checked in ASMA of channels.

    -Gouri

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 29, 2010 at 12:12 PM

    Hi,

    you can wirte udf and map it to root element of the target message type. u just need to execute the udf.

    UDF:

    // UDF havs one input parameter - timestamp

    Code:

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

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

    String OldFileName = conf.get(key);

    String newFileName = "";

    if (OldFileName != null) {

    newFileName = "testfile_" +timestamp ;

    conf.put(key, newFileName);

    }

    return newFileName;

    Mapping:

    Date (standard function) [Formmat yyyyMMdd_hhmmss] -> UDF -> MesageType.

    Thanks.

    Ritu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 29, 2010 at 12:16 PM

    Hi Rahul,

    If you select the "Add timestamp" then the filename would be changed as testfile_yyyymmdd_hhmmss. It would not add the Message ID.

    If you have written any UDF for the file name, then map that UDF to the rootnode of the target Message type.

    public String myFileName(String a,Container container)
    {   
    //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 myFileName = "Test" + timestamp;
    conf.put(key, myFileName);
    return "";
    }
    

    Thanks,

    Add comment
    10|10000 characters needed characters exceeded