Tuesday, April 27, 2010

Using JAVA script in the ABAP workbench...



I have been reading up in the ABAPDOCU in SAP that there is a class available to use in ABAP that will simulate a JAVA Script engine.

The class is CL_JAVA_SCRIPT.


According to the documentation there are 4 things you need to do to get the JAVA Script engine to function in the ABAP environment.

The following in exerpted from the ABAPDOCU:

Executing JavaScript Programs

You can use the CL_JAVA_SCRIPT class to execute JavaScript programs that, for example, have been loaded from external resources or programmed in an Editor you have written yourself: The following are the methods you use, in the sequence in which they are called:

  1. CREATE to create a JavaScript context
  2. CREATE to compile a JavaScript source in the current context
  3. EXECUTE to execute a compiled JavaScript
  4. EXECUTE to delete a compiled JavaScript from the context

Methods 2 to 4 are combined in the method EVALUATE.

I just used their class to write a hello world in JAVA SCRIPT also taken from their docu section…

REPORT  zjava_demo_abap_1.
DATA: js_processor TYPE REF TO cl_java_script,
      return_value TYPE string.

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;' ).

WRITE return_value.



So I guess my question is, If we have to have the PI environment to run certain programs because they require JAVA Script to run, WHY not convert them to use the JAVA_SCRIPT class?



Post a Comment