06-05-2008 3:15 PM
Hi,
I want to display My outbound file in XML format.
hoe to represent starting and ending nodes in XML format.
for ex.
I want XML file in this format.
<idoctype>
<segname>
<field1>value</field1>
<field2<value</field2>
</segname>
</idoctype>
fields I can convert into xml format.But i don't know how to convert nodes.
Can any one give me the idea?
Thanks in advance.
06-05-2008 3:23 PM
Hi,
maybe cl_idoc_xml1 is helpful for you.
*[...]
CREATE OBJECT gx_xml_idoc
EXPORTING
docnum = pa_docno
EXCEPTIONS
error_loading_idoc = 1
error_building_xml = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL METHOD gx_xml_idoc->get_xmldata_as_xstring
IMPORTING
data_string = gv_xml_xstring.
*[...]
There is also a XML editor available:
*[...]
CALL METHOD cl_gui_xml_editor=>create
EXPORTING
im_container = gx_dock_cont
im_xml = gv_xml_xstring
IMPORTING
* ex_data = gx_xml_data
* ex_schema = gx_xml_schema
ex_editor = gx_xml_editor.
gx_xml_editor_prop = gx_xml_editor->get_properties( ).
CALL METHOD gx_xml_editor_prop->set_attributes
EXPORTING
im_readonly = 1.
*[...]
Hope this is helpful.
Regards Rudi
06-06-2008 8:09 AM
Hi,
I have not understood above code.Can any one give me idea.
thanks in advance
06-06-2008 3:37 PM
Hello,
I assumed that you want to convert IDoc data into XML, cause you posted
<idoctype> <segname> <field1>value</field1> <field2<value</field2> </segname> </idoctype>
The class mentioned above convertd IDoc data into XML by passing the IDoc number. All what you have to do, is to create an instance of the class by passing the IDoc number. After successful creation of the object you can the XML data by several methods in different forms:
IDoc in XML Format in
Table of Type X -> GET_XMLDATA_AS_XTABLE
Table of Type C -> GET_XMLDATA_AS_TABLE
String of Type X -> GET_XMLDATA_AS_XSTRING
String of Type C -> GET_XMLDATA_AS_STRING
I think, when you use this class then you don't have to worry about nodes or something else. I am not sure from which SAP release this class is available.
With the mentioned XML editor you can build a quick XML IDoc converter:
DATA:
gv_repid TYPE syrepid,
gv_dynnr TYPE sydynnr,
gv_xml_xstring TYPE xstring,
gt_exclude TYPE TABLE OF rsexfcode,
gs_exclude TYPE rsexfcode,
gx_dock_cont TYPE REF TO cl_gui_docking_container,
gx_xml_idoc TYPE REF TO cl_idoc_xml1,
gx_xml_editor TYPE REF TO cl_gui_xml_editor,
gx_xml_editor_prop TYPE REF TO cl_gui_xml_properties.
PARAMETERS:
pa_docno TYPE edi_docnum MATCHCODE OBJECT edi_docnum .
AT SELECTION-SCREEN OUTPUT.
CHECK NOT pa_docno IS INITIAL.
gv_repid = sy-repid.
gv_dynnr = sy-dynnr.
IF NOT gx_dock_cont IS INITIAL.
CALL METHOD gx_xml_editor->reset_editor.
FREE gx_xml_editor_prop.
FREE gx_xml_editor.
gx_dock_cont->free( ).
FREE gx_dock_cont.
ENDIF.
CREATE OBJECT gx_dock_cont
EXPORTING
repid = gv_repid
dynnr = gv_dynnr
side = cl_gui_docking_container=>dock_at_bottom
name = 'DOCKING'
ratio = 95
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF NOT gx_xml_idoc IS INITIAL.
FREE gx_xml_idoc.
CLEAR gv_xml_xstring.
ENDIF.
CREATE OBJECT gx_xml_idoc
EXPORTING
docnum = pa_docno
EXCEPTIONS
error_loading_idoc = 1
error_building_xml = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL METHOD gx_xml_idoc->get_xmldata_as_xstring
IMPORTING
data_string = gv_xml_xstring.
CALL METHOD cl_gui_xml_editor=>create
EXPORTING
im_container = gx_dock_cont
im_xml = gv_xml_xstring
IMPORTING
ex_editor = gx_xml_editor.
gx_xml_editor_prop = gx_xml_editor->get_properties( ).
CALL METHOD gx_xml_editor_prop->set_attributes
EXPORTING
im_readonly = 1.
Hope that this is helpful.
Regards Rudi