How to Create Initial XML Element from ABAP Proxy

Posted on Apr. 14, 2010 at 11.03 AM - Kuala Lumpur, Malaysia

Have you wonder why there is CONTROLLER field for each proxy structure?

Among others, it is used to determine whether we want to use SAP standard proxy handling mechanism, or use our own one. And with it, we can 'force' XML element to be created even if the proxy field value is initial. Below is the step by step to achieve it.

1. Instantiate your proxy class.

* instantiate the proxy class

TRY.

CREATE OBJECT lo_proxy.

...

ENDTRY.

2. Instantiate protocol class.

* Get Protocol Class Using Method GET_PROTOCOL

DATA: lo_payload_protocol TYPE REF TO if_wsprotocol_payload.

lo_payload_protocol ?= lo_proxy->get_protocol( if_wsprotocol=>payload ).

3. Set the extended XML handling

* over ride standard SAP proxy handling

lo_payload_protocol->set_extended_xml_handling( extended_xml_handling = 'X' ).

4. Populate values into respective field CONTROLLER. Set field FIELD with field name, and field VALUE with sai_ctrl_initial from ABAP type pool SAI.

Notes:

1. Make sure you only populate the field CONTROLLER whenever the field does NOT have value, otherwise your value will be overwritten with initial value.

2. Excerpt is the help file from SAP :

The ABAP proxy generation functions generate control tables of type PRXCTRLTAB (line type PRXCTRL) for each complex type. This component has the name CONTROLLER. Using this table you can define for each individual field whether it is to occur in the message, and how. For a table line, set the field FIELD to the ABAP field name, the field VALUE to a value from the type pool sai, and attach the line to the table. The fieldVALUE can have the following values:

Value Range for Field VALUE of Table CONTROLLER (SENDER side)

On the receiver side as well, the control table is generated in the same way as every other structure. In this case, the proxy runtime completes the control table during parsing with values that the application can then evaluate.

Possible Values for the VALUE Field of the CONTROLLER (RECEIVER side)

Life is beautiful! Let's make it meaningful and colorful!