‎2008 Jan 16 9:48 PM
Hi,
I have successfully output the contents of an xml document object (if_ixml_document) using the following code (where p_xml_document is my xml document object):
TYPES:
BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA:
streamfactory TYPE REF TO if_ixml_stream_factory,
ostream TYPE REF TO if_ixml_ostream,
renderer TYPE REF TO if_ixml_renderer,
ls_xml TYPE xml_line,
lt_xml_table TYPE TABLE OF xml_line,
v_xml_size TYPE i.
Transfer contents of xml document object into an internal table.
streamfactory = g_ixml->create_stream_factory( ).
ostream = streamfactory->create_ostream_itable( table = lt_xml_table ).
renderer = g_ixml->create_renderer( ostream = ostream document = p_xml_document ).
renderer->render( ).
v_xml_size = ostream->get_num_written_raw( ).
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = v_xml_size
filename = 'c:\hr_sl\aaa_sunlife.xml'
filetype = 'BIN'
CHANGING
data_tab = lt_xml_table.
My problem is I really need to output the XML to the application server, so I need to replace the call to cl_gui_frontend_services=>gui_download with something that will download the xml to the app server.
I've tried using OPEN DATASET/TRANSFER/CLOSE DATASET, and while I am getting a file created on the app server, it only contains one line of XML.
My code looks lile this:
OPEN DATASET l_ofile FOR OUTPUT IN BINARY MODE.
Transfer xml to dataset
LOOP AT lt_xml_table INTO ls_xml.
TRANSFER ls_xml TO l_ofile.
ENDLOOP.
Close the dataset.
CLOSE DATASET l_ofile.
I've searched and searched on SDN and have not found an answer. Any help would be greatly appreciated.
Thanks!
Edited by: Russell Hergott on Jan 16, 2008 10:52 PM
‎2008 Jan 16 10:39 PM
Hello,
Can you try this in stead of BINARY mode:
OPEN DATASET l_ofile FOR OUTPUT IN TEXT MODE
The BINARY mode outputs data as a stream of single line.
Thanks,
Venu
‎2008 Jan 17 2:00 PM
Thanks Venu, but I've already tried that. My program ends up dumping on the TRANSFER statement because ls_xml is a non-character datatype (its type is x).
‎2008 Feb 25 2:30 PM
Hi,
Instead of directly transfering it to the concern file....
why dont u concatenate ur xml data into some initial internal table first and then loop this internal table and then transfer data into ur concern file........this wud help u out..........
Please get me back if u've solved this.........or not.........
‎2008 Feb 25 2:42 PM
hi boss,
some of the code may be useful for u .
try like this sending into the internal table and then try ....
&----
*& Report ZTESTPROGRAMFORUPLOAD
*&
&----
*&
*&
&----
REPORT ZTESTPROGRAMFORUPLOAD message-id zmsg.
tables:pa0002.
types:begin of ty_pa0000,
pernr like pa0000-pernr,
endda like pa0000-begda,
end of ty_pa0000.
types:begin of ty_pa0002,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
end of ty_pa0002.
data:it_pa0000 type standard table of ty_pa0000 with header line,
it_pa0002 type standard table of ty_pa0002 with header line.
data: v_pernr like pa0002-pernr,
v_lines type i.
DATA: W_MSG(150) TYPE C.
SELECTION-SCREEN BEGIN OF BLOCK FILE WITH FRAME TITLE TEXT-FIL.
*SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: P_PC RADIOBUTTON GROUP RAD USER-COMMAND USR. "PC
*SELECTION-SCREEN COMMENT 3(5) TEXT-SC1.
PARAMETERS: P_UNIX RADIOBUTTON GROUP RAD DEFAULT 'X'. "UNIX
*SELECTION-SCREEN COMMENT 11(5) TEXT-SC2.
parameters:p_file like rlgrap-filename.
*SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK FILE.
at selection-screen on value-request for p_file.
perform f4_help.
START-OF-SELECTION.
*---Get the active employyes
select pernr
endda
from pa0000
into table it_pa0000 up to 100 rows
where endda >= sy-datum
and begda <= sy-datum
and stat2 = '3'.
if sy-subrc = 0.
sort it_pa0000 by pernr endda descending.
delete adjacent duplicates from it_pa0000 comparing pernr.
endif.
select pernr
begda
endda
vorna
nachn
from pa0002
into table it_pa0002
for all entries in it_pa0000
where pernr = it_pa0000-pernr.
sort it_pa0002 by pernr.
delete adjacent duplicates from it_pa0002 comparing pernr.
append it_pa0002.
endloop.
END-OF-SELECTION.
describe table it_pa0002 lines v_lines .
*---get data into Application Server.
PERFORM OUTPUT_CORPEDIA_VENDOR_FILE .
SKIP 2.
WRITE:/ 'FILE NAME :' , P_FILE .
WRITE:/ 'NO OF RECORDS DOWNLOADED : ', V_LINES .
&----
*& Form f4_help
&----
text
----
--> p1 text
<-- p2 text
----
form f4_help .
IF P_UNIX = 'X'.
F4 help for UNIX
CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
EXPORTING
DYNPFIELD_FILENAME = 'P_FILE'
DYNAME = SY-CPROG
DYNUMB = SY-DYNNR
FILETYPE = 'P'
LOCATION = 'A'
SERVER = ''.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH TEXT-E01 P_FILE.
ENDIF.
ELSEIF P_PC = 'X'.
F4 help for PC
clear p_file.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = P_FILE
MASK = ',..'
MODE = '0 '
TITLE = 'Choose File'
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDIF.
endform. " f4_help
&----
*& Form OUTPUT_CORPEDIA_VENDOR_FILE
&----
text
----
--> p1 text
<-- p2 text
----
form OUTPUT_CORPEDIA_VENDOR_FILE .
IF P_PC = 'X'.
data: v_pcfile type string.
v_pcfile = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = v_pcfile
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = it_pa0002.
sort it_pa0002 by pernr.
delete adjacent duplicates from it_pa0002.
else.
data: outrec(200) type c .
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE encoding DEFAULT.
loop at it_pa0002.
outrec+0(8) = it_pa0002-pernr.
outrec+18(8) = it_pa0002-begda.
outrec+36(8) = it_pa0002-endda.
outrec+54(40) = it_pa0002-vorna.
outrec+104(40) = it_pa0002-nachn.
transfer outrec to p_file.
clear outrec.
endloop.
CLOSE DATASET OUTREC.
IF SY-SUBRC = 0.
CLEAR W_MSG.
CONCATENATE 'Corpedia Vendor Demographic File successfully written to:'
P_FILE
INTO W_MSG SEPARATED BY SPACE.
ULINE. SKIP.
WRITE : W_MSG.
ENDIF.
ENDIF.
endform. " OUTPUT_CORPEDIA_VENDOR_FILE
regards,
venkat.
‎2008 Feb 25 3:02 PM
Thanks for your responses, but I solved this problem a while back.
I was finally able to solve this by using the if_ixml_stream_factory and related classes to populate an internal table from my xml object.
The following code populates internal table lt_xml_table from my xml object p_xml_document (type if_xml_document).
TYPES:
BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA:
streamfactory TYPE REF TO if_ixml_stream_factory,
ostream TYPE REF TO if_ixml_ostream,
renderer TYPE REF TO if_ixml_renderer,
lt_xml_table TYPE TABLE OF xml_line,
pretty_print TYPE ddbool_d.
Transfer contents of xml document object into an internal table.
streamfactory = g_ixml->create_stream_factory( ).
ostream = streamfactory->create_ostream_itable( table = lt_xml_table ).
pretty_print = 'X'.
ostream->set_pretty_print( pretty_print = pretty_print ).
renderer = g_ixml->create_renderer( ostream = ostream document = p_xml_document ).
renderer->render( ).
Once this is accomplished, I can simply use open dataset/file transfer/close dataset to copy the contents of the internal table to the application server.
Cheers!