java tips

Upload: abhishek-dhawan

Post on 08-Jan-2016

212 views

Category:

Documents


0 download

DESCRIPTION

java

TRANSCRIPT

Using replaceAll function

On Presession:

object obj;obj = new("java.lang.String");

On the N102:

If #0093 != "" thenBegin obj=new ("java.lang.String", #0093); #0093 = obj.replaceAll("," , "");End

Please note to use special characters, prefix them with \ -

Carriage Return (\n) replace with null: ("\\\n"," - ");Astericks (\*) replace with ("\*","?")

Another example this separates out the assign and replace, which may be a better approachobject rem_ob1;

rem_ob1=new("java.lang.String",mid(#TDLINE:5,61,17)); rem_ob1.replaceAll("\*",".")

Decimal Formatting with rounding:InitializationObject ob1;String[16] Var_target; ob1 = new("java.text.DecimalFormat","0.000");

UseVar_target = ob1.format();

Random Number Generator:object UniqueNumber; UniqueNumber = new("java.util.Random"); #UniqueNumber = UniqueNumber.nextInt();

Upper Case:object ob;ob = new ("java.lang.String", #field);

#field = ob.toUpperCase();

Current Date using extended date format with milisecondsobject ob_date; object ob_format;

string[30] dd;

ob_date = new ("java.util.Date"); ob_format = new ("java.text.SimpleDateFormat", "yyyyMMddHHmmssSSS"); dd = ob_format.format (ob_date);

Standardized Date formatsCreate public variables in Pre-session rules:

string[30] sDateFmt, sDateTimeFmt;sDateFmt = "yyyy-MM-dd";sDateTimeFmt = "yyyy-MM-dd hh.mm.ss.SSSSSS";

In extended rule to reformat date:

datetime dTemp;object ob_format;string[30] dd, sTemp;dd = "";sTemp = "";dTemp = '';

// Standardize input date for Java Functionif len(#2380) = 8 then sTemp = #2380 + "000000";else sTemp = #2380;

dTemp = date("%Y%m%d%H%M%S", sTemp);// Transform date to predefined format.ob_format = new ("java.text.SimpleDateFormat", sDateFmt);dd = ob_format.format (dTemp);

// Assign variable to output field$TEMP_GROUP[iIDOC].#TEMP_DTM02 = dd;

Add Hex character to any string

Add ^0 with hex value to place in string. To add CR to end of string

# = ## + ^0D;

Use of temp fields vs variables for Java functions.

There are subtle differences between the test servers and production servers where a map might work in unit test environment but not work in production.

In this case, instead of assigning results from java function to variable, create temp field and assign output/results from java function to temp field.