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

XML data

Former Member
0 Likes
1,410

Hi Experts,

How to upload XML data into SAP

14 REPLIES 14
Read only

Former Member
0 Likes
1,374

Hi,

refer the following//

/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach

Regards

vijay

Read only

0 Likes
1,374

Hi

Thanks for the Info.

Read only

0 Likes
1,374

Hi,

I am using SAP4.7 version.

I am having a XML file on my desk top.

So i have to upload data from that XML file to a Z-table in SAP.

Can ny body tell me the procedure clearly..

i have seen some posts..But it is little confusing..

Thanks in Advance.

Read only

0 Likes
1,374

Hi ravi,

1. itab --- > xml

xml ---> itab.

*----


<b>a) after uploading xml file into your internal table,

just use this logic

LOOP AT ITAB.

MODIFY ZTABLE FROM ITAB.

ENDLOOP

(this modify statement will AUTOMATICALLY take care

of insert/update based upon the primary key combination,

if found/not found in ztable)</b>

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.

Read only

0 Likes
1,374

Hi Amit,

Thanks for the response.

But if it is CRM system can you tell me how to do it?

Becoz..the FM HR_EFI_CONVERT_STRING_TO_TABLE does not exist in CRM.

Read only

0 Likes
1,374

Hi again,

1. CONVERT_STRING_TO_TABLE

U can use this FM also.

regards,

amit m.

Read only

0 Likes
1,374

Evn the fm CONVERT_STRING_TO_TABLE does not exist in CRM.

also the FM 'HR_EFI_CONVERT_STRING_TO_TABLE' does not exist in SAP 4.7...

Read only

0 Likes
1,374

Hi again,

1. we can use this also.

SCMS_STRING_TO_FTEXT

(this FM will be available )

regards,

amit m.

Read only

0 Likes
1,374

<i>So i have to upload data from that XML file to a Z-table in SAP.</i>

is it the XML file itself into Ztable or you have to parse the XML file and update the Ztable fields with the value from the xml?

here is the complete code sample for uploading/parsing xml file.

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

Read only

0 Likes
1,374

hi Ravi,

you can use SMUM_XML_TAB function module also

regards,

Pavan

Read only

Former Member
0 Likes
1,374

hi

please check out this blog

Read only

Former Member
0 Likes
1,374

HI Ravi,

Check this link.

/people/sap.user72/blog/2006/01/19/upload-data-from-multiple-worksheets-within-a-single-excel-file-into-internal-table-from-abap

Regards,

Laxmi.

Read only

Former Member
0 Likes
1,374

Hi again,

1. we can use this also.

SCMS_STRING_TO_FTEXT

(this FM will be available )

regards,

amit m.

Read only

Former Member
0 Likes
1,374

Upload XML file with "GUI_UPLOAD" function.

Then you need to convert to SAP parser like this fragment of code

DATA: ixml TYPE REF TO if_ixml,

out type ref to if_ixml_document,

str TYPE string.

CLASS cl_ixml DEFINITION LOAD.

*-- create the main factory

ixml = cl_ixml=>create( ).

DATA: streamfactory TYPE REF TO if_ixml_stream_factory,

istream TYPE REF TO if_ixml_istream,

parser TYPE REF TO if_ixml_parser.

out_xml = ixml->create_document( ).

streamfactory = ixml->create_stream_factory( ).

istream = streamfactory->create_istream_string( str ).

parser = ixml->create_parser( stream_factory = streamfactory

istream = istream

document = out_xml ).

IF parser->parse( ) <> 0.

RAISE parse_error.

ENDIF.

At last you operate with this