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

Function

Executes a script compiled using the COMPILE method. The global data of the script is then available in the context.

Importing Parameter

SCRIPT_NAME (Type STRING)

Name under which the compiled script is stored in the context.

Returning Parameter

RESULT (Type STRING)

Value of the last statement executed in the script.

Example

Example

report DEMO_JAVA_SCRIPT_EXECUTE.

data SOURCE type STRING.
data RETURN_VALUE type STRING.

data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.

JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

concatenate
  'var string = "Hello World";            '
  'function Set_String()                  '
  '  { string += ", this is JavaScript!"; '
  '  }                                    '
  'Set_String();                          '
  'string;                                '
    into SOURCE separated by CL_ABAP_CHAR_UTILITIES=>CR_LF.

JS_PROCESSOR->COMPILE( SCRIPT_NAME = 'HELLO_WORLD.JS'
                       SCRIPT      = SOURCE ).

RETURN_VALUE = JS_PROCESSOR->EXECUTE( 'HELLO_WORLD.JS' ).

write RETURN_VALUE.

The functional call of the EXECUTE method executes the script compiled under the name 'HELLO_WORLD.JS'. RETURN_VALUE then contains the value 'Hello World, this is JavaScript!'.

Leaving content frame