Entering content frameThis graphic is explained in the accompanying text Binding to Static Class Components Locate the document in its SAP Library structure

You can only access the static components of an ABAP class in JavaScript by binding to an object reference variable (Binding to Object References (Instances)) that has the static type of the class. However, you do not necessarily need to create an instance of the class in ABAP.

The static components of the ABAP class are mapped in JavaScript as a proxy object of the predefined proxy class SAPAbapCrefClass. When binding them to an object reference variable, the relevant proxy object (proxy) has a ‘Class’ property based on SAPAbapCrefClass.

The components of the proxy object ‘proxy.Class’ are:

You cannot add other properties or methods to the proxy object ‘proxy.Class’ in JavaScript. In JavaScript, if you make assignments to the ‘proxy.Class’ or if you try to access the components of a class that has not been loaded, JavaScript terminates.

Example

report DEMO_JAVA_SCRIPT_BIND_DREF.

class C1 definition.
  public section.
    class-data A1 type STRING value 'Hello'.
    class-methods M1.
  protected section.
    class-data A2 type STRING value 'Hello'.
endclass.

class C1 implementation.
  method M1.
    concatenate A1 '!' into A1.
  endmethod.
endclass.

data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.

data OREF type ref to C1.

data SOURCE type STRING.

start-of-selection.

  JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

  JS_PROCESSOR->BIND( exporting NAME_OBJ  = 'abap'
                               NAME_PROP = 'Oref'
                      changing  DATA      =  OREF ).

  concatenate  ' if ( abap.Oref.Class.isActive() )'
               '{ abap.Oref.Class.a1 += " World";   '
               '  abap.Oref.Class.invoke( "m1" );  }'
               into SOURCE.

  JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = SOURCE ).

  write / C1=>A1.

In this example, JavaScript changes the attribute C1=>A1 from 'Hello' to 'Hello World!'. The program adds ‘World’ to the attribute value by accessing the static attribute 'Oref.Class.a1'. It adds ‘!’ by calling the method C1=>M1 using 'Oref.Class.invoke'.

Leaving content frame