on 03-05-2013 12:40 PM
Hi,
I need to take the SourceFileTimestamp and pass it in the mail body as text.
I need this date to be in specific format which is - MM/dd/yyyy hh:mm:ss
The date is coming as -YYYYMMDDTHHMMSSZ from ASMA SourceFileTimestamp
where T represents start of time and Z represents end of time.
My code is as below but it is giving error -
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
try{
DynamicConfiguration conf = (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");
String fname= conf.get(key1);
String timestamp= conf.get(key2);
String Str= timestamp;
String date= Str.substring(0, 8);
String year= date.substring(0, 4);
String month= date.substring(4, 2);
String day= date.substring(6, 2);
String time= Str.substring(9, 6);
String hours= time.substring(9, 2);
String mins= time.substring(11, 2);
String secs= time.substring(13, 2);
String date1= month+" / "+day+" / "+year;
String time1= hours+" : "+mins+" : "+secs;
String filename= "EBS File with file name " + fname + " is sucessfully received to SAP @ " +date1+" "+time1;
return "Dear Sir / Madam," +" \n " +" \n "+filename;
}
catch(Exception e)
{
String exception = e.toString();
return exception;
}
Kindly correct this UDF.
Thanks
Neha
Hi Neha,
I have corrected the udf, try this out:
try{
DynamicConfiguration conf = (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");
String fname= conf.get(key1);
String timestamp= conf.get(key2);
String Str= timestamp;
String date= Str.substring(0, 8);
String year= date.substring(0, 4);
String month= date.substring(4, 6);
String day= date.substring(6);
String time= Str.substring(8);
String hours= time.substring(1,3);
String mins= time.substring(3,5);
String secs= time.substring(5,7);
String date1= month+" / "+day+" / "+year;
String time1= hours+" : "+mins+" : "+secs;
String filename= "EBS File with file name " + fname + " is sucessfully received to SAP @ " +date1+" "+time1;
return "Dear Sir / Madam," +" \n " +" \n "+filename;
}
catch(Exception e)
{
String exception = e.toString();
return exception;
}
Regards
Vishnu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Please try this code:
try{
DynamicConfiguration conf = (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");
String fname= conf.get(key1);
String timestamp= conf.get(key2);
String Str= timestamp;
String date= Str.substring(0, 8);
String year= date.substring(0, 4);
String month= date.substring(4, 6);
String day= date.substring(6);
String time= Str.substring(8);
String hours= time.substring(9, 11);
String mins= time.substring(11, 13);
String secs= time.substring(13, 15);
String date1= month+" / "+day+" / "+year;
String time1= hours+" : "+mins+" : "+secs;
String filename= "EBS File with file name " + fname + " is sucessfully received to SAP @ " +date1+" "+time1;
return "Dear Sir / Madam," +" \n " +" \n "+filename;
}
catch(Exception e)
{
String exception = e.toString();
return exception;
}
I just corrected in substring lines only in your code.
Regards
Vishnu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vishnu,
For timestamp too am getting error for below code;
I need time format as YYYYMMDD HH:MM:SS
public String GET_XMLtime(Container container){
DynamicConfiguration conf = (DynamicConfiguration)
container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","SourceFileTimestamp");
String timestamp= conf.get(key);
String Str= timestamp;
String date= Str.substring(0, 8);
String year= date.substring(0, 4);
String month= date.substring(4, 6);
String day= date.substring(6);
String time= Str.substring(8);
String hours= time.substring(9, 11);
String mins= time.substring(11, 13);
String secs= time.substring(13, 15);
String date1= month+" / "+day+" / "+year;
String time1= hours+" : "+mins+" : "+secs;
return timestamp;
Hi Rajesh,
I have corrected the udf, please try this:
DynamicConfiguration conf = (DynamicConfiguration)
container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","SourceFileTimestamp");
String timestamp= conf.get(key);
String Str= timestamp;
String date= Str.substring(0, 8);
String year= date.substring(0, 4);
String month= date.substring(4, 6);
String day= date.substring(6);
String time= Str.substring(8,16);
String hours= time.substring(1,3);
String mins= time.substring(3,5);
String secs= time.substring(5,7);
String date1= year + month + day;
String time1= hours+":"+mins+":"+secs;
timestamp = date1 + " " + time1;
return timestamp;
Hello Rajesh,
Yes.UDF is mandatory.
So you achieved the requirement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raghu,
See if my comments are right. If wrong please correct me.
//Providing xi location package and title GetFilname as string.
Imports com.sap.xi.tf.*;
Public String GetFileName(Container container){
//This interface GetTransformation contains constants and Parameters that can be used in a java mapping to access runtime parameters.
Most of these parameters are attributes of the message header, e.g., sender party, sender service, etc.
DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//In class DynamicConfigurationKey it Creates an instance specifying the namespace of adapter type and name of ASMA attributes.
DynamicConfigurationKey key = DynamciConfigurationKey.create(“http://sap.com/xi/XI/System/File”, “SourceFileName”);
//GetKey returns the value of specified key which is called in previous line.
String filename = conf.get(key);
//The filename is returned.
return filename;
Hi Rajesh,
It should be
//In class DynamicConfigurationKey it Creates an instance specifying the namespace of adapter type and name of ASMA attributes.
DynamicConfigurationKey key = DynamciConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
Your double-quotes are slanted, it might not be accepted by the compiler. Aside from that, the code looks correct.
Regards,
Mark
Yes the comments for each line of codings. Since I'm new to Java mapping or UDF'S.
//Providing xi location package and title GetFilname as label string.
Imports com.sap.xi.tf.*;
Public String GetFileName(Container container){
//This interface GetTransformationConstants contains constants that can be used in a java mapping to access runtime parameters.
Most of these parameters are attributes of the message header, e.g., sender party, sender service, etc.
GetTransformationParameters returns a map with the mapping runtime constants. For a description of which constants you can access by using this map.
The constants are attributes of the class StreamTransformationConstants. Ideally to get the value already stored in parameter.
DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//In class DynamicConfigurationKey it Creates an instance specifying the namespace of adapter type and name of ASMA attributes.
DynamicConfigurationKey key = DynamciConfigurationKey.create(“http://sap.com/xi/XI/System/File”, “SourceFileName”);
//GetKey returns the value of specified key which is called in previous line. FileName is adapter parameter.
String filename = conf.get(key);
//The filename is returned containing a name of a file or folder, which can include a path and file extension.
Basically completes all the statements in the method.
return filename;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajesh,
What do you mean? It is in sap help Configuring the Sender File/FTP Adapter - SAP NetWeaver Exchange Infrastructure - SAP Library
Regards,
Mark
Hi Mark,
Thanks for the reply.
I went across the link which you provided about sender file adapter configurations.
In 7.01 version there is no advanced tab in communication channel of Integration Directory. PFB for the same.
By the way FTP team post ony xml files in source directory so no need of FCC i guess.
Please help on this issue. Thanks
Hi Mark,
See if my comments are right. If wrong please very well correct me line by line.
//Providing xi location package and title GetFilname as string.
Imports com.sap.xi.tf.*;
Public String GetFileName(Container container){
//This interface GetTransformation contains constants and Parameters that can be used in a java mapping to access runtime parameters.
Most of these parameters are attributes of the message header, e.g., sender party, sender service, etc.
DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//In class DynamicConfigurationKey it Creates an instance specifying the namespace of adapter type and name of ASMA attributes.
DynamicConfigurationKey key = DynamciConfigurationKey.create(“http://sap.com/xi/XI/System/File”, “SourceFileName”);
//GetKey returns the value of specified key which is called in previous line.
String filename = conf.get(key);
//The filename is returned.
return filename;
Hi ,
Try this below code
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
string filename=conf.get(key);
filename="Your desired format";
return filename;
Map this to the required node.it doesnot have any input.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neha,
Have you tried to use the dateTrans function and take its output like input parameter in your UDF?
Check this Sarvesh Singh's blog about dateTrans function
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You should return the Filename as a string and also no need of any input for the Filename UDF
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You might want to check this link and try to convert the source timestamp to your required timestamp. Parsing the timestamp using substring might leads to errors.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.