03-29-2016 1:51 PM
Hi,
I am trying to convert data of internal table into XML, using below code
TYPES : BEGIN OF tp_vbap,
vbeln TYPE vbap-vbeln,
posnr TYPE vbap-posnr,
matnt TYPE vbap-matnr,
END OF tp_vbap.
DATA : tl_vbap TYPE STANDARD TABLE OF tp_vbap.
DATA : l_object TYPE REF TO cl_xml_document.
SELECT vbeln posnr matnr FROM vbap INTO TABLE tl_vbap UP TO 100 ROWS.
CREATE OBJECT l_object.
l_object->create_with_data( dataobject = tl_vbap ).
l_object->export_to_file( filename = l_pathtext ).
But in XML file all fields i get are in CAPITAL, like VBELN andd POSNR.I want it to be case sensitive.
How to do that?
Thanks.
03-29-2016 2:11 PM
Hi Bhavika,
You can use XSLT Transformation.
Pl follow this document.
By this procedure you have to
1. Create structure in SE11 same as your required structure.
2. Create XSLT Transformation.
3. Pass data from Internal Table to Transformation.
4. Capture output in String.
5. Download data using GUI_DOWNLOAD FM.
It will give you case sensitive XML tags in output.
Regards,
Saurabh
03-29-2016 2:11 PM
Hi Bhavika,
You can use XSLT Transformation.
Pl follow this document.
By this procedure you have to
1. Create structure in SE11 same as your required structure.
2. Create XSLT Transformation.
3. Pass data from Internal Table to Transformation.
4. Capture output in String.
5. Download data using GUI_DOWNLOAD FM.
It will give you case sensitive XML tags in output.
Regards,
Saurabh
03-29-2016 2:24 PM
Thanks saurabh,
But isnt there any way of doing it by using class that i have used in code above?
03-29-2016 2:37 PM
If you look through standard coding,
XML conversion is handled by Kernel Method.
i.e. We dont have any way to bypass/copy/enhance that code.
With my limited knowledge, I think it may not be possible to work this out with class.
03-29-2016 2:42 PM
03-29-2016 2:51 PM
You are welcome .
Pl note that XSLT will also give you output in all caps.
You have to change transformation source code manually. (it is quite easy)
By replacing caps to small you will get desired output.
03-30-2016 7:27 AM
Hi Saurabh,
One morre thing, the user should be able to give name and path of XML file, so is the above method flexible to run that functionality even?
I am using call METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG, which gives popup to allow user for saving the XML file.
How do i do it in above method?
03-30-2016 9:33 AM
Hi,
You can use any operations.
file path to FNAME.
output data to XTAB.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = FNAME
REPLACEMENT = ' '
TABLES
DATA_TAB = XTAB[]
.
03-29-2016 2:22 PM
I think the fieldnames are upper case in SAP thats why you get them like that in your xml.
If you need them lower case you will have to build up your xml with the classes/interfaces: if_ixml , if_ixml_document and if_ixml_element.
,
03-29-2016 2:30 PM
03-29-2016 3:05 PM
DATA: l_ixml TYPE REF TO if_ixml.
DATA: lv_document TYPE REF TO if_ixml_document.
DATA: lv_element_root TYPE REF TO if_ixml_element.
DATA: lv_element_sub TYPE REF TO if_ixml_element.
DATA: lv_element_sub2 TYPE REF TO if_ixml_element.
DATA: l_streamfactory TYPE REF TO if_ixml_stream_factory.
DATA: l_renderer TYPE REF TO if_ixml_renderer.
DATA: l_ostream TYPE REF TO if_ixml_ostream.
DATA l_rc TYPE i.
DATA gv_xml_string TYPE string.
DATA l_value TYPE string.
* create an xml document
l_ixml = cl_ixml=>create( ).
lv_document = l_ixml->create_document( ).
* Create root element
lv_element_root = lv_document->create_simple_element(
name = 'SampleXML'
parent = lv_document ).
*set attributes (in this case two namespaces
lv_element_root->set_attribute(
name = 'xmlns'
value = 'yournamespace.com'
).
lv_element_root->set_attribute(
name = 'xmlns:tn4'
value = 'anothernamespace.com'
).
* first tag has no value.
lv_element_sub = lv_document->create_simple_element(
name = 'FirstTag'
parent = lv_element_root ).
l_value = 'ValueSecondTag'.
lv_element_sub2 = lv_document->create_simple_element(
name = 'SecondTag'
value = l_value
parent = lv_element_sub ).
l_value = 'ValueLastTag'.
lv_element_sub = lv_document->create_simple_element(
name = 'LastTag'
value = l_value
parent = lv_element_root ).
* now render the xml into a string object
l_streamfactory = l_ixml->create_stream_factory( ).
l_ostream = l_streamfactory->create_ostream_cstring(
string = gv_xml_string ).
l_renderer = l_ixml->create_renderer( ostream = l_ostream
document = lv_document ).
l_rc = l_renderer->render( ).
Now your xml is in gv_xml_string.:
03-29-2016 3:13 PM
04-29-2016 8:19 AM
I have copied your program as is , but i am not able to see XML file or in output.How do i see XML output, like you are showing one.
04-29-2016 2:38 PM
I made the screenshot in debugger. In there you have an option to show xml. Doubleclick on gv_xml_string while in debug and check the xml view.
Or add code to download the file (gv_xml_string)
04-29-2016 7:07 PM
Hi peter,
Thanks for quick reply.I have one more doubt.Need your help
When i am trying to provide string as
''http://w.w3.org/2001/XMLScance" version="3.1" xsi:noNamespaceSch'.
when i pass this string in values, the XML file is created, but it is blan.
I think it is because of '/', so how to do it.
05-03-2016 2:01 PM
Sorry, but I only see your post now.
Can you post the sourcecode where you are adding this ?
I do not think '/' is the problem. But are you using the right quotes (single) ?
and shouldn't it be
xsi:noNamespaceSchemaLocation="http://place_where_your_xsd_is_located" ?
Because your string doesn't make real sense.
05-06-2016 7:12 AM
Thanks Peter,
I have solved the issue, and i realized it was not because of '/'.