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

Function

Passes a reference to an ABAP data object to a JavaScript context. This enables JavaScript programs to work directly with these data objects.

While ABAP is based on specific data types, JavaScript uses "loose typing", where fields do not have unique data types and are interpreted according to content and context. Thus, the many different types in the ABAP type hierarchy are mapped to JavaScript types and objects as follows:

The elementary ABAP types can be mapped to elementary JavaScript types. The other complex ABAP types (structures, internal tables, and references) have to be mapped to special JavaScript objects. For each complex ABAP type that can be mapped, a separate proxy class is implemented in the JavaScript runtime environment for this purpose. When binding a complex ABAP data object to a JavaScript context, the system creates an object of the appropriate proxy class; in JavaScript, it works with a reference to the proxy object.

When binding complex ABAP data objects to a JavaScript context, bear in mind that the size of the proxy object is dynamic. If the ABAP data object is changed either in JavaScript or in ABAP during binding, the system may have to re-generate the proxy object. The BIND method simply binds a JavaScript with a specified name statically to an ABAP data object, while the proxy object lying between them can be exchanged. The latter is not visible to the user.

ABAP type

Mapping in JavaScript

I, F

Double

C, D, N, P T, X, STRING, XSTRING

String

Structures (struct)

  • Components of a structure (struct-comp)

Proxy class: SAPAbapStructClass

  • Identically-named attributes (properties) of the proxy object (proxy.comp)
    Substructures are separate proxy objects

Interne standard tables (itab)

  • Record in a table (itab[] INDEX idx)

Proxy class: SAPAbapStructClass

  • Array access to the proxy object (proxy[idx]).

Data references (dref)

  • Dereferenced data references (dref->*)
  • Components of a dereferenced data references (dref->*-comp or dref ->comp)

Proxy class: SAPAbapDrefClass

  • ‘data’ attribute (property) of the proxy object (proxy.data)
  • Identically-named attributes (properties) of the proxy object (proxy.data.comp)

Object reference variables (oref).

  • Public instance attributes of the object in ABAP Objects (oref->attr)
  • Public instance methods of the object in ABAP Objects (oref->attr)

Proxy class: SAPAbapOrefClass

  • Identically-named attributes (properties) of the proxy object (proxy.attr)
  • Invoke method of the proxy object (proxy.invoke)

Classes (class)

  • Public static attributes of the class in ABAP Objects (class=>attr)
  • Public static methods of the class in ABAP Objects (class=>attr)

Proxy class: SAPAbapCrefClass for property class of SAPAbapOrefClass

  • Identically-named attributes (properties) of the proxy object (proxy.Class.attr)
  • Invoke method of the proxy object (proxy.Class.invoke)

Other ABAP data objects are not supported at present. All combinations of the data types specified above are, however, allowed in ABAP, such as standard tables as components of structures.

Changes made to bound data objects in a JavaScript program directly change the value semantics of the ABAP data objects. However, you can only change elementary data objects or the elementary components of complex or lower data objects in this way (in other words, the elementary parts of records in tables or the attributes of objects). You cannot assign data objects to JavaScript references that point to proxy objects. For example, if you try to assign a value to the Top-Level-Binding object in JavaScript, this script terminates. Moreover, you cannot add or remove properties to a proxy object.

You can only assign bound data objects within JavaScript to other JavaScript variables if the former are elementary data objects or elementary components.

You must use reference semantics to assign a JavaScript reference pointing to an ABAP data object to another JavaScript variable. This means that the target variables in JavaScript point to the same data object in ABAP as the source variable after the assignment. Target variable binding may be lost if internal tables are reorganized or the Garbage Collector is executed in ABAP. If the content of an ABAP object of this sort is changed in memory, a new proxy object is generated in JavaScript. While the source variable is automatically bound to the new proxy object, the target variable still points to the previous proxy object. If you try to access the target variable, the JavaScript generally stops processing, or an ABAP runtime error occurs.

Note

The JavaScript target variable (and the proxy object to which it points) represents a snapshot of the state of the ABAP object during assignment. If you working alternately with JavaScript and ABAP, you should not continue to work with this snapshot after exiting ABAP.

At present, you can remove a binding set using BIND only by deleting the associated JavaScript context, using the ABAP_DESTRUCTOR method.

Importing Parameters

NAME_OBJ (type STRING)

Name of a JavaScript object to which up to 256 ABAP data objects can be bound as properties (Top-Level-Binding). You can create any number of top-level bindings you want in a context. If you pass an empty string, the ABAP data object is bound to a property of the root object (a global variable, for example) of the context. (This is known as Root-Level-Binding and is 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. For complex ABAP data objects, these are references to the object of the associated proxy object.

Changing parameter

DATA (type ANY)

Name of the ABAP data object.

Details and Examples

Binding to the ABAP Types I and F

Binding to the ABAP Type P

Binding to ABAP Structures

Binding to Internal Tables

Binding to Data References

Binding to Object References (Instances)

Binding to Static Class Components

 

 

Leaving content frame