2005 Mar 02 7:34 AM
Hi,
I have read this weblog
/people/patrick.baer/blog/2005/02/24/abap-serialization--part-i-quick-n-easy and tried to serialize ABAP data into XML format.
In fact, I have copied the exact code from this weblog, but somehow this file is not visible in my pc.
DATA example_data TYPE spfli.
select single * from spfli into example_data.
DATA xml_utils TYPE REF TO if_ixml.
xml_utils = cl_ixml=>create( ).
DATA xml_stream_factory TYPE REF TO if_ixml_stream_factory.
xml_stream_factory = xml_utils->create_stream_factory( ).
DATA xml_output_stream TYPE REF TO if_ixml_ostream.
xml_output_stream = xml_stream_factory->create_ostream_uri( system_id =
'file://c:test.xml' ).
try.
CALL TRANSFORMATION id
SOURCE data_node = example_data
RESULT XML xml_output_stream.
catch cx_sy_conversion_base64 CX_SY_CONV_ILLEGAL_DATE_TIME.
write 'there is an exception'.
endtry.
This part of the code, I have also changed to :
xml_stream_factory->create_ostream_uri( system_id =
'file://test.xml' ).
and still the file is not visible.
I presume three reasons:
a) Looking in the wrong place
b) Some configuration, I am not doing properly
c) Something else has to be done, to write a file to system
Any help on this regard, is highly appreciated.
Next issue being, how robust is the approach of serializing ABAP data into XML format, so that a third party system can pick up this data and do a comparison ?
Some parameters that I am looking for in this regards are:
a) Error Validation (can XML data be incorrectly written into a file/while transmitting this data some errors can creep in. If so, how do I rectify it. As far as I know, this data can only be written to Presentation Server or using FTP ,transported to required destination. Is there any other approach ? )
b) Security
Would be great if you could drop some hints for the above procedure.
Regards,
Subramanian V.
2005 Mar 02 8:52 AM
Part of the answer is in this weblog:
/people/thomas.jung3/blog/2004/06/24/bsp-150-a-developer146s-journal-part-v-xml-for-rfcs
Regards,
Subramanian V.
Part of the answer is in this weblog:
/people/thomas.jung3/blog/2004/06/24/bsp-150-a-developer146s-journal-part-v-xml-for-rfcs
Regards,
Subramanian V.
2005 Mar 02 8:52 AM
Part of the answer is in this weblog:
/people/thomas.jung3/blog/2004/06/24/bsp-150-a-developer146s-journal-part-v-xml-for-rfcs
Regards,
Subramanian V.
2005 Mar 02 9:00 AM
Hi Subramanian,
I'm sure you would have done this, but just in case, have you taken a look at the online documenatation for the <i>call transformation</i> statement?
In the meanwhile, I shall try to get you some sample code that <i>works</i>.
Regards,
Anand Mandalika.
P.S. : Howz France, BTW ?
2005 Mar 02 10:01 AM
Hello Subramanian,
I must say that I'm not very happy with the answer I'm giving, because I think it is not as precise as I would have wanted it to be ), but here's something I would like to take your attention to -
1. The Demo Program SXSLTDEMO_FLIGHTS.
2. The following code snippet
DATA : example TYPE spfli,
xmlstring TYPE string.
select single *
from spfli
into example.
try.
CALL TRANSFORMATION id
SOURCE data_node = example
RESULT XML xmlstring.
* catch cx_sy_conversion_base64 CX_SY_CONV_ILLEGAL_DATE_TIME.
* write 'there is an exception'.
endtry.The string variable <b>xmlstring</b> contains the data in XML format.
Regards,
Anand Mandalika.
2005 Mar 02 1:46 PM
Hi Poornanand,
Thanks for your reply. Yes I have more/less figured out how serializing to XML format works. The weblog given by Thomas Jung has been pretty useful and in fact he has also given a mention of the development class/package to be used for this .
Probably tomorrow, I might have a chance to figure out, why the serializing process is not happening.
The only question remaining is the second part :
a) How to store ABAP data serialized to XML files into a different system, altogether ?
b) How robust will this approach be and how secure will it be ?
Regards,
Subramanian V.
P.S. - France must be good, I got no idea, why you ask.
2005 Mar 02 2:09 PM
I think you are perhaps overestimating the capabilities of the osteam object. If you want to write the XML to a file the easiest thing to do is render it an ostream_itable (internal ABAP table). Then you can download it your PC with the GUI_DOWNLOAD function:
parameter: ifile type file_table-filename obligatory
default 'c:issue.xml'.
****Temp File name for function module call.
data: ifilename type string.
move ifile to ifilename.
create object issue
exporting
id = id
create_mode = abap_false.
data: g_ixml type ref to if_ixml,
g_stream_factory type ref to if_ixml_stream_factory,
xslt_err type ref to cx_xslt_exception,
g_encoding type ref to if_ixml_encoding,
ostream type ref to if_ixml_ostream.
constants: line_length type i value 4096.
types: line_t(line_length) type x,
table_t type standard table of line_t.
data: restab type table_t.
constants:
* encoding for download of XML files
encoding type string value 'utf-8'.
data: ressize type i.
try.
g_ixml = cl_ixml=>create( ).
g_stream_factory = g_ixml->create_stream_factory( ).
g_encoding = g_ixml->create_encoding( character_set = encoding
byte_order = 0 ).
refresh restab.
ostream =
g_stream_factory->create_ostream_itable( table = restab ).
ostream->set_encoding( encoding = g_encoding ).
call transformation id_indent
source asap_issue = issue
result xml restab
options
data_refs = 'embedded'.
ressize = ostream->get_num_written_raw( ).
catch cx_xslt_exception into xslt_err.
data: s type string.
s = xslt_err->get_text( ).
endtry.
call function 'GUI_DOWNLOAD'
exporting
bin_filesize = ressize
filename = ifilename
filetype = 'BIN'
tables
data_tab = restab
exceptions
others = 1.
call method cl_gui_frontend_services=>execute
exporting
document = ifilename
* APPLICATION =
* PARAMETER =
* DEFAULT_DIRECTORY =
* MAXIMIZED =
* MINIMIZED =
* SYNCHRONOUS =
exceptions
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
others = 8.
As far as a different system, once you have the data serialized into a string or internal table you have lots of possibilites. If the other system is an SAP system you could send the data via RFC. You could always write the XML string to the server file system (via open dataset, transfer to dataset). You can then FTP the file (using built in SAP FTP functionality) just about anywhere.
What are you looking for as far as robust and secure. The XML serializer is built in the ABAP Kernel and quite robust. As far as secure- the data isn't secure at all. The data is written into a simple string (if written into the file system or your pc - it is a text or binary file that can easily be read by just about anything). Serializing to XML in and of itself isn't going to provide any security.
2005 Mar 02 2:35 PM
I would not put it as overestimating, but ignorance of what ostream can do. Thank you , anyway, for your help, I am sure, I will be able to eventually figure out how the pieces fit in, by reading the help, weblogs etc.
Thanks again for your help.
Best Regards,
Subramanian V.
2005 Mar 03 2:45 PM
Hello,
when downloading an XML file , make sure
you have serialized the XML into a raw table or xstring and
you have used utf-8 or utf-16 as your encoding. Otherwise, you will have problems displaying different character sets
depending on your PC locale settings.
Regards,
Marc
2005 Mar 03 6:38 AM
The file is created on the application server and you can use transaction AL11 to see the file in the DIR_HOME directory. But if do not execute the CLOSE method of the output stream object, you create a empty file of size 0.
2005 Mar 03 7:04 AM
Thanks Heinrich. I did see my test.xml in DIR_HOME directory.
Regards,
Subramanian V.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |