Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
SEdelstein
Product and Topic Expert
Product and Topic Expert

General Syntax:
The data to be converted is initially identified in the system variable %external%. JavaScript functionality can be accessed by preceding any command with the key "js:" to indicate a JavaScript command will follow next.

To use JavaScript, ensure that the CONVERT_INTERNAL parameter is set in the calling Transformation file as follows:
If the transformation option Convert_Internal = NO, JavaScript can be used in the Internal column.
Example: the function js:parseInt(%internal%) placed in the internal column of the conversion sheet will return the Integer portion of the converted data.

If the transformation option Convert_Internal = YES, JavaScript can be used in the External column.
Example: the function js:parseInt(%external%) placed in the external column of the conversion sheet will return the Integer portion of the incoming data.

JavaScript can also be used in the FORMULA column of the Conversion sheet. The system variable "Value" is defined as the initial value of the string before processing:
js:Math.round(Value) and Value =0.60 returns the quantity "1"
js:Math.round(Value) and Value =0.50 returns the quantity "1"
js:Math.round(Value) and Value =0.49 returns the quantity "0"
js:Math.round(Value) and Value =-4.43 returns the quantity "-4"

Example:


Wildcards
You can use the asterisk (*) and question mark (?) wildcards in the External or Internal columns.
An asterisk (*) stands for any character, while a question mark (?) stands for any single
character. For example, if you want to reference all members, use the asterisk (*). Example: 


JavaScript function: parseInt()
This function parses an input string and returns an integer value. For example:
js:parseInt(%external%)and %external%="10 " returns the value 10
js:parseInt(%external%)and %external%="10.00" returns the value 10
js:parseInt(%external%)and %external%="50.33" returns the value 50
js:parseInt(%external%)and %external%="000000010" returns the value 10
js:parseInt(%external%)and %external%="C000010" returns the value "NaN"

Tips and Notes:
1. Only the first number in the string is returned!
2. Leading and trailing spaces are allowed.
3. If the first character cannot be converted to a number, parseInt() returns NaN ("Not a Number").

Example:

 

JavaScript function: if...then...else
Use the if/then/else statement to execute some code if the condition is true and another code if the condition is false.
See example above: js: if(isNaN(%external%)) then %external%.substring(0,6);else parseInt(%external%) .


JavaScript function: toUpperCase()
This function coverts all characters in the input string into upper case characters.
Example:

JavaScript function: replace
This function finds a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.
Example:

JavaScript function: split & join
This function finds a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring.

Example:

2 Comments