Java functions in Xi

Source: Internet
Author: User
1. Split Function

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 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

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

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

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

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

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 ++)

Unknown macro: {If (xmlstring. charat (I) = '<') {flag = 1; Res = res + xmlstring. charat (I );}

Else
 

Unknown macro: {If (xmlstring. charat (I) = '>') {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]);}

}
Https://wiki.sdn.sap.com/wiki/display/XI/JAVA+Functions+in+XI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.