on 05-15-2006 1:56 PM
Hi friends
I am using R/3 4.7. I want parsing a xml file into my internal table. How can I do?
Clearly : I must download a xml file from website. Like www.a.com/b.xml And parse it in Abap to Internal table.
how can I do this?
Thanks
This message was moderated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mehmet,
Here is an example of Call transformation using the identity transformation
Convert internal table to XML .
CALL TRANSFORMATION id
SOURCE Z_VNDBNK = wa_vndbnk
RESULT XML lv_xml_data_string.
here the Z_VNDBNK is a custom structure and the wa_vndbnk is a workarea corresponding to that custom structure. If you are using a standard DDID structure say Sflight your code would be
CALL TRANSFORMATION id
SOURCE slfight = wa_sflight
RESULT XML lv_xml_data_string.
Convert XML to internal table.
For this you can still use identity transformation except you have to make couple of changes. The name space in the XML file you have probably is different from that the transformation is expecting. In this example I do a string replace.
Let us assume that the XML file is in lv_xml_data_string
Remove NEW-LINE character from XML data in STRING format
CLASS cl_abap_char_utilities DEFINITION LOAD.
REPLACE ALL OCCURENCES OF cl_abap_char_utilities=>newline IN
lv_xml_data_string WITH ''.
Make the XML envelope compliant with identity transform
REPLACE '<?xml version="1.0" encoding="UTF-8"?><data>'
IN lv_xml_data_string
WITH '<?xml version="1.0" encoding="iso-8859-1"?><asx:abap xmlns
:asx="http://www.sap.com/abapxml" version="1.0"><asx:values>'.
REPLACE '</data>'
IN lv_xml_data_string
WITH '</asx:values></asx:abap>'.
Apply the identity transform and convert XML into ABAP in one step
CALL TRANSFORMATION id
SOURCE XML lv_xml_data_string
RESULT Z_VNDBNK = wa_vndbnk.
I could have avoided the string replace by writing my own transformation and calling it using Call Transformation.
Hope this helps.
Thanks and Regards,
Vani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hai Mehmet
Try with the following Code
*----
*
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.
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.
FORM DESCARGA_XML *
*----
*
Thanks & regards
Sreenivasulu P
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
downloading xml from a site
call this method
data: http_client type ref to if_http_client ,
v_response type string .
call method cl_http_client=>create_by_url
exporting
url = 'http://bla.bal.com/ddd.xml'
* PROXY_HOST =
* PROXY_SERVICE =
* SSL_ID =
importing
client = http_client
exceptions
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
others = 4.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
call method http_client->send
exceptions
http_communication_failure = 1
http_invalid_state = 2.
* receive response
call method http_client->receive
exceptions
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
* get response as character data
v_response = http_client->response->get_cdata( ).
now v_response will have the returned xml
Regards
Raja
in the next post i will give you a example on how to convert the xml in to a ABAP itab.
Message was edited by: Durairaj Athavan Raja
Mehmet,
Have you tried Call Transformation? You can use the SAP delivered identity transformation which willdirectly convert XML to internal table or if this is not satisfactory you can write your own transformation and call it using CALL TRANSFORMATION.
Vani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Vani how can do it? Yes I have been searching CALL TRANSFORMATION but I have only result like this
ELEMENT : flights NUM_CHILDREN: 8 ROOT: #document NAME2:
#document
ELEMENT : airline NUM_CHILDREN: 2 ROOT: #document NAME2:
flights
ATTRIBUTE: code = AA
ATTRIBUTE: name = American Airlines
ELEMENT : flight NUM_CHILDREN: 5 ROOT: #document
NAME2: airline
ATTRIBUTE: number = 0017
ELEMENT : from NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
ATTRIBUTE: airport = JFK
VALUE : NEW YORK,US NAME2: from
ELEMENT : to NUM_CHILDREN: 1 ROOT: #document NAME2:
flight
ATTRIBUTE: airport = SFO
VALUE : SAN FRANCISCO,US NAME2: to
ELEMENT : departure NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
VALUE : 110000 NAME2: departure
ELEMENT : arrival NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
VALUE : 140100 NAME2: arrival
ELEMENT : type NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
VALUE : Scheduled NAME2: type
ELEMENT : flight NUM_CHILDREN: 5 ROOT: #document
I want load this data into table but I cann't do it. What is my solution? How can I read this lines and them into internal table.
Thanks for all persons. When I finish this topic I will give points to all interestrd person.
Thanks
Hi Mehmet,
Please refer the code below. It converts ITAB to XML and vice versa.
*----
DATA
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0,
a(100) TYPE c,
END OF itab.
DATA: xml_out TYPE string .
DATA : BEGIN OF upl OCCURS 0,
f(255) TYPE c,
END OF upl.
DATA: xmlupl TYPE string .
FIRST PHASE
FIRST PHASE
FIRST PHASE
*----
Fetch Data
SELECT * FROM t001 INTO TABLE t001.
*----
XML
CALL TRANSFORMATION ('ID')
SOURCE tab = t001[]
RESULT XML xml_out.
*----
Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = xml_out
i_tabline_length = 100
TABLES
et_table = itab.
*----
Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'BIN'
filename = 'd:\xx.xml'
TABLES
data_tab = itab.
SECOND PHASE
SECOND PHASE
SECOND PHASE
BREAK-POINT.
REFRESH t001.
CLEAR t001.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\XX.XML'
filetype = 'BIN'
TABLES
data_tab = upl.
LOOP AT upl.
CONCATENATE xmlupl upl-f INTO xmlupl.
ENDLOOP.
*----
XML
CALL TRANSFORMATION ('ID')
SOURCE XML xmlupl
RESULT tab = t001[]
.
BREAK-POINT.
<b>Please reward points to all the helpful answers and close the thread if your question has been answered.</b>
Regards,
Amit Mishra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How can I download www.blabla.com/releases.xml ? I didn't see any sample in your replies.
And my XML file using XSL how can I parse it ?
Thanks
to download the xml from www.blabla.com/releases.xml
use cl_http_client class.
and to convert the xml into ABAP itab you need to create the XSLT program from transaction se80.
let me know the format of the xml then i can help with the xslt
Regards
Raja
hii
do you want to <b>load the xml file into internal table</b> (as a table of binary strings),then simply use GUI_UPLOAD
if you want to load the xml data mapped to itab row columns
you need to load the xml file using <b>gui_upload and use XLST program</b> to transform into an itab
for example
<b>*----
DATA
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0,
a(100) TYPE c,
END OF itab.
DATA: xml_out TYPE string .
DATA : BEGIN OF upl OCCURS 0,
f(255) TYPE c,
END OF upl.
DATA: xmlupl TYPE string .
*----
Fetch Data
SELECT * FROM t001 INTO TABLE t001.
*----
XML
CALL TRANSFORMATION ('ID')
SOURCE tab = t001[]
RESULT XML xml_out.
*----
Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = xml_out
i_tabline_length = 100
TABLES
et_table = itab.
*----
Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'BIN'
filename = 'd:\xx.xml'
TABLES
data_tab = itab.
BREAK-POINT.
REFRESH t001.
CLEAR t001.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\XX.XML'
filetype = 'BIN'
TABLES
data_tab = upl.
LOOP AT upl.
CONCATENATE xmlupl upl-f INTO xmlupl.
ENDLOOP.
*----
XML
CALL TRANSFORMATION ('ID')
SOURCE XML xmlupl
RESULT tab = t001[]
.</b>BREAK-POINT.
for a good example refer to
Regards
Naresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Just to complement the above posts:
This should also be possible to do via the ABAP iXML framework:
There is good documentation and example code at:
http://help.sap.com/saphelp_nw04/helpdata/en/86/8280ba12d511d5991b00508b6b8b11/content.htm.
Another simple option would be to copy the code from blog:
/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach
And replace the file-upload code with a call to istream = streamfactory->create_istream_uri( URL_TO_SITE ).
which would let you read the XML data directly from a specified URI.
Regards,
Christian
Use the function:
S_XML_EBP_PARSE_TABLE
Regards,
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
10 | |
6 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.