cancel
Showing results for 
Search instead for 
Did you mean: 

How to map XML to Web Dynpro context nodes?

Former Member
0 Kudos

Hi All,

Could anyone tell how xml string can be bound to context nodes ? In my requirement i need to serialize context nodes value to string and deserialize it back to nodes for implementing back naviagtion between views.

I didnt see much threads achieving this giving details on class cl_wdr_xml_convert_util and methods if_wd_client_conversion_util~string_to_struct.

I am using wd_context->to_xml to convert into xml.

From this format, i want to bind it back to context node.

When i use this below approch i get short dumb.

Serialization to xml:

lv_data_string = wd_context->to_xml( ).

Deserialization:

DATA lv_typedescr TYPE REF TO cl_abap_typedescr.

FIELD-SYMBOLS:

<fs_data> TYPE ANY TABLE.

CALL METHOD cl_abap_typedescr=>describe_by_object_ref

EXPORTING

p_object_ref = wd_context

RECEIVING

p_descr_ref = lv_typedescr

EXCEPTIONS

reference_is_initial = 1

OTHERS = 2.

try.

CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct

EXPORTING

in = lv_data_string

typedescr = lv_typedescr

IMPORTING

data = <fs_data>

.

CATCH cx_wdr_conversion_exception into lo_err .

lv_exp = lo_err->get_text( ).

ENDTRY.

wd_context->bind_table( values = <fs-data>.

Using this way, i get a short dumb as assert statement is failed as value for typedescr->type_kind is '*'.

method if_wd_client_conversion_util~string_to_struct.

assert typedescr->type_kind = cl_abap_typedescr=>typekind_struct1

or typedescr->type_kind = cl_abap_typedescr=>typekind_struct2.

raise exception type cx_wdr_conversion_exception

exporting textid = cx_wdr_conversion_exception=>illegal_type.

On debugging changing this value to required also made no difference, as no value could be assigned to the field symbol.

Suggest a soution to do this.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>Using this way, i get a short dumb as assert statement is failed as value for typedescr->type_kind is '*'.

The problem is you are building an RTTI of an object reference. This isn't what this method needs.

CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct

This method converts an XML string back into a ABAP data structure. It needs an RTTI of the structure not the WD_CONTEXT object.

So instead of this:

CALL METHOD cl_abap_typedescr=>describe_by_object_ref
EXPORTING
p_object_ref = wd_context

You need need to create a type descriptor object for the actual structure bound to the context node.

Answers (2)

Answers (2)

Former Member
0 Kudos

HI Thomas,

Thanks for your response.

Could you sample the code on what i should do.

Based on your changes, i have changed the following below:

CALL METHOD cl_abap_typedescr=>describe_by_data ( before it was describe_by_object_ref)

EXPORTING

p_data = lo_nd_bp

receiving

p_descr_ref = lv_typedescr

CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct

EXPORTING

in = lv_data_string

typedescr = lv_typedescr

IMPORTING

data = go_ref "<fs_data>

.

CATCH cx_wdr_conversion_exception into lo_err .

lv_exp = lo_err->get_text( ).

ENDTRY.

assign go_ref->* to <fs_data>.

wd_context->bind_table(

new_items = <fs_data>

set_initial_elements = abap_true

).

I stll get the dumb.

Thank you for the inputs.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You switched to describe_by_data, but you aren't giving it a data object. You are giving it the object reference to your node. You need to give the typedescr class a data object that matches the structure you used to define your node. Your coding is right by the object you are passing into the method isn't.

Former Member
0 Kudos

Hi Thomas,

Thanks for your replies.

I have corrected it, but the field symbol is empty and while debugging it says data type is incorrect.

code:

FIELD-SYMBOLS:

<fs_data> TYPE ANY TABLE.

data: lsbp type ZXBPCENTRAL,

go_ref type ref to data.

CALL METHOD cl_abap_typedescr=>describe_by_data " ( before it was describe_by_object_ref)

EXPORTING

p_data = lsbp

receiving

p_descr_ref = lv_typedescr.

try.

CALL METHOD cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct

EXPORTING

in = lv_data_string

typedescr = lv_typedescr

IMPORTING

data = go_ref "<fs_data>

.

CATCH cx_wdr_conversion_exception into lo_err .

lv_exp = lo_err->get_text( ).------> Here the error says " Invalid data type and hence, there is no data.

ENDTRY.

assign go_ref->* to <fs_data>.

I am still looking for solution and thanks a lot ....

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

go_ref is an initial type ref to data. You need to create a data object that has the structure you want to restore into and then get reference to this data object in GO_REF. You can't just pass in an empty reference.

Former Member
0 Kudos

hi Thomas,

Indeed i am really confused what to do.

could you please sample a code for me? It will be a great help from u.

thanks..

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> hi Thomas,

>

> Indeed i am really confused what to do.

> could you please sample a code for me? It will be a great help from u.

>

> thanks..

Your code is basically correct. You just need to fill the data reference before calling the string_to_struct method.

Something like:

get reference of lsbp into go_ref.

Former Member
0 Kudos

Hi Thomas,

But go_ref is a importing parameter from the method rt ?

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Then I guess your type descriptor object isn't right. I can't really tell you more from just this description. You might have to debug into the SAP method call to see why and where it is throwing the exception.

Former Member
0 Kudos

Hi,

Please go through this...

Cheers,

Kris.

Former Member
0 Kudos

Thanks for your immediate response.

Unfortunately, these links does not tell how to map xml back to the view context node.

anyone please help me with this?

cheers..