cancel
Showing results for 
Search instead for 
Did you mean: 

Append and Time stamp

Former Member
0 Kudos

Hi Experts,

I have 2 requirements.

My scenario is Idoc to file.

1) My requirement is, I need file name at receiver side as file name+time stamp.

2) I need to append the file.

But in PI it is allowing only either to Use add time stamp or append file in file construction mode.

Can any one please let me know how can i achive both.

Regards

Swetha

Accepted Solutions (1)

Accepted Solutions (1)

gagandeep_batra
Active Contributor
0 Kudos

Hi swetha

you can handle this by using first append.

and then us OS command to rename with time stemp.

Regards

Gagandeep

Former Member
0 Kudos

Hi Batra,

Can you please explain the procedure bit breifly.

Regards

Swetha

gagandeep_batra
Active Contributor
0 Kudos

Hi Swetha,

following may help you

in command line after processing use following command

cmd.exe /C "ren %F %F_%date%_%time%.csv

Regards

Gagandeep Batra

Former Member
0 Kudos

Batra

I am sorry it did not work.

Regards

gagandeep_batra
Active Contributor
0 Kudos

are u using NFS or FTP.

command is work for NFS only.

and try for other rename command, there might be syntax problem google it for that  and what is your system widows or Unix,

if unix then use unix scripts.

Former Member
0 Kudos

Hi Batra,

I am using FTP and windows OS. Please let me know the command for FTP.

Regards

former_member190624
Active Contributor
0 Kudos

Hi swetha,

Try the following UDF,

public String Dynamic(String FileName, String Date, Container container) throws StreamTransformationException{

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

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

String myFileName = "" ;

myFileName = FileName + "_" + Date + ".csv";

conf.put(key, myFileName);

return myFileName;

}

1st parameter for this UDF is constant(i.e, ur desired file name).

2nd parameter is Date (use current date function and specify date and time format )

Don't forget to map udf to any node , then only ur dynamic configuration will work. Have alook at attached files.

Please let me know the result.

Regards

Hari.

Former Member
0 Kudos

Hi Hari,

It is throwing error

Just for your reference so that u can cross check......................While creating UDF i had given first argument as FileName and second argument as Date

and execution type Single Values

And in the constant i had given my file name which is

AndwATTInv_.csv

It is throwing below error

Check result for Message Mapping: MM_ATT_Invoice_Out | http://com.commscope.com/ATTCSVEDI/Invoice:

Starting compilation

Source text of object Message Mapping: MM_ATT_Invoice_Out | http://com.commscope.com/ATTCSVEDI/Invoice has syntax errors:

Function Dynamic, Line 1:

not a statement StreamTransformationException{ ^

Function Dynamic, Line 1:

';' expected StreamTransformationException{                              ^ 2 errors

Former Member
0 Kudos

Hi Hari Thanks a lot.

It worked

Answers (2)

Answers (2)

Former Member
0 Kudos

mightbe below approach is helpful for ur requirement :

on message mepping :

you can use timestamp and dynamic configuration udf's for  dynamically call filename on mapping :

filename_ + time stamp udf + concat + contatnt(.csv) +concat+  dynamic conf udf -> target node

udf:

time stamp:

public String AddTimestamp(String var1, Container container) throws StreamTransformationException{  
String DATE_FORMAT_NOW = "yyyyMMdd-HHmmss";  

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

dynamic conf:

public String DynamicConfig(String a, Container container) throws StreamTransformationException{

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 "";

in Communication channel :

you have to enable flag UseAsma properties and file name .

and you can use Append From File Construction mode .

Thanks,

Message was edited by: S Sankar

Former Member
0 Kudos

Hi Sankar,

i did not get the below logic, can you explain it breifly

filename_ + time stamp udf + concat + contatnt(.csv) +concat+  dynamic conf udf -> target node

Regards

Former Member
0 Kudos

please follw below printscreen:

addTimeStamp:

public String addTimeStamp(Container container) throws StreamTransformationException{

  
String DATE_FORMAT_NOW = "yyyyMMdd-HHmmss";

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

and add pkg in as below printscreen:

dynamicConf udf:

public String dynamicConf(String a, Container container) throws StreamTransformationException{

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 "";

thats all....

On Communication channel:

and for dynamic generate file name:

Former Member
0 Kudos

Hi Sankar,

Thanks a lot for your help.

but as per the above discussion i want may file with just Date.

I mean i want file like shown below

File_YYYYMMDD.csv

If you dont mind can you please send the procedure for it and save my day.

Former Member
0 Kudos

hi Swetha,

Every thing is same , just change date format in addTimeStamp Udf only.

just u have to wtite in

String DATE_FORMAT_NOW = "yyyyMMdd";

insted of

String DATE_FORMAT_NOW = "yyyyMMdd-HHmmss";

zameerf
Contributor
0 Kudos

>>

1) My requirement is, I need file name at receiver side as file name+time stamp.

Normally we add timestamp to file name to distinguish each files in the directory.

Do you mean to have only the date along with file name?

If so, you can use dynamic configuration in mapping and then use append option in receiver file channel.

Former Member
0 Kudos

Hi Zameer,

Thanks for your help,

My requirement is like i want file like shown below.

File_YYYYMMDD-HHMMSS.csv

I mean i need both date and time.

Former Member
0 Kudos

Hi,

if both date and time (along with Seconds is used) then everytime a new file will get created and append will not happen as append time with seconds will be a unique value...

so you need to use hours and minutes if only a single to be generated per hour else as said above maintain one file per day .else you can have the data appended to the file..

HTH

Rajesh

Former Member
0 Kudos

Hi Rajesh,

Thanks for your valuble suggestion,

Can you please tell me how to add the date then.

I mean how do i get file like this

File_YYYYMMDD.csv

Former Member
0 Kudos

Hi Zameer,

Can you please tell me how to use dynamic configuration in mapping.

I am really new to PI with no Java knowledge.

Regards

Swetha

zameerf
Contributor
0 Kudos

You can refer below blog to know the steps to achieve your file name like File_YYYYMMDD.csv using Dynamic Configuration in mapping.

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