Java functions in Xi 1. Split function is split into string arrays by characters
String [] strarray = lgort. Split (",") // -- pass lgort to this UDF
Int len1 = lgort. length;
For (I = 0; I <len1; I ++) {result. addvalue (strarray [I]);}
2. Global containers global Parameters 2.1 To store values in global variable
Container. getglobalcontainer (). setparameter ("str", fieldname );
2.2 To get the value already stored in global variable.
String mystr = (string) container. getglobalcontainer (). getparameter ("str ");
3. Removeleadingzeros deletes leading zero
Int value = integer. parseint (STR );
String str1 = integer. tostring (value );
Return str1;
You can also use this code.
Here a is input string.
// Write your code here
String B = A. replacefirst ("^ 0 + ","");
Return B;
4. Unique value globally unique value, one mapping, Run Time
String strlocal =
(String) container. getglobalcontainer (). getparameter ("strglobal ");
Container. getglobalcontainer (). setparameter ("strglobal", STR );
If (! Str. Equals (strlocal ))
Return "1 ";
Else
Return "0 ";
5. Credit/debit using substring character comparison
Int I = Str. Length ();
String str1 = Str. substring (I-1, I );
If (str1.equals ("-"))
Return "D ";
Else
Return "K ";
6. Capturing input file name in output file to modify the text name. This blog has more details.
Dynamicconfiguration conf = (dynamicconfiguration) container. gettransformationparameters (). Get (streamtransformationconstants. dynamic_configuration );
Dynamicconfigurationkey key = dynamicconfigurationkey. Create ("http://sap.com/xi/XI/System/File", "FILENAME ");
String outputfile = Conf. Get (key, a); // enable Asma in your er file Channel
Return outputfile;
7. Remove comma from string SEARCH replacement
Here 'A' is a input string.
// Write your code here
String B = "";
B = A. replaceall (",","");
Return B;
8. Find index of a word or sentence inside one sentence and get sub string starting from that index
Fixed string to find in sentence coming from input "A". result will contain in that index No as start point of index in other sentence.
// Write your code here
String Fixed = "order of"; // fixed string to find in sentence coming from input "A". result will contain that index No as start point of index in other sentence.
String res = "";
Int Index = 0;
Index = A. indexof (fixed );
Res = B. substring (index + 9, index + 12 );
Return res;
9. Add new line in end of each xml tag
Xmlstring is input to this program.
// Write your code here
String res = "";
Int flag = 0;
For (INT I = 0; I <xmlstring. Length (); I ++)
{If (xmlstring. charat = '<')
Unknown macro: {flag = 1; Res = res + xmlstring. charat (I );}
Else
{If (xmlstring. charat = '> ')
Unknown macro: {flag = 0; Res = res + xmlstring. charat (I) + "N ";}
Else
Unknown macro: {res = res + xmlstring. charat (I );}
}
}
Return res;
10. Displaying xmlstring in single line into approriate XML format
Xmlstring = xmlstring. replaceall ("> <", ""> \ n <");
11. Check if integer
Try
{
Int I = integer. parseint (input, 10 );
Return "integer ";
} Catch (numberformatexception exception)
{
Return "string ";
}
12. remove duplicates from List
// Write your code here
Hashset H = new hashset ();
For (INT I = 0; I <A. length; I ++)
{If (! H. contains (a [I])
Unknown macro: {H. Add (A [I]); Result. addvalue (A [I]);}
}
Http://wiki.sdn.sap.com/wiki/display/XI/JAVA+Functions+in+XI
Favorites