Entering content frame

Function documentation SET Locate the document in its SAP Library structure

Function

Sets a global variable of the JavaScript context to a value. If the variable is not yet available, it is created with the specified name. The variable can be accessed while all the compiled scripts (COMPILE or EVALUATE methods) of the same context are being executed and with the GET method. Only properties of the root object can be set with SET.

Importing Parameter

NAME (Type STRING)

Name of the variables to be set.

VALUE (Type STRING)

Value to which the variable is set.

Example

Example

report DEMO_JAVA_SCRIPT_SET.

data RETURN_VALUE type STRING.

data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.

JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

JS_PROCESSOR->SET( NAME = 'Field' VALUE = 'Hello' ).

JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = 'Field += " World!";' ).

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

write RETURN_VALUE.

The SET method generates a global JavaScript variable 'Field' and sets it to the value 'Hello'. Two different scripts are then evaluated with the EVALUATE method. Both of these scripts access this variable. The first script changes the variable and the second script returns the value 'Hello World!' to RETURN_VALUE.

Leaving content frame