Entering content frameFunction documentation CREATE Locate the document in its SAP Library structure

Function

Creates an object of the class CL_JAVA_SCRIPT and simultaneously creates a context for the JavaScript Engine, which you can use to access the object. Several JavaScript contexts can be created for each ABAP program. Conversely, each JavaScript context can contain several compiled scripts. A JavaScript context can be deleted immediately using the ABAP_DESTRUCTOR method. Otherwise its lifetime lasts until the ABAP Garbage Collector deletes it.

Each JavaScript context has a global data area, which the GET method and all compiled scripts in the context can access. You can define global data either using the SET method or in the scripts themselves (outside the functions).

Returning parameter

RESULT (type REF TO CL_JAVA_SCRIPT)

Reference to the created object and to the context of the JavaScript Engine.

Example

Example

report DEMO_JAVA_SCRIPT_CREATE.

data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.
JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

...

JS_PROCESSOR->COMPILE( SCRIPT_NAME = 'SCR.JS'
                 SCRIPT = 'var Field = "Hello World!";' ).

JS_PROCESSOR->EXECUTE( SCRIPT_NAME = 'SCR.JS' ).

RETURN_VALUE =
         JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = 'Field;' ).

A JavaScript context is created in the form of an ABAP object and the appropriate reference is assigned to the reference variable JS_PROCESSOR. This allows you to use the JavaScript Engine using the reference variable. The program compiles and executes a script called SCR.JS, which defines a global variable Field and assigns a value to it. Another temporary script evaluates the variable.

 

 

Leaving content frame