cancel
Showing results for 
Search instead for 
Did you mean: 

Add date to the file at receiver side.

former_member190358
Participant
0 Kudos

Hello Everyone,

I have a requirement to add date to the receiver file adapter file.

Its a file to file scenario.

I know we have two options . one is custom module or a script.

Can someone help me with the script to be coded .

Regards,
Ravi

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

You might want to try adding Add Timestamp  parameter under construction mode. Remember, this provides date followed by time. You might want to give only date format and ignoring the time part and see if that helps. Otherwise after the files are created, You run the script that append dates as the end.

Unix command

cp filename filename`date +%Y%m%d`

former_member190358
Participant
0 Kudos

Hello Baskar,

I am not much aware of Unix script. Could you please let me know the entire code that needs to be wriiten for changing the file name from  " XYZ "  to "  XYZ_20130423.txt " .

Regards,

Ravi

Former Member
0 Kudos

HI Ravi,

is that scenari with ESR / without ESR ?

if scenario having with ESR then you follow below logic :

thanks,

former_member190358
Participant
0 Kudos

Hello Baskar,

My question is till open as i tried to write a script and it did not work ..

Can you please check the below script and see what is going wrong.

logDir=/interface/scripts

logFile=dateMATMASTFiles.log

echo "Entered script" >> $logDir/$logFile

USER=xxxxxx

PASSWD=xxxxxxx

HOST="xxx.xxx.xxx.xx"

ftp -n $HOST <<END_OF_FTP >> /interface/scripts/ftp_connection.log

user $USER $PASSWD

cd /interface/tes

binary

prompt off

cp filename filename`date +%Y%m%d

quit

END_OF_FTP

echo "Leaving script" >> $logDir/$logFile

Answers (5)

Answers (5)

roger_alluivall
Participant
0 Kudos

Hello,

Check my blog>

I hope it helps.

Regards!

Former Member
0 Kudos

yes 

: (import pkg "java.text.SimpleDateFormat" under importInstructions)

 
String DATE_FORMAT_NOW = "yyyyMMddHHmmssSSS"; // here u have to give specific format

   Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
    return sdf.format(cal.getTime());

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

conf.put(key,a);

return "";

Former Member
0 Kudos

Hi,

use the below code.

DynamicConfiguration conf = (DynamicConfiguration) container 

    .getTransformationParameters()

    .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");

//get current date

Date date = new Date( );

var_Filename = conf.get(key) + dateFormat.format(date);

conf.put(key, var_Filename);

Thanks,

Satish.

former_member201264
Active Contributor
0 Kudos

Hi Ravi,

I agree all above replies, if they siut your requirement as per your business.

My descriptions:

1.If you have AttribMapper in your PI (Generally comes from Seeburger AS2 Adapter),

   then you can use that as below:

2. you are using Mapping for your scenario, then you write UDF same as above UDF (from Sugata) and use DATE functions as per your requirement to get file name and pass the same to UDF and use it to create file name.

Among all these replies now you can choose whichever is easy.

Regards,

Sreeni.

Former Member
0 Kudos

Hi Ravi,

You can simply write a UDF and use ASMA properties to add date. Instead of going for script this would be the better option.

sugata_bagchi2
Active Contributor
0 Kudos

You can use dynamic configuration in mapping along with ASMA in rcv file adapter..

Using UDF and Java date time class you can add your custom date time to the file.

e,g-

try { 

String filename = ""; 

String timestamp = "";

DynamicConfiguration conf1 = (DynamicConfiguration) container 

.getTransformationParameters() 

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); 

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

DynamicConfigurationKey key2 = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","SourceFileTimestamp");

filename = conf1.get(key1); 

timestamp = conf1.get(key2);

filename = filename.replaceAll( ".txt" ,"_" ); 

filename = filename+timestamp+".xml";

conf1.put(key1,filename); 

return filename; 

}

catch(Exception e) 

String exception = e.toString(); 

return exception; 

}

you can change the timestamp value as per your own.