0% found this document useful (0 votes)
3 views2 pages

Java String and Date Manipulation Guide

This document provides examples of using various Java functions in Extended Rules including: - Using replaceAll to replace characters in a string - Formatting decimals with rounding - Generating random numbers - Converting strings to uppercase - Getting the current date and time in a specified format - Standardizing date formats - Adding hexadecimal characters to strings - Using temp fields instead of variables for Java function outputs

Uploaded by

Abhishek Dhawan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java String and Date Manipulation Guide

This document provides examples of using various Java functions in Extended Rules including: - Using replaceAll to replace characters in a string - Formatting decimals with rounding - Generating random numbers - Converting strings to uppercase - Getting the current date and time in a specified format - Standardizing date formats - Adding hexadecimal characters to strings - Using temp fields instead of variables for Java function outputs

Uploaded by

Abhishek Dhawan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

Using replaceAll function

On Presession:
object obj;
obj = new("[Link]");
On the N102:
If #0093 != "" then
Begin
obj=new ("[Link]", #0093);
#0093 = [Link]("," , "");
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("[Link]",mid(#TDLINE:5,61,17));
rem_ob1.replaceAll("\*",".")
Decimal Formatting with rounding:
Initialization
Object ob1;
String[16] Var_target;
ob1 = new("[Link]","0.000");
Use
Var_target = [Link](<Field or Variable>);
Random Number Generator:
object UniqueNumber;
UniqueNumber = new("[Link]");
#UniqueNumber = [Link]();
Upper Case:
object ob;
ob = new ("[Link]", #field);
#field = [Link]();

Current Date using extended date format with miliseconds


object ob_date;
object ob_format;
string[30] dd;
ob_date = new ("[Link]");
ob_format = new ("[Link]", "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 [Link]";

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 ("[Link]", 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