Application Development and Automation 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: 
Read only

function module to covert internal table to xml format

Former Member
0 Likes
3,046

function module to covert internal table to xml format

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,611

You can use this coding in 46c, in newer releases you can use the CALL TRANSFORMATION statement to convert to xml(of course you could probably use this coding in new releases as well.)



report zrich_0001.

type-pools: truxs.

data: it001 type table of t001 with header line.
data: ixml type truxs_xml_table.
data: xxml like line of ixml.
data: size type i.


select * into table it001 from t001.


call function 'SAP_CONVERT_TO_XML_FORMAT'
     importing
          pe_bin_filesize      = size
     tables
          i_tab_sap_data       = it001
     changing
          i_tab_converted_data = ixml
     exceptions
          conversion_failed    = 1
          others               = 2.


data: file_str type string.

file_str = 'C:test.xml'.

call function 'GUI_DOWNLOAD'
     exporting
          bin_filesize = size
          filename     = file_str
          filetype     = 'BIN'
     tables
          data_tab     = ixml
     exceptions
          others       = 22.

Regards,

Rich Heilman

2 REPLIES 2
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,612

You can use this coding in 46c, in newer releases you can use the CALL TRANSFORMATION statement to convert to xml(of course you could probably use this coding in new releases as well.)



report zrich_0001.

type-pools: truxs.

data: it001 type table of t001 with header line.
data: ixml type truxs_xml_table.
data: xxml like line of ixml.
data: size type i.


select * into table it001 from t001.


call function 'SAP_CONVERT_TO_XML_FORMAT'
     importing
          pe_bin_filesize      = size
     tables
          i_tab_sap_data       = it001
     changing
          i_tab_converted_data = ixml
     exceptions
          conversion_failed    = 1
          others               = 2.


data: file_str type string.

file_str = 'C:test.xml'.

call function 'GUI_DOWNLOAD'
     exporting
          bin_filesize = size
          filename     = file_str
          filetype     = 'BIN'
     tables
          data_tab     = ixml
     exceptions
          others       = 22.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,611

sooraj,

here is the sample code which i found in the forum

*&----


*

*& Report ZTESTXML *

*& *

*&----


*

*& *

*& *

*&----


*

*----


*

  • Report ZPRUEBA_MML_13 *

  • Export an internal table to XML document *

  • NO BORRAR ESTE CODIGO *

*----


*

report zprueba_mml_13.

*----


*

  • PANTALLA SELECCION *

parameters: gk_ruta type rlgrap-filename.

  • PANTALLA SELECCION *

*----


*

*----


*

  • TYPE TURNOS *

types: begin of turnos,

lu like t552a-tpr01,

ma like t552a-tpr01,

mi like t552a-tpr01,

ju like t552a-tpr01,

vi like t552a-tpr01,

sa like t552a-tpr01,

do like t552a-tpr01,

end of turnos.

  • TYPE TURNOS *

*----


*

*----


*

  • TYPE SOCIO *

types: begin of socio,

numero like pernr-pernr,

reposicion like pa0050-zauve,

nombre like pa0002-vorna,

turnos type turnos,

end of socio.

  • TYPE SOCIO *

*----


*

*----


*

  • ESTRUCTURA ACCESOS *

data: begin of accesos occurs 0,

socio type socio,

end of accesos.

  • ESTRUCTURA ACCESOS *

*----


*

*----


*

  • START OF SELECTION *

start-of-selection.

perform llena_accesos.

perform descarga_xml.

end-of-selection.

  • END OF SELECTION *

*----


*

*----


*

  • FORM LLENA_ACCESOS *

form llena_accesos.

refresh accesos.

clear accesos.

move: '45050' to accesos-socio-numero,

'MOISES MORENO' to accesos-socio-nombre,

'0' to accesos-socio-reposicion,

'T1' to accesos-socio-turnos-lu,

'T2' to accesos-socio-turnos-ma,

'T3' to accesos-socio-turnos-mi,

'T4' to accesos-socio-turnos-ju,

'T5' to accesos-socio-turnos-vi,

'T6' to accesos-socio-turnos-sa,

'T7' to accesos-socio-turnos-do.

append accesos.

clear accesos.

move: '45051' to accesos-socio-numero,

'RUTH PEÑA' to accesos-socio-nombre,

'0' to accesos-socio-reposicion,

'T1' to accesos-socio-turnos-lu,

'T2' to accesos-socio-turnos-ma,

'T3' to accesos-socio-turnos-mi,

'T4' to accesos-socio-turnos-ju,

'T5' to accesos-socio-turnos-vi,

'T6' to accesos-socio-turnos-sa,

'T7' to accesos-socio-turnos-do.

append accesos.

endform. "LLENA_ACCESOS

  • FORM LLENA_ACCESOS *

*----


*

*----


*

  • FORM DESCARGA_XML *

form descarga_xml.

data: l_dom type ref to if_ixml_element,

m_document type ref to if_ixml_document,

g_ixml type ref to if_ixml,

w_string type xstring,

w_size type i,

w_result type i,

w_line type string,

it_xml type dcxmllines,

s_xml like line of it_xml,

w_rc like sy-subrc.

data: xml type dcxmllines.

data: rc type sy-subrc,

begin of xml_tab occurs 0,

d like line of xml,

end of xml_tab.

class cl_ixml definition load.

g_ixml = cl_ixml=>create( ).

check not g_ixml is initial.

m_document = g_ixml->create_document( ).

check not m_document is initial.

write: / 'Converting DATA TO DOM 1:'.

call function 'SDIXML_DATA_TO_DOM'

exporting

name = 'ACCESOS'

dataobject = accesos[]

importing

data_as_dom = l_dom

changing

document = m_document

exceptions

illegal_name = 1

others = 2.

if sy-subrc = 0.

write 'Ok'.

else.

write: 'Err =',

sy-subrc.

endif.

check not l_dom is initial.

w_rc = m_document->append_child( new_child = l_dom ).

if w_rc is initial.

write 'Ok'.

else.

write: 'Err =',

w_rc.

endif.

call function 'SDIXML_DOM_TO_XML'

exporting

document = m_document

importing

xml_as_string = w_string

size = w_size

tables

xml_as_table = it_xml

exceptions

no_document = 1

others = 2.

if sy-subrc = 0.

write 'Ok'.

else.

write: 'Err =',

sy-subrc.

endif.

loop at it_xml into xml_tab-d.

append xml_tab.

endloop.

call function 'WS_DOWNLOAD'

exporting

bin_filesize = w_size

filename = gk_ruta

filetype = 'BIN'

tables

data_tab = xml_tab

exceptions

others = 10.

if sy-subrc <> 0.

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

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

endif.

endform. "DESCARGA_XML

  • FORM DESCARGA_XML *

*----


*

You can use the FMs:

SAP_CONVERT_TO_XML_FORMAT

SDIXML_DOM_TO_XML to do this.

See

for more reference.

~~Guduri