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

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

The components of the structure form the properties of the proxy object, whereby the ABAP name is passed in lower case. Substructures are mapped as separate proxy objects.

In JavaScript, you can only access each component of the bound ABAP structure and its substructures separately, not as a whole. The corresponding statements do not affect bound ABAP data objects themselves, but rather the proxy object in JavaScript. Moreover, you cannot add other properties or methods to the proxy object in JavaScript.

Example

report DEMO_JAVA_SCRIPT_BIND_STRUCT.

data: begin of ADDRESS,
        FIRST_NAME type STRING,
        SECOND_NAME type STRING,
        begin of STREET,
          NAME      type STRING,
          NUMBER(4) type C,
        end of STREET,
        begin of CITY,
          ZIPCODE(5) type N,
          NAME       type STRING,
        end of CITY,
      end of ADDRESS.

data SOURCE type STRING.

data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.
JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).

JS_PROCESSOR->BIND( exporting NAME_OBJ  = 'abap'
                              NAME_PROP = 'Adr'
                    changing  DATA      = ADDRESS ).

concatenate 'abap.Adr.first_name=   "Han";       '
            'abap.Adr.second_name=  "Solo";      '
            'abap.Adr.street.name=  "Woodway";   '
            'abap.Adr.street.number="666";       '
            'abap.Adr.city.zipcode= "64283";     '
            'abap.Adr.city.name=    "Horse Town";'
  into SOURCE separated by CL_ABAP_CHAR_UTILITIES=>CR_LF.

JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = SOURCE ).

write: / ADDRESS-FIRST_NAME,   ADDRESS-SECOND_NAME,
       / ADDRESS-STREET-NAME,  ADDRESS-STREET-NUMBER,
       / ADDRESS-CITY-ZIPCODE, ADDRESS-CITY-NAME.

SOURCE = 'abap.Adr = "Hello World!";'.

JS_PROCESSOR->EVALUATE( JAVA_SCRIPT = SOURCE ).

write JS_PROCESSOR->LAST_ERROR_MESSAGE.

In this example, the program allows the JavaScript to access the ABAP structure ADDRESS using the name 'abap.Adr' and assign values to its components. After the EVALUATE method is called for the first time, the structure in the ABAP program has the values set in JavaScript.

Executing EVALUATE for a second time leads to an error, since you cannot make assignments to complex attributes.

 

 

Leaving content frame