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

Function

Variant of the BIND method, which allows exclusively ABAP Objects to be bound. In contrast to BIND, the instance is bound as opposed to the reference. Bound ABAP Objects enable JavaScript the same access to the public instance attributes of the objects and to call up public instance methods as described in Link to Instances (Attributes and Methods). These do not provide access to static components.

Importing Parameter

NAME_OBJ (Type STRING)

Name of a JavaScript object to which up to 256 ABAP Objects can be bound as properties ( Top-Level Binding). Any number of top-level bindings can be created in a context. If an empty string is transferred, the ABAP Object is bound to a property of the root object (a global variable, for example) of the context ( Root-Level Binding, not recommended).

NAME_PROP (Type STRING)

Name of the property of the top-level binding object or of the root object under which the ABAP data object is accessed in the JavaScript context.

Changing Parameter

OBJECT_REF (Type REF TO OBJECT)

Name of a reference variable that must point to an instance in ABAP Objects when binding is performed.

Example

Example

report DEMO_JAVA_SCRIPT_BIND_INSTANCE.

class C1 definition.
  public section.
    data ATTR type STRING.
    methods CONSTRUCTOR.
endclass.

class C1 implementation.
  method CONSTRUCTOR.
    ATTR = 'Hello '.
  endmethod.
endclass.

data OREF type ref to C1.

data SOURCE type STRING.
data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.

data RETURN_VALUE type STRING.

start-of-selection.

  JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

  create object OREF.

  JS_PROCESSOR->BIND_INSTANCE( exporting NAME_OBJ   = 'abap'
                                        NAME_PROP  = 'Ref'
                               changing OBJECT_REF = OREF ).

  if JS_PROCESSOR->LAST_CONDITION_CODE
                      <> CL_JAVA_SCRIPT=>CC_OK.
   message 'Binding Error' type 'E'.
  endif.

  SOURCE = 'abap.Ref.attr += " World!";'.

  RETURN_VALUE =
    JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = SOURCE ).
  write RETURN_VALUE.

In this example, JavaScript extends the OREF->ATTR attribute from 'Hello' to 'Hello World!'. Calling the BIND_INSTANCE method without the previous statement CREATE OBJECT would cause a termination of JavaScript processing.

 

 

Leaving content frame