En el siguiente programa podremos transferir un xml a una tabla interna.
El código es el siguiente:
DATA: gcl_xml TYPE REF TO cl_xml_document.
DATA: gv_subrc TYPE sy-subrc.
DATA: gv_xml_string TYPE xstring.
DATA: gv_size TYPE sytabix.
DATA: gt_xml_data TYPE TABLE OF smum_xmltb.
DATA: gwa_xml_data TYPE smum_xmltb.
DATA: gt_return TYPE TABLE OF bapiret2.
DATA: gv_tabix TYPE sytabix.
DATA: gt_student TYPE TABLE OF ty_xml.
DATA: gwa_student TYPE ty_xml.
CREATE OBJECT gcl_xml.
*Upload XML File
CALL METHOD gcl_xml->import_from_file
EXPORTING
filename = p_p_filout
RECEIVING
retcode = gv_subrc.
IF gv_subrc = 0.
CALL METHOD gcl_xml->render_2_xstring
IMPORTING
retcode = gv_subrc
stream = gv_xml_string
size = gv_size.
IF gv_subrc = 0.
* Convert XML to internal table
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
xml_input = gv_xml_string
TABLES
xml_table = gt_xml_data
return = gt_return.
ENDIF.
ENDIF.
WRITE:/ 'fecha',6 'moneda',26 'compra', 33 'venta'.
*Convert XML internal table to Target Student table
LOOP AT gt_xml_data INTO gwa_xml_data WHERE hier EQ 2.
IF gwa_xml_data-type is INITIAL.
gv_tabix = sy-tabix + 1.
READ TABLE gt_xml_data INTO gwa_xml_data INDEX gv_tabix.
gwa_student-fecha = gwa_xml_data-cvalue.
gv_tabix = gv_tabix + 1.
READ TABLE gt_xml_data INTO gwa_xml_data INDEX gv_tabix.
gwa_student-moneda = gwa_xml_data-cvalue.
gv_tabix = gv_tabix + 1.
READ TABLE gt_xml_data INTO gwa_xml_data INDEX gv_tabix.
gwa_student-tccompra = gwa_xml_data-cvalue.
gv_tabix = gv_tabix + 1.
READ TABLE gt_xml_data INTO gwa_xml_data INDEX gv_tabix.
gwa_student-tcventa = gwa_xml_data-cvalue.
APPEND gwa_student to gt_student.
ENDIF.
CLEAR: gwa_xml_data, gwa_student.
ENDLOOP.
*Display data
LOOP AT gt_student INTO gwa_student.
WRITE:/ gwa_student-fecha,11 gwa_student-moneda,27 gwa_student-tccompra,
33 gwa_student-tcventa.
CLEAR: gwa_student.
ENDLOOP.
Muchas gracias José.
ResponderEliminarTu código me ha sido de gran ayuda dentro de un desarrollo para gestionar ficheros XML de remesas de pagos.
Un cordial saludo.