Hi experts,
I try to save my WebDynpro context in XML structure to DBase, to restore it at a later time ... (should be kind of storing a draft of a form) ...
The SAVE_TOXML is quite easy because of the TO_XML() method, but I struggle with the reverse binding. Here we go:
First the SAVE_TOXML, which works like it should:
method save_toxml . ********************************************************************** * Saves Context Root to XML String in Database ********************************************************************** data lv_data_string type string. lv_data_string = wd_context->to_xml( ). data ls_save type zkdp_gaxmldrafts. ls_save-mandt = sy-mandt. ls_save-atluser = sy-uname. concatenate sy-datlo sy-timlo into ls_save-timestamp. * just for testing purposes with static ID ls_save-gaid = '0000000001'. ls_save-xmlstring = lv_data_string. insert into zkdp_gaxmldrafts values ls_save. endmethod.
The stored XMLSTRING is like
<context>
<node1><attr1>12345</attr1><attr2>test</attr2></node1>
<node2>...</node2>
...
</context> which is ok.
And now how to get it back is not so easy?
I found the hint to use:
cl_wdr_xml_convert_util=>if_wd_client_conversion_util~string_to_struct
and to bind the sturcture back, but I struggle while using this functions ...
But how can I reference (assign) the table to bind to the wd_context?
Here we go:
method load_fromxml .
**********************************************************************
* Load GA Data from DBase
**********************************************************************
data lv_data_string type string.
data lv_typedescr type ref to cl_abap_typedescr.
field-symbols:
<fs_data> type data.
* just for testing purposes with static ID
select single xmlstring from zkdp_gaxmldrafts into lv_data_string
where atluser = sy-uname
and gaid = '0000000001'.
* get typedefinition of context table
* needed for conversion
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
.
if sy-subrc <> 0.
* Do error handling later
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
** How to Assign context table ?*
*ASSIGN ? to <fs_data>.*
* try conversion
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 .
endtry.
wd_context->bind_table(
new_items = <fs_data>
set_initial_elements = abap_true
).
endmethod.
Thanks for any advice ...
Best regards
Volker