Application Development 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: 

Anyone know how to output an XML file from ABAP to a non sapgui location?

Former Member
0 Kudos

I have a program that creates XML and then outputs a file via CALL METHOD cl_gui_frontend_services=>gui_download. But now I want to execute the program in background mode and therefore I need to be able to output that XML to a NON sapgui file location. Current code creates the XML to an internal table which is binary then the gui_download method converts that to output XML. . Does anyone know how I can change the code to either a) output the XML to an internal table which can be output via, say, a TRANSFER command..or, b) output the created binary table of XML to a NON sapgui file location?

Excerpts from current code are as follows:

first the XML is created (to the binary file)

  • Creating a ixml factory

l_ixml = cl_ixml=>create( ).

  • Creating the dom object model

l_document = l_ixml->create_document( ).

  • Fill root node with value XML

l_element_xml = l_document->create_simple_element(

name = 'XML'

parent = l_document ).

  • Create tag 'HEADER' as child of 'XML'

l_element_header = l_document->create_simple_element(

name = 'HEADER'

parent = l_element_xml ).

  • header information about the file and general data about the fleet follows

l_value = c_fleet_import.

l_element_dummy = l_document->create_simple_element(

name = 'TYPE'

value = l_value

parent = l_element_header ).

etc.......

then the xml is connected to the stream factory and rendered

  • Creating a stream factory

l_streamfactory = l_ixml->create_stream_factory( ).

  • Connect internal XML table to stream factory

l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).

  • Rendering the document

l_renderer = l_ixml->create_renderer( ostream = l_ostream

document = l_document ).

l_rc = l_renderer->render( ).

  • Saving the XML document

l_xml_size = l_ostream->get_num_written_raw( ).

and then output to the file

IF sy-subrc = 0.

CALL METHOD cl_gui_frontend_services=>gui_download

EXPORTING

bin_filesize = l_xml_size

filename = 'g:\sapdms\BSCC-DEV\EFPAC XML Files\ALL.xml'

  • filename = '/TRICK/727/OUT/ZEFP/EFPAC.XML' "doesnt work with sap gui

filetype = 'BIN'

CHANGING

data_tab = l_xml_table

EXCEPTIONS

OTHERS = 24.

as implied by the comments the method above will successfully output the XML file to the g:drive but will not output to /TRICK/ location, which is where I need it to go in a background mode run.

This is a problem which has defeated all our local expertise and I would appreciate any help given... Barry Jones

1 ACCEPTED SOLUTION

former_member193964
Active Participant
0 Kudos

Try this code below:

data l_xml_table2 type table of xml_line with header line.

      • W_filename - This is a Path.

if w_filename(02) = '
'.

open dataset w_filename for output in binary mode.

if sy-subrc = 0.

l_xml_table2[] = l_xml_table[].

loop at l_xml_table2.

transfer l_xml_table2 to w_filename.

endloop.

endif.

close dataset w_filename.

else.

call method cl_gui_frontend_services=>gui_download

exporting

bin_filesize = l_xml_size

filename = w_filename

filetype = 'BIN'

changing

data_tab = l_xml_table

exceptions

others = 24.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

2 REPLIES 2

former_member193964
Active Participant
0 Kudos

Try this code below:

data l_xml_table2 type table of xml_line with header line.

      • W_filename - This is a Path.

if w_filename(02) = '
'.

open dataset w_filename for output in binary mode.

if sy-subrc = 0.

l_xml_table2[] = l_xml_table[].

loop at l_xml_table2.

transfer l_xml_table2 to w_filename.

endloop.

endif.

close dataset w_filename.

else.

call method cl_gui_frontend_services=>gui_download

exporting

bin_filesize = l_xml_size

filename = w_filename

filetype = 'BIN'

changing

data_tab = l_xml_table

exceptions

others = 24.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

Former Member
0 Kudos

Thanks Marcelo, I appreciate your reply....but I had tried a TRANSFER statement, from l_xml_table, which does convert binary to XML but only outputs 1 long record which is one string of several XML lines. ie it does the same conversion as the sapgui method but TRANSFER obviously does not format it correctly. I tried your use of l_xml_table2 but this did not do anything different.

a ps to my previous input we do not have an XI option. Am currently thinking we may need XSLT CALL TRANSFORMATION ABAP but there is a bigger learning curve on that...thanks anyway.... BJ