Entering content frameThis graphic is explained in the accompanying text Binding to Data References Locate the document in its SAP Library structure

An ABAP data reference is mapped in JavaScript as a proxy object of the predefined proxy class SAPAbapDrefClass. You can specify a – case-sensitive – name for the JavaScript reference using the NAME_PROP parameter of the BIND method.

Unless the ABAP data reference is initial (that is, provided it points to a data reference) the proxy object has exactly one property, ‘data’, which you can use to access the referenced ABAP data object (dereferencing). Assignments to the component ‘data’ change the content of the referenced data object in ABAP. If the ABAP data reference is assigned the type of a structured ABAP data type, the property ‘data’ contains the corresponding sub-properties with the names of the ABAP components in lower case. If the ABAP data reference is blank, there is no ‘data’ property.

The proxy object has a method, ‘notInitial’, with no input parameters, that returns a Boolean value. The return value is true if the ABAP data reference points to a data object, and false if the ABAP data reference is blank.

You cannot add other properties or methods to the proxy object in JavaScript. If you try to assign objects to bound data references in JavaScript, it terminates.

Example

report DEMO_JAVA_SCRIPT_BIND_DREF.

types: begin of T_STRUCT,
         TEXT type STRING,
      end of T_STRUCT.

data DREF type ref to T_STRUCT.
data STRUCT type T_STRUCT.

data SOURCE type STRING.

data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.

STRUCT-TEXT = 'Hello'.
get reference of STRUCT into DREF.

JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

JS_PROCESSOR->BIND( exporting NAME_OBJ  = 'abap'
                              NAME_PROP = 'Dref'
                    changing  DATA      = DREF ).

concatenate  'if ( abap.Dref.notInitial() )        '
             '{ abap.Dref.data.text += " World!"; }'
             INTO source.

JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = SOURCE ).

write STRUCT-TEXT.

This example shows how you can access a component of a structured data reference in JavaScript. The ‘notInitial’ method checks whether or not the data reference points to a data object.

 

 

Leaving content frame