Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Converting the SAP Data into XML Format

Former Member
0 Likes
2,348

Hi All,

I am working on the Interface. In that I need to send the SAP data into XML format using the RFC. I know there is standard function modules available to convert SAP data into XML data. But I am not sure If the data in the below mentioned format will support the standard ones are not.

The format looks likes this.

<Header>

<FIELD1> F1 </FIELD1>

<FIELD2> F2 <FIELD2>

<ITEM>

<FIELD3>F3</FIELD3>

<CONTENT>

<FIELD4>F4</FIELD4>

</CONTENT>

</ITEM>

</HEADER>

I have a header data and line item data and again in line items I have multiple content data. I need to display this data like Header data once and line item with multiple contents etc...

Can Anybody help me to resolve this issue.

I am planning to convert the XML data for the above mentioned format manually if standard ones are not going to support the above mentioned format.

All suggestions are welcome.

Thanks in advance for the valuble replies.

Thanks,

Antony.

7 REPLIES 7
Read only

madhu_vadlamani
Active Contributor
0 Likes
1,876

Hi Antony,

[Sales Order|;

I think there is no need worry about the format. Suppose for a sales order there is a header and some line items. Check that example then your issue will be resolved.

Regards,

Madhu.

Read only

0 Likes
1,876

Hi Madhu,

Thanks for the reply...But its not related to sales order.. Its RFC in which i need to send specific data in above format to legacy system.Please let me know if you have any idea on that I tried standard function modules but those are not supporting as I have header and line item data.

Thanks,

Antony

Read only

0 Likes
1,876

At least three ways

1) create a string with appropriate format concatenating all tags and field values to it, then download it to XML file

2) using [simple transformation|http://help.sap.com/saphelp_nw04s/helpdata/en/e3/7d4719ca581441b6841f1054ff1326/frameset.htm]


<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
 
<tt:root name="head"/>
<tt:root name="item" />
<tt:root name="content_tab" />
    
<tt:template>  
  <HEADER>
     <tt:ref name="head">
       <FIELD1> <tt:value ref="field1"></FIELD1>
       <FIELD2> <tt:value ref="field2"><FIELD2>
     </tt:ref>
     <tt:ref name="item">
         <FIELD3><tt:value ref="field3"></FIELD3>
     </tt:ref>
     <tt:loop ref="content_tab">
       <CONTENT>   
          <FIELD4><tt:value ref="field4"></FIELD4>
       </CONTENT>
     </tt:loop>
  </HEADER>

   "now calling program
  DATA: BEGIN OF gs_header,
              field1, 
              field2,
            END OF gs_header.
 data: begin of gs_item,
             field3,
         end of gs_item.

data: begin of gt_content occurs 0,
             field4,
         end of gt_content.

data xml_str type string.
 
CALL TRANSFORMATION zsimple_trans
  SOURCE head = gs_header
                 item = gs_item
                 content_tab = gt_content
  RESULT XML xml_str.

"now dowload XML_STR

3) using [DOM|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/bb/576637dca511d4990b00508b6b8b11/frameset.htm]


"sample program
DATA: gr_ixml TYPE REF TO if_ixml,
      gr_ixml_doc TYPE REF TO if_ixml_document.

gr_ixml = cl_ixml=>create( ).
gr_ixml_doc = gr_ixml->create_document( ).

DATA  gr_ixml_element TYPE REF TO if_ixml_element.

CALL METHOD gr_ixml_doc->create_element
  EXPORTING
    name = 'JOBS'
  RECEIVING
    rval = gr_ixml_element.

CALL METHOD gr_ixml_doc->append_child
  EXPORTING
    new_child = gr_ixml_element.

CALL METHOD gr_ixml_element->set_attribute
  EXPORTING
    name  = 'OBJID'
    value = '566677890'.

"serialization
DATA g_encoding_type TYPE string.
DATA g_stream_factory TYPE REF TO if_ixml_stream_factory.
DATA gr_encoding TYPE REF TO if_ixml_encoding.

g_stream_factory = gr_ixml->create_stream_factory( ).
gr_encoding = gr_ixml->create_encoding( byte_order = 0
                                       character_set = 'UTF-8' ).

DATA b_xml TYPE xstring.
DATA gr_ostream TYPE REF TO if_ixml_ostream.
gr_ostream = g_stream_factory->create_ostream_xstring( b_xml ).

CALL METHOD gr_ostream->set_encoding
  EXPORTING
    encoding = gr_encoding.

CALL METHOD gr_ixml_doc->render
  EXPORTING
    ostream = gr_ostream
    recursive = 'X'.

DATA g_resize TYPE i.
g_resize = gr_ostream->get_num_written_raw( ).

data ex_tab type table of x255.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer                = b_xml
  tables
    binary_tab            = ex_tab.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    BIN_FILESIZE                    = g_resize
    filename                        = 'C:\doc.xml'
    FILETYPE                        = 'BIN'
  tables
    data_tab                        = ex_tab.

Regards

Marcin

Read only

0 Likes
1,876

Hi Marcin Pciak,

The URL http://help.sap.com/saphelp_nw04s/helpdata/en/e3/7d4719ca581441b6841f1054 is not available.

can you please explain how to create Z transformation?

The requirement am working on is to pull the BOM master with item from SAP and pass the data in XML format for the third party SW. Please help me out in this.

The below attached is the required XML format for my interface.

- <BILLOFMATERIAL>
- <BOMHEAD>
<TRANNO></TRANNO>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<LEVEL></LEVEL>
</BOMHEAD>
- <ITEMDETAIL>
- <BOMDET1>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<COMPSCRPPER></COMPSCRPPER>
<LEVEL></LEVEL>
</BOMDET1>
- <BOMDET2>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<COMPSCRPPER></COMPSCRPPER>
<LEVEL></LEVEL>
</BOMDET2>
- <BOMDET3>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<COMPSCRPPER></COMPSCRPPER>
<LEVEL></LEVEL>
</BOMDET3>
</ITEMDETAIL>
</BOMHEAD>
</BILLOFMATERIAL>
Read only

0 Likes
1,876

Hello,

Where is exactly the problem lying? Please follow the DOM approach link and you will understand how to build such XML easily.

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/bb/576637dca511d4990b00508b6b8b11/frameset.htm

In case you need and example please check demo program T_DOM_MANIPULATE.

Regards

Marcin Pciak

Read only

Former Member
0 Likes
1,876

Thanks for the replys. My Issue has been based on above responses

Read only

0 Likes
1,876

Hi Former Member,

Can you please share your knowledge on the above issue?

The requirement, am working on is to pull the BOM master with item from SAP and pass the data in XML format for the third party SW. Please help me out in this.

The below attached is the required XML format for my interface.

- <BILLOFMATERIAL>
- <BOMHEAD>
<TRANNO></TRANNO>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<LEVEL></LEVEL>
</BOMHEAD>
- <ITEMDETAIL>
- <BOMDET1>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<COMPSCRPPER></COMPSCRPPER>
<LEVEL></LEVEL>
</BOMDET1>
- <BOMDET2>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<COMPSCRPPER></COMPSCRPPER>
<LEVEL></LEVEL>
</BOMDET2>
- <BOMDET3>
<ITEMCODE></ITEMCODE>
<QUANTITY></QUANTITY>
<UOM></UOM>
<COMPSCRPPER></COMPSCRPPER>
<LEVEL></LEVEL>
</BOMDET3>
</ITEMDETAIL>
</BOMHEAD>
</BILLOFMATERIAL>