Skip to Content
0
Nov 18, 2011 at 11:00 AM

Import xml file from server to itab

173 Views

Hi all,

I have a little issue loading data from xml file in server into my itab.

With my file in local (C:\example\example.xml) works fine, but if try this with the same file in the server (e:\example\example.xml) dont work. This is my code resume.

TYPES: BEGIN OF TY_TAB,
NAME TYPE STRING,
VALUE TYPE STRING,
END OF TY_TAB.

DATA: ITAB TYPE STANDARD TABLE OF TY_TAB,
WA TYPE TY_TAB.

* Nombre del fichero
DATA: NOMBREFICHEROXML LIKE IBIPPARMS-PATH,


* data XML
DATA: LCL_XML_DOC TYPE REF TO CL_XML_DOCUMENT,
V_SUBRC TYPE SYSUBRC,
V_NODE TYPE REF TO IF_IXML_NODE,
V_CHILD_NODE TYPE REF TO IF_IXML_NODE,
V_ROOT TYPE REF TO IF_IXML_NODE,
V_ITERATOR TYPE REF TO IF_IXML_NODE_ITERATOR,
V_NODEMAP TYPE REF TO IF_IXML_NAMED_NODE_MAP,
V_COUNT TYPE I,
V_INDEX TYPE I,
V_ATTR TYPE REF TO IF_IXML_NODE,
V_NAME TYPE STRING,
V_PREFIX TYPE STRING,
V_VALUE TYPE STRING,
V_CHAR TYPE CHAR2.

NOMBREFICHEROXML = 'E:\example\example.xml'.

CREATE OBJECT LCL_XML_DOC.
CALL METHOD LCL_XML_DOC->IMPORT_FROM_FILE
EXPORTING
FILENAME = NOMBREFICHEROXML
RECEIVING
RETCODE = V_SUBRC.

IF V_SUBRC EQ '0'.
V_NODE = LCL_XML_DOC->M_DOCUMENT.
CHECK NOT V_NODE IS INITIAL.
V_ITERATOR = V_NODE->CREATE_ITERATOR( ).
V_NODE = V_ITERATOR->GET_NEXT( ).

WHILE NOT V_NODE IS INITIAL.
CASE V_NODE->GET_TYPE( ).
WHEN IF_IXML_NODE=>CO_NODE_ELEMENT.
V_NAME = V_NODE->GET_NAME( ).
WHEN IF_IXML_NODE=>CO_NODE_TEXT OR
IF_IXML_NODE=>CO_NODE_CDATA_SECTION.
*text node
V_VALUE = V_NODE->GET_VALUE( ).
MOVE V_VALUE TO V_CHAR.
IF V_CHAR <> CL_ABAP_CHAR_UTILITIES=>CR_LF.
WA-NAME = V_NAME.
WA-VALUE = V_VALUE.
APPEND WA TO ITAB.
CLEAR WA.
ENDIF.
ENDCASE.
*advance to next node
V_NODE = V_ITERATOR->GET_NEXT( ).
ENDWHILE.

WRITE:/ 'file ok'.
ELSE.
WRITE:/ 'file ko'.

Anyone can help, or tell me a easy way to load xml file from server to my itab that works with my old sap 4.7.

thanks

Edited by: DIEGO_GT on Nov 18, 2011 12:04 PM