You are on page 1of 2

Using replaceAll function

On Presession:
object obj;
obj = new("java.lang.String");
On the N102:
If #0093 != "" then
Begin
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:
Astericks (\*) replace with

("\\\n"," - ");
("\*","?")

Another example this separates out the assign and replace, which may be a better approach
object rem_ob1;
rem_ob1=new("java.lang.String",mid(#TDLINE:5,61,17));
rem_ob1.replaceAll("\*",".")
Decimal Formatting with rounding:
Initialization
Object ob1;
String[16] Var_target;
ob1 = new("java.text.DecimalFormat","0.000");
Use
Var_target = ob1.format(<Field or Variable>);
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 miliseconds


object 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 formats
1. Create public variables in Pre-session rules:
string[30] sDateFmt, sDateTimeFmt;
sDateFmt = "yyyy-MM-dd";
sDateTimeFmt = "yyyy-MM-dd hh.mm.ss.SSSSSS";

2. In extended rule to reformat date:


datetime dTemp;
object ob_format;
string[30] dd, sTemp;
dd = "";
sTemp = "";
dTemp = '';
// Standardize input date for Java Function
if 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
#<fieldname> = ##<fieldname> + ^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.

You might also like