‎2006 Dec 11 10:56 PM
Hi friends
I am writing an interface program to generate an XML file.
I need to extract data from SAP system and generate the XML file as below.
I have gone through many threads but i didnt find one which can give the attributes in the XML file. If i found also i didnt find one which has header with two or more details and also they are generating few characters like <ts:.....xmlns etc>
can anyone post an example which gives the below format.
Thanks in advance
Satya
<?xml version="1.0"?>
<ts:TransactionSet xmlns:ts="http://schemas.abc.com/IS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xtc="http://schemas/abc/xt/core"
xmlns:xtd="http://schemas/abc/xt/datatypes" xmlns:dts="http://schemas/abc/xt/database" msgid="95efb764-db05-4b9f-a32a-e91e5f5c26ce">
<TransactionSetProperties null_representation="implicit" transaction_scope="entity">
<DateTimeFormats dateTimeFormat="2006-11-21 17:25:35"/>
<Source>SAP</Source>
<Message_Version>1.0.0</Message_Version>
<COM_Version>1.0.0</COM_Version>
<Application_Version>4.0.1 Build 1060</Application_Version>
</TransactionSetProperties>
<xt:Sample_Transaction xmlns:xt="http://schemas.abc.com/IS/1.0.0/Sample_Transaction" operation="INSERT" objectId="1886" type_name="Sample_Transaction">
<Sample_Transaction_ID>800000000000359</Sample_Transaction_ID>
<Transaction_Date>2005-02-05 09:39:54</Transaction_Date>
<Sample_Document_Value>7654</Sample_Document_Value>
<Employee_ID>96</Employee_ID>
<Sample_Transaction_Detail_List type_name="Sample_Transaction_Detail_List">
<Sample_Transaction_Detail operation="INSERT" objectId="1887" type_name="Sample_Transaction_Detail">
<Sample_Transaction_Detail_ID>800000000000360</Sample_Transaction_Detail_ID>
<Unit_Quantity>42</Unit_Quantity>
<Lot_Number>02</Lot_Number>
<Product_ID>168</Product_ID>
<Comment>Comment for Product 168 lot 02</Comment>
</Sample_Transaction_Detail>
</Sample_Transaction_Detail_List>
<Sample_Transaction_Detail operation="INSERT" objectId="1887" type_name="Sample_Transaction_Detail">
<Sample_Transaction_Detail_ID>800000000000361</Sample_Transaction_Detail_ID>
<Unit_Quantity>43</Unit_Quantity>
<Lot_Number>03</Lot_Number>
<Product_ID>169</Product_ID>
<Comment>Comment for Product 168 lot 02</Comment>
</Sample_Transaction_Detail>
</Sample_Transaction_Detail_List>
</xt:Sample_Transaction>
</ts:TransactionSet>
‎2006 Dec 11 10:58 PM
Check this links..
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
YOu can do it through XLST. it is supported in ABAP from 4.7. you can create a XSLT, and read you XML, then CALL TRANSFORMATION to convert a XML into ABAP data structure.
reference link:
http://help.sap.com/saphelp_nw04/helpdata/en/fd/9d7348389211d596a200a0c94260a5/frameset.htm
Raja T
Message was edited by:
Raja T
‎2006 Dec 12 1:01 AM
Hi,
Just like Raja said, yOu can do it through XLST and it is supported in ABAP from 4.7 and above.
Try below program, and it will help you.
REPORT Z_XML NO STANDARD PAGE HEADING .
*-----------------------------------------------------------------------
* D.A.T.A.
*-----------------------------------------------------------------------
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0,
a(100) TYPE c,
END OF itab.
DATA: xml_out TYPE string .
DATA : BEGIN OF upl OCCURS 0,
f(255) TYPE c,
END OF upl.
DATA: xmlupl TYPE string,
XML_FILE TYPE STRING .
*-----------------------------------------------------------------------
* S.E.L.L.E.C.T.I.O.N. .S.C.R.E.E.N.
*-----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK BLC1 WITH FRAME TITLE TEXT-S10.
PARAMETER: P_FILE TYPE TEXT80 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK BLC1.
*-----------------------------------------------------------------------
* I.N.I.T.I.A.L.I.Z.A.T.I.O.N.
*-----------------------------------------------------------------------
INITIALIZATION.
P_FILE = 'C:test.xml'.
*-----------------------------------------------------------------------
* M.A.I.N. .P.R.O.G.R.A.M.
*-----------------------------------------------------------------------
START-OF-SELECTION.
XML_FILE = P_FILE.
SELECT * FROM t001 INTO TABLE t001.
* 1 >> download to XML
* XML
CALL TRANSFORMATION ('ID')
SOURCE tab = t001[]
RESULT XML xml_out.
* Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = xml_out
i_tabline_length = 100
TABLES
et_table = itab.
* Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'BIN'
filename = XML_FILE
TABLES
data_tab = itab.
* Upload to Table
BREAK-POINT.
REFRESH t001.
CLEAR t001.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = XML_FILE
filetype = 'BIN'
TABLES
data_tab = upl.
LOOP AT upl.
CONCATENATE xmlupl upl-f INTO xmlupl.
ENDLOOP.
* XML
CALL TRANSFORMATION ('ID')
SOURCE XML xmlupl
RESULT tab = t001[].
Regards,
‎2006 Dec 12 1:09 AM
Thanks for your help but my question is how can i get the below tags
<ts:TransactionSet xmlns:ts="http://schemas.abc.com/IS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xtc="http://schemas/abc/xt/core"
xmlns:xtd="http://schemas/abc/xt/datatypes" xmlns:dts="http://schemas/abc/xt/database" msgid="95efb764-db05-4b9f-a32a-e91e5f5c26ce">
<TransactionSetProperties null_representation="implicit" transaction_scope="entity">
<DateTimeFormats dateTimeFormat="2006-11-21 17:25:35"/>
<Source>SAP</Source>
<Message_Version>1.0.0</Message_Version>
<COM_Version>1.0.0</COM_Version>
<Application_Version>4.0.1 Build 1060</Application_Version>
</TransactionSetProperties>
‎2006 Dec 12 6:45 AM
you can use cl_xml_document class do that.
check this sample program.
report y_test_xml_complex
no standard page heading.
data: l_ixml type ref to if_ixml,
l_ixml_sf type ref to if_ixml_stream_factory,
l_istream type ref to if_ixml_istream,
l_ostream type ref to if_ixml_ostream,
l_categories_element type ref to if_ixml_element,
l_document type ref to if_ixml_document,
l_parser type ref to if_ixml_parser,
l_root_element type ref to if_ixml_element,
l_c_element type ref to if_ixml_element,
l_s_element type ref to if_ixml_element ,
title type ref to if_ixml_element ,
link type ref to if_ixml_element ,
description type ref to if_ixml_element ,
xml type xstring ,
size type i ,
l_xml type ref to cl_xml_document .
data: xml_out type string ,
temp_string type string .
data: nodes type standard table of wpmnodes ,
favos type standard table of wpmnodes .
data: fav_wa type wpmnodes .
call function 'SPR4_GET_USER_MENU'
exporting
* READ_MENU = 'X'
read_favo = 'X'
max_level = '99'
fill_has_children = 'X'
generate_url = 'X'
tables
nodes = nodes
favos = favos .
l_ixml = cl_ixml=>create( ).
l_ixml_sf = l_ixml->create_stream_factory( ).
l_document = l_ixml->create_document( ).
l_root_element = l_document->create_element( name = 'rss' ).
l_root_element->set_attribute( name = 'version' value = '1.0' ).
l_document->append_child( new_child = l_root_element ).
clear l_categories_element .
l_categories_element = l_document->create_simple_element( parent = l_root_element name = 'channel' ).
l_c_element = l_document->create_simple_element( parent = l_categories_element name = 'title' value = 'Favorite Txns' ).
loop at favos into fav_wa where node_type ne 'F' .
clear temp_string .
temp_string = fav_wa-text .
l_s_element = l_document->create_simple_element( parent = l_categories_element name = 'item' ).
title = l_document->create_simple_element( parent = l_s_element name = 'title' value = temp_string ).
link = l_document->create_simple_element( parent = l_s_element name = 'link' value = 'http://www.google.com' ).
description = l_document->create_simple_element( parent = l_s_element name = 'description' value = temp_string ).
clear fav_wa .
endloop .
l_ostream = l_ixml_sf->create_ostream_xstring( xml ).
l_document->render( ostream = l_ostream ).
create object l_xml.
call method l_xml->parse_xstring
exporting
stream = xml.
l_xml->render_2_string(
exporting
pretty_print = 'X'
importing
* RETCODE = RETCODE
stream = xml_out
size = size
).
call method l_xml->display.
Regards
Raja
‎2006 Dec 12 2:55 PM
Hi raja
i was waiting for your reply from yesterday. thanks for your reply and i will implement this code and see what happens
Thanks once again for your reply
‎2006 Dec 12 3:03 PM
Raja
how can we set many attributes for one tag like below
<ts:TransactionSet xmlns:ts="http://schemas.abc.com/IS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xtc="http://schemas/abc/xt/core"
xmlns:xtd="http://schemas/abc/xt/datatypes" xmlns:dts="http://schemas/abc/xt/database" msgid="95efb764-db05-4b9f-a32a-e91e5f5c26ce">
<TransactionSetProperties null_representation="implicit" transaction_scope="entity">
<xt:Sample_Transaction xmlns:xt="http://schemas.abc.com/IS/1.0.0/Sample_Transaction" operation="INSERT" objectId="1886" type_name="Sample_Transaction">
<Sample_Transaction_Detail operation="INSERT" objectId="1887" type_name="Sample_Transaction_Detail">
‎2006 Dec 12 4:23 PM
‎2006 Dec 12 7:54 PM
check this online help explaining all the methods of if_ixml_element interface, it details out how you can add attributes
http://help.sap.com/saphelp_nw04/helpdata/en/bb/576670dca511d4990b00508b6b8b11/content.htm
However seeing your example XML file, all elements looks to be statis content. in such a case you can simply concatenat them to create the xml.
Regards
Raja
‎2006 Dec 13 3:48 PM
‎2006 Dec 13 3:48 PM
‎2006 Dec 13 7:45 PM