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

Function

Evaluates a script of a particular stack level in debugging mode. The prerequisite for this is that each script to be evaluated has been executed once with the EXECUTE method, even if it is only called up in the actual program execution.

Importing Parameter

STACK_ENTRY_NUMBER (Type I)

Number of the stack entry. Number 1 is always the highest (most current) stack entry, while numbers greater than 1 access entries at a lower position in the stack.

SCRIPT (Type STRING)

Script to be executed. The names of variables can be entered here and their value queried.

Returning Parameter

RESULT (Type STRING)

Value of the statement queried using EVALUATE_IN_STACK.

Example

Example

report DEMO_JAVA_SCRIPT_STEP.

data SOURCE1 type STRING.
data SOURCE2 type STRING.
data VALUE_GLOBAL type STRING.
data VALUE_LOCAL  type STRING.

data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.
data STACK type JS_STACK_TABLE.

data STACK_ENTRY like line of STACK.
data STACK_DEPTH type I.

JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

concatenate
  'function Set_String()          ' " 1
  '{                              ' " 2
  '  var local = "";              ' " 3
  '  local += " this";            ' " 4
  '  local += " is";              ' " 5
  '  local += " JavaScript";      ' " 6
  '  global = global + local;     ' " 7
  '  global += "!";               ' " 8
  '}                              ' " 9
   into SOURCE1 separated by CL_ABAP_CHAR_UTILITIES=>CR_LF.

concatenate
  'var global = "Hello World,";   ' " 1
  'Set_String();                  ' " 2
  'string;                        ' " 3
   into SOURCE2 separated by CL_ABAP_CHAR_UTILITIES=>CR_LF.

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

JS_PROCESSOR->EXECUTE( exporting SCRIPT_NAME = 'SOURCE1.JS' ).

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

JS_PROCESSOR->SET_BREAKPOINT(
    SCRIPT_NAME = 'SOURCE2.JS'
    LINE_NUMBER = 1 ).

JS_PROCESSOR->EXECUTE( exporting SCRIPT_NAME = 'SOURCE2.JS' ).

if JS_PROCESSOR->LAST_CONDITION_CODE =
                 CL_JAVA_SCRIPT=>CC_BREAKPOINT.
  STACK = JS_PROCESSOR->GET_CALL_STACK( ).
  STACK_DEPTH = LINES( STACK ).
endif.

while STACK_DEPTH > 0.

  read table STACK into STACK_ENTRY index 1.

  VALUE_GLOBAL = JS_PROCESSOR->EVALUATE_IN_STACK(
                 STACK_ENTRY_NUMBER = 1 SCRIPT = 'global' ).
  VALUE_LOCAL  = JS_PROCESSOR->EVALUATE_IN_STACK(
                 STACK_ENTRY_NUMBER = 1 SCRIPT = 'local' ).

  write: at /(3) STACK_ENTRY-LINE_NUMBER,
         at 10   STACK_ENTRY-SCRIPT_NAME,
         at 25   STACK_ENTRY-FUNCTION_NAME,
         at 40   VALUE_GLOBAL,
         at 75   VALUE_LOCAL.

  JS_PROCESSOR->STEP_INTO( ).

  STACK = JS_PROCESSOR->GET_CALL_STACK( ).
  STACK_DEPTH = LINES( STACK ).

endwhile.

Two scripts, SOURCE1.JS and SOURCE2.JS, are compiled here. SOURCE2.JS calls up the Set_String function in SOURCE1.JS. For SOURCE1.JS to be active in the stack, it has to be executed once after the compilation with the EXECUTE method. After a breakpoint has been set in line one, the EXECUTE method switches SOURCE1.JS to debugging mode. The current stack is read into an internal table with the GET_CALL_STACK method. The values of the variables from SOURCE1.JS and SOURCE2.JS are read with the EVALUATE_IN_STACK method. Since the value 1 is transferred for STACK_ENTRY_NUMBER, the most local context is always considered with the data visible here. The corresponding table line of the stack is output with the variables. The entire script is performed with the STEP_INTO method until its execution is finished and the stack is empty.

Leaving content frame