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 ABAP

Former Member
0 Likes
749

Hello Experts,

i want convert XML file to ABAP and my XML file is mentioned below:-

i have used CALL TRANSFORMATION and i have created structure in se11 Znee_dataset is my structure which has fields that are listed in the XML output and my problems are:-

1.) how to create CALL TRANSFORMATION ?

2.) can i use CALL TRANSFORMATION ID ?

My code:-

REPORT ZTEST_XML_CONVERSTAION.

TYPE-POOLS abap.

*Input file contents as string.XML file path where we saved the file. *Here it is saved in desktop.

*Input file with path as constant

CONSTANTS gs_file TYPE string VALUE 'C:UsersNeeru SangwanDesktopNee FileACT_GlobalExample Gatekeeper XML filesMATCREATE_11314_20111031_19344131.XML' ."'C:Documents and

"SettingsAdministratorDesktop est1.xml'.

BREAK-POINT.

*PARAMETERS : gs_file TYPE string.

*PARAMETER: FILE_NM TYPE RLGRAP-FILENAME OBLIGATORY.

*This is the structure type for the data from the XML file

TYPES: BEGIN OF ts_zeu_matmas03,

idoc TYPE Znee_dataset, "ZIDOC_TEST structure we created in SE11

END OF ts_zeu_matmas03.

  • Table for storing the XML content from file

DATA: gt_itab TYPE STANDARD TABLE OF char2048.

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

DATA: gt_zeu_matmas03 TYPE STANDARD TABLE OF ts_zeu_matmas03,

gs_zeu_matmas03 TYPE ts_zeu_matmas03.

DATA : IT_DATA_XML TYPE STANDARD TABLE OF ZNEW_DATASET WITH HEADER LINE.

DATA : XML_RESULT TYPE STRING.

  • 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.

FIELD-SYMBOLS:

type any.

  • For error handling

DATA: gs_rif_ex TYPE REF TO cx_root,

gs_var_text TYPE string,

IT_TAB TYPE FILETABLE,

GD_SUBRC TYPE I,

l_xml_table_size TYPE i.

  • Get the XML file from your client

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = gs_file

filetype = 'DAT'

IMPORTING

filelength = l_xml_table_size

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.

CALL TRANSFORMATION ID

SOURCE XML gt_itab

RESULT SOURCE = IT_DATA_XML[].

Nothing is in IT_DATA_XML[]

Please help me <removed by moderator>.

Regards,

Nee

Edited by: Thomas Zloch on Nov 15, 2011 12:33 PM

Hello Experts,

i want convert XML file to ABAP and my XML file is mentioned below:-

i have used CALL TRANSFORMATION and i have created structure in se11 Znee_dataset is my structure which has fields that are listed in the XML output and my problems are:-

1.) how to create CALL TRANSFORMATION ?

2.) can i use CALL TRANSFORMATION ID ?

My code:-

REPORT ZTEST_XML_CONVERSTAION.

TYPE-POOLS abap.

*Input file contents as string.XML file path where we saved the file. *Here it is saved in desktop.

*Input file with path as constant

CONSTANTS gs_file TYPE string VALUE 'C:UsersNeeru SangwanDesktopNee FileACT_GlobalExample Gatekeeper XML filesMATCREATE_11314_20111031_19344131.XML' ."'C:Documents and

"SettingsAdministratorDesktop est1.xml'.

BREAK-POINT.

*PARAMETERS : gs_file TYPE string.

*PARAMETER: FILE_NM TYPE RLGRAP-FILENAME OBLIGATORY.

*This is the structure type for the data from the XML file

TYPES: BEGIN OF ts_zeu_matmas03,

idoc TYPE Znee_dataset, "ZIDOC_TEST structure we created in SE11

END OF ts_zeu_matmas03.

  • Table for storing the XML content from file

DATA: gt_itab TYPE STANDARD TABLE OF char2048.

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

DATA: gt_zeu_matmas03 TYPE STANDARD TABLE OF ts_zeu_matmas03,

gs_zeu_matmas03 TYPE ts_zeu_matmas03.

DATA : IT_DATA_XML TYPE STANDARD TABLE OF ZNEW_DATASET WITH HEADER LINE.

DATA : XML_RESULT TYPE STRING.

  • 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.

FIELD-SYMBOLS:

type any.

  • For error handling

DATA: gs_rif_ex TYPE REF TO cx_root,

gs_var_text TYPE string,

IT_TAB TYPE FILETABLE,

GD_SUBRC TYPE I,

l_xml_table_size TYPE i.

  • Get the XML file from your client

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = gs_file

filetype = 'DAT'

IMPORTING

filelength = l_xml_table_size

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.

CALL TRANSFORMATION ID

SOURCE XML gt_itab

RESULT SOURCE = IT_DATA_XML[].

Nothing is in IT_DATA_XML[]

Please help me <removed by moderator>.

Regards,

Nee

Edited by: Thomas Zloch on Nov 15, 2011 12:33 PM

3 REPLIES 3
Read only

Former Member
0 Likes
653

Hi,

Refer this link..

http://sample-code-abap.blogspot.com/2009/05/processing-xml-with-xslt-transformation.html

Also, you can view this one also..

<link to blocked site removed by moderator>

This will really be helpful to you..

Regards,

Jhings

Edited by: Jhings on Nov 15, 2011 4:19 PM

Edited by: Thomas Zloch on Nov 15, 2011 12:33 PM

Read only

0 Likes
653

Hi Jhings,

Thanks for quick reply but i already tried those links and it was not help me when i excute my code one error message comes which says 'Incorrect element Material for XML-ABAP transformation'

I already copied my code and XML file on my post just have a look and help me <removed by moderator>.

Regards,

Nee

Moderator message: everybody is on the same priority in these forums, please avoid terms that suggest otherwise, like "it's urgent".

Edited by: Thomas Zloch on Nov 15, 2011 2:49 PM

Read only

0 Likes
653

Hi Neeru,

You can check SDN wiki for a sample code for uploading an xml file to an internal table. I would suggest you to go through the code, debug it and check how exactly it is appending the values into an internal table:-

http://wiki.sdn.sap.com/wiki/display/ABAP/UploadXMLfiletointernal+table