File Name in UDF
Hi,
I am writing one UDF in which based on the input value, the target file name has to be changed. For example if the input value is "1120" then the target file name should be "1120.txt" and if the input value is null then ".txt" should be the file name. My code is working fine if the input contains value and if the input value is null, then it is giving run time exception "Base run time error in message mapping". My requirement is the empty file ".txt" has to be created. Can you please help me to handle the situation.
Thanks,
Naresh
Sorry experts,
I can not use variable substitution.. here i am giving my error and code.. Please help me out..
Runtime exception during processing target field mapping /ns0:MT_InternalOrder/Record/E_IbuyEntity. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._MM_INF00083_02_SAP_to_IBUY_ method Dynamic$[114S.txt, com.sap.aii.mappingtool.tf3.rt.Context@735c735c] com.sap.aii.mappingtool.tf3.MessageMappingException: Runtime exception during processing target field mapping /ns0:MT_InternalOrder/Record/E_IbuyEntity. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._MM_INF00083_02_SAP_to_IBUY_ method Dynamic$[114S.txt, com.sap.aii.mappingtool.tf3.rt.Context@735c735c]
MappingTrace importanttrace;
importanttrace = container.getTrace();
importanttrace.addWarning(a);
DynamicConfiguration objDynConf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey objKey1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
objDynConf.put(objKey1, a);
container.setParameter(StreamTransformationConstants.DYNAMIC_CONFIGURATION, objDynConf);
return (a);
Thanks,
Naresh
Similar Messages
-
File to proxy dont get the file name from UDF
Hi Pi gurus,
when i try to get the name of the file from the mapping by using the code above in a UDF i simply get a null in place of the real name of the file.
here the code that i used:
=============================
String SourceFileName = "";
String context ="http"+":" +"/" +"/" + "sap.com/xi/XI/System/File";
try {
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http"+":" + "/" +"/" + "sap.com/xi/XI/System/File","filename");
SourceFileName = conf.get(key);
catch(Exception e)
SourceFileName = context;
return SourceFileName;
=================================
thank youhey
In the sender File communication channel,did you check the Checkbox.
"Set adapter specific message attrbiutes" and "Filename"
if not,please do that first and test again.
Thanks
Aamir -
Get File Name in UDF from file adapter sender
Hi,
I've looking for this solution, but I couldn't find any usefull information.
I want to obtain the name of the file, sended by the file adapter.. and later use it in the mapping logic.
I've readed about sustitution... any help?
Thanks.HI Stortoni,
Take a look at these blogs:
http://wiki.sdn.sap.com/wiki/display/XI/CombiningthreedifferentaspectsofPIinoneshot
/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14
/people/sap.user72/blog/2005/07/15/copy-a-file-with-same-filename-using-xi
Regards,
---Satish -
File Name and Target Directory name issue in FTP CC
Hi All ,
I am using following code to assing file name and directory name in UDF. I don;t want these parameters to be part of my target structure. Since i have created these files names in UDF, what are the values do i need to mention in FTP CC's "File access Parameter" which are mandatory fiels in CC ?
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create(u201Chttp://sap.com/xi/XI/System/Fileu201D,u201CFileNameu201D);
String myFileName =biz +".dat";
conf.put(key, myFileName);
//Similar code for direcotry
Thanks for your support.
MKHi,
in ID in receiver file comm channel, just tick the option of Adapter Specific messge attributes and in it tick FileName and DirectoryName.............
the filename and directory you give in comm channel will be treated as dummy and the values will be taken from your UDF.......
Regards,
Rajeev Gupta -
How write the Outbound file name in the Inbound file
Friends,
I have a scenario like this.
Outbout filename - sample.txt
In sample.txt, i have having data like 20
Inbound filename - vivek.txt
i need data the like sample, 20
(NOTE: sample is the outbound file)
How to get this scenario.
Thanks in advance.
regards,
Vivek.Hi Vivek,
If your PI is of SP14 and more you have an option called Adapter Specific Message Attributes.(ASMA) in communicatoin channel configurtaion, Which will help you in capturing the Sender file name during runtime.
So you will have to enable that option (ASMA) in Commchannel and capture file name in UDF using Java Code with the help of sap related API and map it to the target field which u would like to get populated.
follow the thread it has the discussion about acessing the Source file name.
Re: Getting file directory using dynamic configuration:Code needed
Thanks,
Ram. -
Hi All,
I am trying to use dynamic attribute file name using UDF in message mapping:
<i>String filename = null;
filename = "Yahoo";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://seeburger.com/xi/common" , "dtSubject");
conf.put(key1,filename);
return "";</i>
But its just giving me the name on the receiver side as in the sender side.
I have checked FileName in Dynamic attributes in the reciever adapter.
Regards,
XIeryour return statement looks like <i>return "";</i>
Return the filename that you have assigned inside the UDF and can be achieved by
conf.put(key1,filename);
<b>return filename;</b>
Do refer this blog as well
/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14 -
Hi Master,
I written the UDF for Getting the Dynamic File name.
DynamicConfiguration conf = (DynamicConfiguration) container.getParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
// Retrieve the filename
String FileName = conf.get(key);
This is working ok - but I want to return these values so I can be used in mapping.
when I try to add the statement return FileName; , the compiler then complains with the following error:
cannot return a value from method whose result type is void return FileName;
Please help me,
Thanks,
AnuThanks Nithiyanandam,
I am using the Same code. But i am getting the Syntax error:
Source code has syntax error: E:/usr/sap/DX1/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Mapaf708c00d6bb11dd83ee00101816a382/source/com/sap/xi/tf/_MM_I_FF_O_RFC_.java:13: cannot resolve symbol symbol : class variable location: class com.sap.xi.tf._MM_I_FF_O_RFC_ variable a; ^ 1 error
UDF Name: FileName
while creating the UDF, I select the first radio button(Value). not Context and Queue.
I written the 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.put(key, a);
return FileName;
Thanks,
ANU -
Udf to pass constant corrsponding to 2 file names from different location
if i have one source file, i m able to pass the file name directly to the target through the udf below:
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
return ourSourceFileName;
But i have 2 files from different location. Now both files has dates at the end. how can i pass AAA for File1.txt and BBB for File2.txt. .
after the above code, i have included below code too, but not working(*-for date n timestamps):
if(ourSourceFileName.equals("ABC*.txt"))
return "FILE1";
else if(ourSourceFileName.equals("XYZ*.txt"))
return "FILE2";
please suggestHi Basker,
Error in activating object in IR - heres the total code i have used for this purpose. plz help in getting this.
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
return ourSourceFileName;
if(ourSourceFileName.equals("SOURCE_1*.txt"))
return "File1";
else if(ourSourceFileName.equals("SOURCE_2*.txt"))
return "File2";
Source code has syntax error: /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Map27461f402eff11e0898d00144f1e71f0/source/com/sap/xi/tf/_MM_UPDATE_.java:839: unreachable statement if(ourSourceFileName.equals("SOURCE1_*.txt")) ^ /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Map27461f402eff11e0898d00144f1e71f0/source/com/sap/xi/tf/_MM_UPDATE_.java:844: missing return statement } ^ 2 errors -
UDF to capture the source file name or the source folder for mapping
Hi All,
i have 2 files - File1 from File2 from 2 different folders- single comm channel FTP (FCC). i have to pass a constant A and B respectively to a field in target structure.
my options are -
either create a new field in source str populating different constants and then map to the target str
or a udf to get the source file name or the source folder so that i can map the constant using the value mapping/FixValue mapping.
please suggest. thanks.
rajibHi,
please use the UDF to determine the file name. Then based on file name either pass A or B to your target field.
The code is as given below. Just tweak the code to pass either A or B as per your requirement.
public String G_GetFileName(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 ourSourceFileName = conf.get(key);
return ourSourceFileName;
Regards,
Deepak. -
UDF to read a file name and use some of its contents to map fields in target.
I have a scenario where I need to take the month and year from the file name and map it to suitable fields in the target. Ex - filename_apr2014 from this i should be able to read the month and year and map it. How to do this? I tried the udf -
public String getFileName(Container container){
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
return ourSourceFileName;
got this error while testing the mapping -
Runtime exception when processing target-field mapping /ns0:MT_<<>>_Output/I<<>>; root message: Exception:[java.lang.NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.DynamicConfiguration.get(com.sap.aii.mapping.api.DynamicConfigurationKey) of a null object loaded from a local variable at slot 2] in class <<>> method getSourceFileName[com.sap.aii.mappingtool.tf7.rt.Context@5b04fc0f]
See error logs for detailsHi Satish - You declared "conf" twice.
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
UDF -
String filename = "";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","FileName");
filename = conf.get(key);
return filename;
And did you define the variable slot 2 in any of your UDF's?
The above UDF return the filename and you should handle the sub string later.. -
Same file name from sender to receiver file adapter with out using UDF
Hi All,
I am working on FILE TO FILE. My requirement is same file name from sender to receiver file adapter. Is it possible to do using only Adapter Specific message properties? i mean with out using UDF.
Thanks
KarthikHi,
>>>Is it possible to do using only Adapter Specific message properties?
yes
just enable Adapter Specific message properties in sender and receiver channel for file name
and you're done
Regards,
Michal Krawczyk -
UDF for getting File Name and updating in target as reference value
Dear All,
I am working on File-PI-RFC interface. In one of the columns of RFC, I need to pass the File Name as reference.
Kindly guide me on which UDF can be used for this requirement.
Regards,
NJHi Nishu Jain,
Basically my requirement to get Filename in idoc segments in order to validate the posting at month end.
Its an File to idoc scenario- GL Posting.
Please check attached UDF and it gives error. Kindly help. Thanks -
Hi Experts,
I am working on one scenrio, where i am fetching the file name dynamically by adapter module.
Now, the file name needs to be checked for the following conditions:
BOOKING_REF_DELIVERYNO_WB.pdf
BOOKING_REF_DELIVERYNO_BOLCOPY.PDF
DELIVERYNO_AWB.PDF
Depending upon the type of file being picked up by PI from the mail box,following needs to be done:
1.time stamp needs to be added ..
ex..
for file SO10162239_123_458_BOLCOPY.pdf--> the file name must be changed to :
SO10162239_X2100_20101206_123_458_BOLCOPY.pdf.
Please suggest if this can be done by graphical mapping ?
Thanks,
Sushamahi,
I am using following UDF..
FileName->ParseFile>getNykFilename>concat--
Current date-> concat> Trim> FileName
concat----
|
constatnt[.pdf]--->
UDF for parse file:
String[] sarray;
String regex = "\"";
String retstring;
String fname;
int l= raw.length();
try {
sarray = raw.split(regex, 3);
retstring = sarray[1];
fname=sarray[l-1];
if( fname=="WB")
raw.concat("_X2100_");
else if (fname=="BOLCOPY")
raw.concat("_X2101_");
else if (fname=="AWB")
raw.concat("_X2102_");
} catch (Exception e) {
retstring = "no_att_name_found.err";
return retstring;
UDF for getNykFileName:
String[] sarray;
String regex = "[_]";
String retstring;
if(!orgName.endsWith(".err")){
try {
sarray = orgName.split(regex, 3);
retstring = sarray[0];
} catch (Exception e) {
retstring = "nyk_filename.err";
return retstring;
}else{
return orgName;
But, its not working..
Its giving the file name as:
no_att_name_found.err20101206 for the input file : 801243209_81473641_wb.pdf
Display queue result for parsefileName:
"no_att_name_found.err"
Please suggest.
Thanks,
Suahama -
UDF for Reciver file name.
Hi Can any one provide me UDFfor following Requirement.
My source file name is like this XXXX081090001 and i want reciver file name as XXXXMT940.
Where MT940 is constant and XXXX is first 4 digits of Source file name.
Note that First four digits of Source file name can change.
Example :- Source file name ABC081090001 -
Target should be ABCMT940
and if Source file name is XYZ091100002 -
Target should be XYZMT940.
Thanks in advance....Hi,
try this one...
DynamicConfiguration conf = (DynamicConfiguration)
container.getTransformationParameters().get
(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create
("http://sap.com/xi/XI/System/File","FileName");
String input = conf.get(key);
String s1 = input.substring(0,4);
String s2 = "MT940";
String newfile = s1.concat(s2);
conf.put(key,newfile);
return (newfile);
Consider to set "Filename" in the Adapter Specific Message Attributes in FileAdapter.
Regards,
Ralph -
Changing time stamp format in the file receiver adapter file name
Hi all,
How can we change the standard date time stamp from
filename_yyyymmdd-hhmmss-mil
to
filename_yymmdd_hhmmss
i.e., I want "underscores" instead of "hyphens" and also I do not want the MilliSeconds.
I read in the forums that I have to use the combination of variable substitution and mapping functions to do this, but not sure how exactly.
Can the experts help me with this please?
Many thanks.Hello Ramesh,
You can make this possible using runtime filename creation using UDF.
Please go though the below steps.
Message mapping:
Create an UDF and include the piece of code that captures the Filename and Timestamp from source side via ASMA.
Modify them according to our requirement by adding the <Timestamp> at the end of <filename> with _.
Map the UDF to any of the top level node so that the modified filename will be available for the target communication channel
UDF Code is:
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 = filenametimestamp".xml";
filename = filename.replaceAll( "-" ,"_" );
conf1.put(key1,filename);
return filename;
catch(Exception e)
String exception = e.toString();
return exception;
Click on Advanced tab and check the Option u201CSetAdapterSpecificMessageAttributesu201D in addition to that check the attribute that are required to be captured during run time. In our case File Name and Source File Time Stamp are required to be checked
In the receiver communication channel Mention u2018 * u2018as File Name Scheme.
Click on Advanced tab and check the Option u201CSetAdapterSpecificMessageAttributesu201D in addition to that check the attribute u201CFile Nameu201D which will carry the modified value in the UDF .
i hope this will help you.
Monica
Maybe you are looking for
-
Ipod cannot be updated the disk could not be readfrom or written to
what does this mean? I don't have any disk,I'm just trying to download songs from my library to ipod and I get this message,please help
-
IPhoto onto External Hard drive
I am trying to be able to completely remove iPhoto from my internal hard drive and move it to my external hard drive. I have over 8000 and have no plan on stopping soon I want to be able to open iPhoto from my external hard drive and see my sorted fo
-
Uploading DVD from laptop to iPod Video
I have a wonderful music video I'd like to put on my iPod, but can't seem to figure out how to do that from the cd-drive on my laptop. If anyone can help, I would greatly appreciate it. Yes, I've checked the manual....can't seem to figure out what to
-
Summary Report question regarding data that is included and data that is not.
I have a survey that is running at the momemt with about 15% of the expected responses(250-300) which I'll gather over the next couple of weeks. When I check the current Summary Report it omits several of the questions and answers shown in the curren
-
Lion Recovery Disk erased mounted volume
Has anyone had this problem: I created a Lion Recovery Disk and it erased mounted volume? Can the data be recovered?