cancel
Showing results for 
Search instead for 
Did you mean: 

Need UDF for For Length Condition

Former Member
0 Kudos

Hi Experts,

I need a UDF for this below business case we have vendor name which having length 45. that need to mapped with Name1 & name 2. in the Target.

for the name1 the condition is like if vendor name having length up to 35 that will comes in Name1 filed.

for the Name2 . the condition is like if the vendor name is having more vthan 35 i.e means 35 to 45 those charactes will be filled in Name 2

let me give one exampl

vendorname-pavankumar- will goes to name1 bcz it's length is below35

vendorname- pavankumar pavankumarpavankumarpavankumar

pavankumar

- kumar will comes in Name2 filed bcz its more than length 35

I Need UDF For NAME2 Condition

please help me out. bcz this is my first UDF . i have never done UDF before

Thanks in Advance

Pavan

Edited by: Pavan Kumar Thiruveedula on Jan 4, 2012 12:42 PM

Accepted Solutions (0)

Answers (2)

Answers (2)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Pavan,

I think you can solve this using graphical mapping alone


vendorName-----> length------>
                                                             less ------->          
                              constant(36)--->
                                                                                ifwithoutelse  ---->Name1
                                                               vendorname --->                                                      
 

same logic for name2 field also. I used standard text, boolean and arithmetic fuctions.

Regards

Anupam

Former Member
0 Kudos

Hi Priyanka,

I applied the below logic

Venorname -


>length

Constant-35---> greater than-> if-> then--->vendorname substring(35, 10) -


> else constant() -


>name2. but the problem is here i am using substring so that mean it's length should be 45 mandatory. but in real time we have vendor name may have 36 character length or 37,38,39,40 etc up to 45. please help me out.

Thanks In Advance

Pavan

anupam_ghosh2
Active Contributor
0 Kudos

Hi ,

you can try below logic for name2



vendorName-----> length------>
                                                             greater ------->          
                              constant(35)--->
                                                                                ifwithoutelse  ---->Name2
                                                               vendorname --->                                                   

Please note that minimum occurence of name1 or name2 should be Zero.

Regards

Anupam

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

str is the name of the input parameter to udf.....please check by default it'll be var i think....

Regards,

Priyanka.

Former Member
0 Kudos

Hi Anupam,

Thanks for giving reply.

I tried to apply your logic but is giving output as true not the values.

Former Member
0 Kudos

Hi Priyanka,

I will explian you what i have done from the start. i clicked on User-defined fuction in that i saw arguement follwed by Var1. in the var1 field i replaced with Vendor name and then i clicked create function in that i copied you UDF logic like below

String result ="";

if(VendorName.length > 35){

result = VendorName.subString(35,VendorName.length-1);

}

return result;

then i mapped with vendorname->title->Name2

and later i tested i am getting this error

Source text of object Message Mapping: MM_VendorMasterTransferToTRAX | http://thy.com/FI/AP/VendorMasterTransferToTRAX_0088 has syntax errors:

Function calculate, Line 2:

cannot find symbol symbol : variable length location: class java.lang.String if(VendorName.length > 35){ ^

Function calculate, Line 3:

cannot find symbol symbol : variable length location: class java.lang.String result = VendorName.subString(35,VendorName.length-1); ^

Function calculate, Line 3:

cannot find symbol symbol : method subString(int,int) location: class java.lang.String result = VendorName.subString(35,VendorName.length-1); ^ Note: /usr/sap/D04/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map3075e9cf36d011e185e800000049bc5e/source/com/sap/xi/tf/_MM_VendorMasterTransferToTRAX_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 3 errors

plz help out i never worked on UDF's before. your assistance is very great full to me.

Regards,

Pavan

anupam_ghosh2
Active Contributor
0 Kudos

Hi Pavan,



vendorName-----> length------>
                                                             greater ------->          
                              constant(35)--->

should be input to ifwithoutelse

and in the "then" part of "ifwithoutelse" input will be vendorname.

This is working in my system.

Please let me know if it works.

Regards

Anupam

Former Member
0 Kudos

i appiled you logic like below

Vendor name----->length

constant(35)--


>gretaerthat-if--->then -vendorname---->name2

but i am getting entire vendorname . i want only characters between 35 to 45

Regards,

Pavan

Former Member
0 Kudos

chk this code(same as Priyanka's suggestion but with slight modifications):

Execution type: single value

Variable name: VnedorName


 String result ="";
if(VendorName.length() >35)
{
result = VendorName.substring(35);
}
return result;

Former Member
0 Kudos

Hi Anupam,

What i need to do just map with direct means vendorname-->udf->name2

please help out

Regards,

Pavan

PriyankaAnagani
Active Contributor
0 Kudos

Hi Pavan,

Sorry I've missed () after length function. Please try this



String result ="";
if(VendorName.length() > 35){
result = result +VendorName.subString(35,VendorName.length()-1);
}


Regards,

Priyanka

anupam_ghosh2
Active Contributor
0 Kudos

Hi Pavan,

Apologies I jumped this point of your second requirement. Logic for Name1 filed remains same as my earlier post.

for name 2 you need an UDF .


 String dynamic(String vendorname)
	{
	
		int i,l;
		l=vendorname.length();
		if(l>35)
		{
			vendorname=vendorname.substring(35,vendorname.length());
		}
		else
		{
			vendorname="";
		}
		return vendorname;
	} 

Hi Priyanka,

I feel the UDF you wrote might be missing the last character of the string.

Regards

Anupam

Edited by: anupamsap on Jan 4, 2012 2:13 PM

anupam_ghosh2
Active Contributor
0 Kudos

removing the post since I already posted the same earlier.

Former Member
0 Kudos

Thnaks alot anupam. YOur UDF Is Working fine. BUT I solved this with below logic

Vendorname---Length>Constant->35

-


Greaterthan--->IF->then> Vendorname-substring(35,0)--> Else-> constant ()----


>Name2

Thank you very much for you help. this is my first UDF.

Thanks & Regards,

Pavan

PriyankaAnagani
Active Contributor
0 Kudos

Hi Pavan,

What is the occurrence of Name2 in the target.....If it is zero,please try with the below code...pass thestr as input to UDF

what you want to pass to field name2 whent the length greater than 35 add that one in else condition.


String result ="";
if(str.length > 35){
	result = str.subString(35,str.length-1);
}
return result;

Regards,

Priyanka

Former Member
0 Kudos

Hi Priyanka,

Thanks For Giving Reply. The UDF Which you given can i need to fill any thing in this Double Quotes of the below one

String result ="";

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

You dont need to pass any thing, it'll be an empty string. If the condition is satisfied it'll be filled with characters from input string whose length i s greater than 35.

Regards,

Priyanka

Former Member
0 Kudos

HI Priyanka

i am getting this below error i just copied the UDF which you have given

Source text of object Message Mapping: MM_VendorMasterTransferToTRAX | http://thy.com/FI/AP/VendorMasterTransferToTRAX_0088 has syntax errors:

Function calculate, Line 2:

cannot find symbol symbol : variable str location: class com.sap.xi.tf._MM_VendorMasterTransferToTRAX_ if(str.length > 35){ ^

Function calculate, Line 3:

cannot find symbol symbol : variable str location: class com.sap.xi.tf._MM_VendorMasterTransferToTRAX_ result = str.subString(35,str.length-1); ^

Function calculate, Line 3:

cannot find symbol symbol : variable str location: class com.sap.xi.tf._MM_VendorMasterTransferToTRAX_ result = str.subString(35,str.length-1); ^ Note: /usr/sap/D04/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map6f346e5036cd11e1c1c900000049bc5e/source/com/sap/xi/tf/_MM_VendorMasterTransferToTRAX_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 3 errors