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 to internal table

Former Member
0 Likes
1,197

Hi all,

i have a requirement to convert XML to itab.

i tried using call transformation but i ma getting an error related to XSLT...

can anyone tell me the exact procedure for doing this. i referred many links but not able to get the solution.

11 REPLIES 11
Read only

Former Member
0 Likes
1,044

This message was moderated.

Read only

Former Member
0 Likes
1,044

Can you please try function module 'HR_PT_XML_TO_TABLE' or 'HR_BE_DMFA_XML_TO_TABLE'.

Read only

Former Member
0 Likes
1,044

This message was moderated.

Read only

0 Likes
1,044

hi,

can you tell me how can i read an xml file to string when the xml file is in presentation server?

Read only

0 Likes
1,044

Hi,

basically get all the xml code into a txt file and using FM GUI_UPLOAD get the file into an internal table of type string. ie.

data:
    t_itab type table of string.

call function gui_upload.
filename = 'path:\' .   " TXT  File Path in the presentation server


tab  = t_itab.



read table t_itab.

thanks

ravi

Read only

Former Member
0 Likes
1,044

Hi Poonam,

Even i had this problem before and saw many links ultimately found one,

Suppose this is the content in the xml file

<?xml version="1.0" encoding="iso-8859-1" ?>

<CUSTOMERS>

<PERSON>

<customer_id>1</customer_id>

<first_name>Jan</first_name>

<last_name>Krohn</last_name>

</PERSON>

<PERSON>

<customer_id>2</customer_id>

<first_name>James</first_name>

<last_name>Kirk</last_name>

</PERSON>

</CUSTOMERS>

Now to shift the data from the above XML file into an internal ABAP table of the type ts_person.

This ABAP report to accomplish this task consists of two parts.

The first part is a regular ABAP programme, the second part is an XSLT transformation.

SAP supports this standard via "CALL TRANSFORMATION".

&----


*& Report Z_XML_TO_ABAP *

*& *

&----


*& Read the data from an XML file into an ABAP internal table, *

*& and print it on the screen *

&----


REPORT z_xml_to_abap.

TYPE-POOLS abap.

CONSTANTS gs_file TYPE string VALUE 'C:\temp\customers.xml'.

  • This is the structure for the data from the XML file

TYPES: BEGIN OF ts_person,

cust_id(4) TYPE n,

firstname(20) TYPE c,

lastname(20) TYPE c,

END OF ts_person.

  • Table for the XML content

DATA: gt_itab TYPE STANDARD TABLE OF char2048.

  • Table and work ares for the data from the XML file

DATA: gt_person TYPE STANDARD TABLE OF ts_person,

gs_person TYPE ts_person.

  • Result table that contains references of the internal tables to be filled

DATA: gt_result_xml TYPE abap_trans_resbind_tab,

gs_result_xml TYPE abap_trans_resbind.

  • For error handling

DATA: gs_rif_ex TYPE REF TO cx_root,

gs_var_text TYPE string.

*For getting the XML file

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = gs_file

CHANGING

data_tab = gt_itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

not_supported_by_gui = 17

error_no_gui = 18

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.

  • Fill the result table with a reference to the data table.

  • Within the XSLT stylesheet, the data table can be accessed with

  • "IPERSON".

GET REFERENCE OF gt_person INTO gs_result_xml-value.

gs_result_xml-name = 'IPERSON'.

APPEND gs_result_xml TO gt_result_xml.

  • Perform the XSLT stylesheet

TRY.

CALL TRANSFORMATION z_xml_to_abap

SOURCE XML gt_itab

RESULT (gt_result_xml).

CATCH cx_root INTO gs_rif_ex.

gs_var_text = gs_rif_ex->get_text( ).

MESSAGE gs_var_text TYPE 'E'.

ENDTRY.

  • for checking the file contents

LOOP AT gt_person INTO gs_person.

WRITE: / 'Customer ID:', gs_person-cust_id.

WRITE: / 'First name :', gs_person-firstname.

WRITE: / 'Last name :', gs_person-lastname.

WRITE : /.

ENDLOOP. "gt_person.

revert back if you have any problems

Thanks and Regards

Srikanth.P

Read only

0 Likes
1,044

i am getting an error :

z_xml_to_abap cannot be executed.

Read only

0 Likes
1,044

Hi,

Being the author of this programme, I'd like to ask you not to paste it without any reference or link to the original.

Thanks,

Jan

Read only

0 Likes
1,044

Hi Poonam,

Did you created z_xml_to_abap and activated all.

Regards,

Madhu.

Read only

Former Member
0 Likes
1,044

Go through the link. It will solve your problem.

<pre>

https://wiki.sdn.sap.com/wiki/display/Snippets/SimulatortoreaddatafromaxmlfilestoredintheMIMErepositoryandconvertitintotheinternal+table.

</pre>

Edited by: Shiva Prasad L on Jun 15, 2009 12:27 PM

Edited by: Shiva Prasad L on Jun 15, 2009 12:29 PM

Read only

Former Member
0 Likes
1,044

I dont know what to place in the call transformation .. how do i generate the xslt code for the xml fiel i have??