Function
Compiles a script and stores the compiled version in the current context so that it can be executed. All of the compiled scripts in a context can access the global data of the context. Global data can be created with the SET method or by executing scripts.
Importing Parameter
SCRIPT_NAME (Type STRING)
Name under which the compiled script is stored in the current context.
SCRIPT (Type STRING)
JavaScript source text in a string in which individual source text lines are separated from one another by the static constant CL_ABAP_CHAR_UTILITIES=>CR_LF.
Example
report DEMO_JAVA_SCRIPT_COMPILE.
data SOURCE type STRING.
data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.
data RETURN_VALUE type STRING.
JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).
SOURCE = 'var string; string = "Hello World!";'.
call method JS_PROCESSOR->COMPILE
exporting
SCRIPT_NAME = 'HELLO_WORLD.JS'
SCRIPT = SOURCE.
RETURN_VALUE = JS_PROCESSOR->EXECUTE( 'HELLO_WORLD.JS' ).
write RETURN_VALUE.
The script in the SOURCE string is compiled and stored in the context as HELLO_WORD.JS. It can then be executed with the EXECUTE method.