2006 May 24 10:13 AM
Hi All
I have to upload data from an xml file.
I guess the function module SMUM_XML_PARSE can be used for achieving this. But can anybody please tell me the exact procedure to use this function module.
The program is going for a dump showing a CALL_FUNCTION_CONFLICT_TYPE error.
The code is as follows
data: stab like smum_xmltb occurs 0 with header line.
data: ret1 like bapiret2 occurs 0.
call function 'SMUM_XML_PARSE'
exporting
xml_input = 'C:TEST.XML'
tables
xml_table = stab
return = ret1
.
loop at stab.
write:/ stab-hier,stab-type.
endloop.Thanks in advance
Sree Ramya
2006 May 24 10:28 AM
Welcome to SDN.
the import parameter XML_INPUT is not file name.
its of type XSTRING which holds the actual xmldata in binary format.
first use gui_upload with file type 'BIN' to upload the xml file from 'C:\TEST.XML' into an itab.
then use FM SCMS_BINARY_TO_XSTRING to conver the GUI_UPLOAD returned binary table to xstring and now pass the XSTRING value to xml_input parameter of FM SMUM_XML_PARSE
Hope this is clear.
Regards
Raja
Hi All
I have to upload data from an xml file.
I guess the function module SMUM_XML_PARSE can be used for achieving this. But can anybody please tell me the exact procedure to use this function module.
The program is going for a dump showing a CALL_FUNCTION_CONFLICT_TYPE error.
The code is as follows
data: stab like smum_xmltb occurs 0 with header line.
data: ret1 like bapiret2 occurs 0.
call function 'SMUM_XML_PARSE'
exporting
xml_input = 'C:TEST.XML'
tables
xml_table = stab
return = ret1
.
loop at stab.
write:/ stab-hier,stab-type.
endloop.Thanks in advance
Sree Ramya
2006 May 24 10:14 AM
Hi sree,
1. itab --- > xml
xml ---> itab.
2. This program will do both.
(just copy paste in new program)
3.
REPORT abc.
*----
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.
regards,
amit m.
2006 May 24 10:38 AM
Thanks Amit
But the FM HR_EFI_CONVERT_STRING_TO_TABLE is not available in the repository. Can u suggest any other FM whuch serves the purpose ?
2006 May 24 11:09 AM
2006 May 24 12:17 PM
Hi Amit
The func. module 'HR_EFI_CONVERT_STRING_TO_TABLE' is not available in function module repository. Can you let me know any alternative function module which does the same functionality as 'HR_EFI_CONVERT_STRING_TO_TABLE' does?
Your early reply will be appreciable.
Thanks,
Pavan.
2006 May 24 12:26 PM
did you read my earlier post?
use
SCMS_STRING_TO_FTEXT for converting string to table.
Regards
Raja
2006 May 24 10:18 AM
2006 May 24 10:19 AM
2006 May 24 10:23 AM
hii
as for fm
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = inputstring
TABLES
XML_TABLE = xmltab
RETURN = ZBAPIRET2.
This function module converts yr xml file i.e. in inputstring into zmltab table. Then U can loop on table to check the content.
go thru this link
http://www.geocities.com/victorav15/sapr3/abapfun.html#xml
and also refer the example
check this code
1. Convert internal table to XML.
Here is a sample program to convert internal table to XML
*&----
*
*& 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 *
*----
*
2. To convert XML to internal table.
You can use these function modules
TEXT_CONVERT_XML_TO_SAP or
SDIXML_DOM_TO_XML Convert DOM (XML) into string of bytes that can be downloaded to PC or application server
or
SMUM_XML_PARSE (Parse XML docment into a table structure)
You can also refer to these:
SMUM_XML_CREATE (Create XML document from internal table)
SMUM_XML_CREATE_X (Create XSTRING xml doc)
Check this code, it converts an XML data into a string internal table.
REPORT Z_XML_TO_TABLE.
TYPE-POOLS: ixml.
TYPES: BEGIN OF t_xml_line,
data(256) TYPE x,
END OF t_xml_line.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_parser TYPE REF TO if_ixml_parser,
l_istream TYPE REF TO if_ixml_istream,
l_document TYPE REF TO if_ixml_document,
l_node TYPE REF TO if_ixml_node,
l_xmldata TYPE string.
DATA: l_elem TYPE REF TO if_ixml_element,
l_root_node TYPE REF TO if_ixml_node,
l_next_node TYPE REF TO if_ixml_node,
l_name TYPE string,
l_iterator TYPE REF TO if_ixml_node_iterator.
DATA: l_xml_table TYPE TABLE OF t_xml_line,
l_xml_line TYPE t_xml_line,
l_xml_table_size TYPE i.
DATA: l_filename TYPE string.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'c: emporders_dtd.xml'.
Validation of XML file: Only DTD included in xml document is supported
PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
START-OF-SELECTION.
Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.
wrap the table containing the file into a stream
l_istream = l_streamfactory->create_istream_itable( table =
l_xml_table
size =
l_xml_table_size ).
Creating a document
l_document = l_ixml->create_document( ).
Create a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
Validate a document
IF pa_val EQ 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
ENDIF.
Parse the stream
IF l_parser->parse( ) NE 0.
IF l_parser->num_errors( ) NE 0.
DATA: parseerror TYPE REF TO if_ixml_parse_error,
str TYPE string,
i TYPE i,
count TYPE i,
index TYPE i.
count = l_parser->num_errors( ).
WRITE: count, ' parse errors have occured:'.
index = 0.
WHILE index < count.
parseerror = l_parser->get_error( index = index ).
i = parseerror->get_line( ).
WRITE: 'line: ', i.
i = parseerror->get_column( ).
WRITE: 'column: ', i.
str = parseerror->get_reason( ).
WRITE: str.
index = index + 1.
ENDWHILE.
ENDIF.
ENDIF.
Process the document
IF l_parser->is_dom_generating( ) EQ 'X'.
PERFORM process_dom USING l_document.
ENDIF.
*&----
*
*& Form get_xml_table
*&----
*
FORM get_xml_table CHANGING l_xml_table_size TYPE i
l_xml_table TYPE STANDARD TABLE.
Local variable declaration
DATA: l_len TYPE i,
l_len2 TYPE i,
l_tab TYPE tsfixml,
l_content TYPE string,
l_str1 TYPE string,
c_conv TYPE REF TO cl_abap_conv_in_ce,
l_itab TYPE TABLE OF string.
l_filename = pa_file.
upload a file from the client's workstation
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_xml_table_size
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Writing the XML document to the screen
CLEAR l_str1.
LOOP AT l_xml_table INTO l_xml_line.
c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
replacement = space ).
c_conv->read( IMPORTING data = l_content len = l_len ).
CONCATENATE l_str1 l_content INTO l_str1.
ENDLOOP.
l_str1 = l_str1+0(l_xml_table_size).
SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
WRITE: /.
WRITE: /' XML File'.
WRITE: /.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
IN
l_str1 WITH space.
WRITE: / l_str1.
ENDLOOP.
WRITE: /.
ENDFORM. "get_xml_table
*&----
*
*& Form process_dom
*&----
*
FORM process_dom USING document TYPE REF TO if_ixml_document.
DATA: node TYPE REF TO if_ixml_node,
iterator TYPE REF TO if_ixml_node_iterator,
nodemap TYPE REF TO if_ixml_named_node_map,
attr TYPE REF TO if_ixml_node,
name TYPE string,
prefix TYPE string,
value TYPE string,
indent TYPE i,
count TYPE i,
index TYPE i.
node ?= document.
CHECK NOT node IS INITIAL.
ULINE.
WRITE: /.
WRITE: /' DOM-TREE'.
WRITE: /.
IF node IS INITIAL. EXIT. ENDIF.
create a node iterator
iterator = node->create_iterator( ).
get current node
node = iterator->get_next( ).
loop over all nodes
WHILE NOT node IS INITIAL.
indent = node->get_height( ) * 2.
indent = indent + 20.
CASE node->get_type( ).
WHEN if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
WRITE: / 'ELEMENT :'.
WRITE: AT indent name COLOR COL_POSITIVE INVERSE.
IF NOT nodemap IS INITIAL.
attributes
count = nodemap->get_length( ).
DO count TIMES.
index = sy-index - 1.
attr = nodemap->get_item( index ).
name = attr->get_name( ).
prefix = attr->get_namespace_prefix( ).
value = attr->get_value( ).
WRITE: / 'ATTRIBUTE:'.
WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',
value COLOR COL_TOTAL INVERSE.
ENDDO.
ENDIF.
WHEN if_ixml_node=>co_node_text OR
if_ixml_node=>co_node_cdata_section.
text node
value = node->get_value( ).
WRITE: / 'VALUE :'.
WRITE: AT indent value COLOR COL_GROUP INVERSE.
ENDCASE.
advance to next node
node = iterator->get_next( ).
ENDWHILE.
ENDFORM. "process_dom
Regards
Naresh
2006 May 24 10:28 AM
Welcome to SDN.
the import parameter XML_INPUT is not file name.
its of type XSTRING which holds the actual xmldata in binary format.
first use gui_upload with file type 'BIN' to upload the xml file from 'C:\TEST.XML' into an itab.
then use FM SCMS_BINARY_TO_XSTRING to conver the GUI_UPLOAD returned binary table to xstring and now pass the XSTRING value to xml_input parameter of FM SMUM_XML_PARSE
Hope this is clear.
Regards
Raja
2006 May 24 12:55 PM
Thanks Raja
The information which u provided was very useful.
But still I came across a few problems while implementing the logic.
Could you please give a sample code demonstrating ur logic.
2006 May 24 1:09 PM
sure, let me know which version of SAP you are using , so that i can use the right FMs
Regards
Raja
2006 May 24 1:43 PM
Thanks again Raja
We r using 4.7.
I am facing a problem with the stucture type of the table with file type BIN in GUI_UPLOAD
2006 May 24 1:51 PM
2006 May 24 2:03 PM
here is the complete code sample.
1. uploading XML from front end (i just hard coded the filename for simplicity sake - youcan use cl_gui_front end service=>file_open_dialog to dynamically get the file name.
2. parse the uploaded xml using the FM SMUM_XML_PARSE
REPORT Y_XML_UPLOAD
NO STANDARD PAGE HEADING.
data: filename type string ,
xmldata type xstring .
data: result_xml type standard table of SMUM_XMLTB .
data: return type standard table of BAPIRET2 .
constants: line_size type i value 255.
data: begin of xml_tab occurs 0,
raw(line_size) type x,
end of xml_tab,
file type string,
size type i.
* upload the xml file
filename = 'C:rajabw.xml' .
call function 'GUI_UPLOAD'
exporting
filename = filename
filetype = 'BIN'
has_field_separator = ' '
header_length = 0
importing
filelength = size
tables
data_tab = xml_tab
exceptions
others = 1.
************uncomment this and comment the call of SCMS_BINARY_TO_XSTRING if you dont have this fm in your system.
* if sy-subrc <> 0.
* clear: xmldata.
* exit.
* else.
* data: len type i.
* len = size.
* loop at xml_tab.
* if len <= line_size. exit. endif.
* concatenate xmldata xml_tab-raw(line_size)
* into xmldata in byte mode.
* len = len - line_size.
* endloop.
* if len > 0.
* concatenate xmldata xml_tab-raw(len)
* into xmldata in byte mode.
* len = len - size.
* endif.
* endif.
******* end of comment.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = size
* FIRST_LINE = 0
* LAST_LINE = 0
IMPORTING
BUFFER = xmldata
TABLES
binary_tab = xml_tab
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
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 FUNCTION 'SMUM_XML_PARSE'
EXPORTING
xml_input = xmldata
TABLES
xml_table = result_xml
return = return .Regards
Raja
2006 May 24 2:52 PM
2006 May 24 10:32 AM
hi
chk the code
u hav to declare xstring for the input
this works
<b>data : str type xstring.
str = 'C:\TEST.XML'.</b>
data: stab like smum_xmltb occurs 0 with header line.
data: ret1 like bapiret2 occurs 0.
call function 'SMUM_XML_PARSE'
exporting
xml_input = <b>str</b>
tables
xml_table = stab
return = ret1
.
loop at stab.
write:/ stab-hier,stab-type.
<b>plz reward points</b>
2006 May 24 12:27 PM
Hi again,
1. CONVERT_STRING_TO_TABLE
( im not sure , whether this FM will also be there
in your version)
2. *----
As suggested by raja,
we can use that FM.
CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
EXPORTING
TEXT = xml_out
IMPORTING
LENGTH =
TABLES
FTEXT_TAB = itab
.
regards,
amit m.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |