cancel
Showing results for 
Search instead for 
Did you mean: 

How to add timestamp in receiver channel in the below format?

Former Member
0 Kudos

Hi All,

I have a ECC to FTP pass through scenario i.e. no ESR objects.

ECC will send FILE.DAT. After adding timestamp it should look like FILE_DDMMYYYY.DAT. Using Add Time Stamp it will add time stamp but not in the desired format.

How to achieve this?

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

The best option for pass through scenario is to create dummy ESR objects and use UDF to name the file name dynamically, as sunil mentioned.

With this option you are creating only one valid ESR object, other objects shall be dummy ones.

Thanks,

Pranav

former_member184789
Active Contributor
0 Kudos

Hi,

If you wish to go for a Java mapping, then below code may be useful:

package com.sap.pi.java.mapping;

import java.io.InputStream;

import java.io.OutputStream;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Map;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.DynamicConfiguration;

import com.sap.aii.mapping.api.DynamicConfigurationKey;

import com.sap.aii.mapping.api.StreamTransformationConstants;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class DynamicFileName extends AbstractTransformation{

     public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException

     {

         String oldFilename = "";

         String newFilename = "";

      try

      {

           InputStream inputstream = transformationInput.getInputPayload().getInputStream();

           OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

           Map mapParameters = (Map) transformationInput.getInputHeader().getAll();

           mapParameters.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/Dynamic",StreamTransformationConstants.DYNAMIC_CONFIGURATION), "");

           DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

           Date obj1 = new Date();

           SimpleDateFormat formatter = new SimpleDateFormat ("DDMMYYYY");

                   String dateStr = formatter.format(obj1);

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

           oldFilename = conf.get(key);   

           oldFilename = oldFilename+"_"+dateStr;

           conf.put(key, newFilename);

           byte[] b = new byte[inputstream.available()];

           inputstream.read(b);

           outputstream.write(b);

      }

      catch (Exception exception)

      {

       getTrace().addDebugMessage(exception.getMessage());

       throw new StreamTransformationException(exception.toString());

      }

}

}

Also go through:

http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=272171407

http://wiki.sdn.sap.com/wiki/display/Snippets/Dynamic+file+name+in+a+File+to+File+pass+through+scena...

smavachee
Active Contributor
0 Kudos

Overall you have three possibilities..

> Create dummy ESR objects and use UDF for Dynamic Configuration

> Develope Adapter Module with your specific requirement

> RUN OS Command

As you are using FTP at receiver end, use of OS Command will be easiest way to achieve your scenario.

Assosiated threads already provided in above replies.

Hope it helps.!

Regards,

Sunil

former_member556603
Active Contributor
0 Kudos

Hi Shaibayan,

Yes, You can achieve by using Dynamic configuration UDF and well  Adapter specific message attributes. Also please find the below step by step documents:

http://scn.sap.com/thread/1389680

http://saptechnical.com/Tips/XI/ASMA/Index.htm

" saptechnical "

Thanks,

Maruthi

Former Member
0 Kudos

Hi Shaibayan,

They is a Similar  thread like this, you can check here,

https://scn.sap.com/thread/192751

Thanks,

Seshu.

gagandeep_batra
Active Contributor
0 Kudos

Hi Shaibayan,

AS you don't using ESR object so it is difficult to require file name with time stamp with dynamic configuration.

but you can go for RUN OS command and use the rename command after message processing and try to achieve this using OS command.

if you want to go for dynamic configuration then check blow blog that may help you.

http://scn.sap.com/community/pi-and-soa-middleware/blog/2009/03/26/dynamic-configuration-vs-variable...

Regards

Gagan

Former Member
0 Kudos

Hi Gagan,

As there is no ESR objects so I think Dynamic Configuration is out of question.

Moreover renaming a file using OS Command is a possibility but can I get the Timestamp in the format DDMMYYYY?

I can use mv FILE.DAT FILE_TIMESTAMP.DAT but how to change the TIMESTAMP value?

Former Member
0 Kudos

Hi Shaibayan,

You can achieve this in 2 ways.

1)Custom Module

2)OS command/batch/shell script executing from PI Receiver file channel.

1)I personally prefer this .With few lines of code you can achieve your requirement with good error handling.

2)OS dependent.Need to be bit cautious .Go through below link for better clarity .

http://scn.sap.com/thread/1987070

Regards

Venkat

Former Member
0 Kudos

This message was moderated.