on 02-25-2008 11:58 AM
Hi Friends,
Its an IDOC to File interface. For a particular field coming from IDOC I need to calculate the length. The actual length I need to send is only 8 . In XI is there any UDF for calculating the length of that particular field?
I need the calculations as follows: if length of field is less than 8, need to send a length of 8 starting from the right with zeros padded on the left and equal to 9 or 10 then only last 8 need to be considered.
Thanks in advance,
Regards,
Meghna.
public String appendZero(String a,Container container)
// code start
int length = a.length();
if ( length > 8 )
return(a.substring((a.length()-8),a.length()));
else
for (int i=length;i<8;i++)
{
a="0"+a;
}
return a;
// code ends
input1 : ABC
Result : 00000ABC
input2 : ABC123456
Result: BC123456
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Meghna,
This would require some simple java Coding
let us assume the field is a
int diff;
String delimter = "0".
diff = a.length - 8.
if ( diff = 0 ){
// do nothing
}
elseif ( diff > 0 ) {
a.substring( start index , end index ) would be your answer
}
Elseif ( diff < 0 ){
for ( int i = 0 ; i <= diff ; i ++ ) {
delimter = delimeter.concat("0").
}
delimeter.concat(a) would be your String.
Put this in an UDF execute yourmapping
award points if useful
Regards
Abhishek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You could do this with UDF
See below code
Source field --->> Test UDF ---> Target field
Use the A as Source field and cache parameter as value.
try
{
If(A.length() >= 😎
return(A.substring((a.length()-8),a.length()));
else
{
for(int i=0; i<(A.length()-8); i++)
A = A.concat("0");
return(A.substring((a.length()-8),a.length()));
}
}catch(Exception e){}
Thanks
Swarup
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
the above mentioned code is just have to copy paste in your UDF editor.
This is the complete code as per your requirment.
If still you have some other things to be consider please let me know.
Is there any multiple occurance with the Target field then probably you need some changes in the coding. Let me know about it.
Otherwise above code is fine. Its the compact way of coding UDF...:-)
Thanks
Swarup
User | Count |
---|---|
71 | |
26 | |
10 | |
9 | |
7 | |
6 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.