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
1,597

Hi,

I wrote a ABAP report to convert XML document to ABAP internal tables. I used CALL TRANSFORNATION (`zxmltoabap`) and got asXML using XSLT program. For some reason i am getting dump at statement CALL TRANSFORNATION. Its shows Runtime error as 'XML_FORMAT_ERROR' and the exception is 'CX_XSLT_FORMAT_ERROR'. But when i execute the XSLT prohrem individually it is running fine. Any ideas or suggestions will be helpfull.

My Report:

include bcciixml_decl.

include bcciixml_impl.

TYPE-POOLS: abap.

*-- starting

start-of-selection.

*-- data

data: piXML type ref to if_ixml,

pDocument type ref to if_ixml_document,

pStreamFactory type ref to if_ixml_stream_factory,

pIStream type ref to if_ixml_istream,

pParser type ref to if_ixml_parser,

pNode type ref to if_ixml_node,

pText type ref to if_ixml_text,

string type string,

count type i,

index type i,

totalSize type i,

dsn(40) type C,

xstr type xstring.

*-- internal table

*types: BEGIN OF ITAB_DATA,

  • ITAB_EMP_ID TYPE N,

  • ITAB_EMP_NAME TYPE c,

  • ITAB_CITY TYPE c,

  • ITAB_STATE TYPE c,

  • ITAB_ZIP TYPE n,

  • END OF ITAB_DATA.

data: BIND TYPE abap_trans_resbind,

EMP_ITAB TYPE abap_trans_resbind_tab.

*-- data types for fields

data: EMP_ID TYPE STRING,

EMP_NAME TYPE STRING,

EMP_CITY TYPE STRING,

EMP_STATE TYPE STRING,

EMP_ZIP TYPE STRING.

*-- read the XML document from the frontend machine

types: begin of xml_line,

data(256) type X,

end of xml_line.

data: xml_table type table of xml_line.

data: filename type string.

filename = 'C:/Documents and Settings/Desktop/testxml.xml'. "#EC NOTEXT

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = filename

FILETYPE = 'BIN' "#EC NOTEXT

IMPORTING

FILELENGTH = totalSize

TABLES

DATA_TAB = xml_table

EXCEPTIONS

OTHERS = 11

.

*if sy-subrc <> 0.

  • message w000.

  • exit.

*endif.

*-- cnreate the main factory

pixml = cl_ixml=>create( ).

*-- create the initial document

pDocument = pixml->create_document( ).

*-- create the stream factory

pStreamFactory = pixml->create_stream_factory( ).

*-- create an input stream for the table

pIStream = pStreamFactory->create_istream_itable( table = xml_table

size = totalSize ).

*-- we are creating structure for the ITAB.

BIND-NAME = 'EMPLOYEE_ID'.

GET REFERENCE OF EMP_ID INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'EMPLOYEE_NAME'.

GET REFERENCE OF EMP_NAME INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'CITY'.

GET REFERENCE OF EMP_CITY INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'STATE'.

GET REFERENCE OF EMP_STATE INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'ZIP'.

GET REFERENCE OF EMP_ZIP INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

CALL TRANSFORMATION (`ZXSLT_XML_ABAP`)

SOURCE xml = pIStream

RESULT EMP_INFO = EMP_ITAB.

My XSLT:

<xsl:transform version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="*"/>

<xsl:template match="EMPLOYEE_DATA">

<asx:abap version = "1.0" xmlns:asx = "http://www.sap.com/abapxml">

<asx:values>

<EMP_INFO>

<EMP_ITAB>

<xsl:variable name="EMP" select="EMPLOYEE_1"/>

<EMPLOYEE_ID ><xsl:value-of select="$EMP/EMPLOYEE_ID"/>

</EMPLOYEE_ID>

<EMPLOYEE_NAME><xsl:value-of select="$EMP/EMPLOYEE_NAME"/>

</EMPLOYEE_NAME>

<CITY><xsl:value-of select="$EMP/CITY"/></CITY>

<STATE><xsl:value-of select="$EMP/STATE"/>

</STATE>

<ZIP><xsl:value-of select="$EMP/ZIP"/></ZIP>

</EMP_ITAB>

</EMP_INFO>

</asx:values>

</asx:abap>

</xsl:template>

</xsl:transform>

Hi,

I wrote a ABAP report to convert XML document to ABAP internal tables. I used CALL TRANSFORNATION (`zxmltoabap`) and got asXML using XSLT program. For some reason i am getting dump at statement CALL TRANSFORNATION. Its shows Runtime error as 'XML_FORMAT_ERROR' and the exception is 'CX_XSLT_FORMAT_ERROR'. But when i execute the XSLT prohrem individually it is running fine. Any ideas or suggestions will be helpfull.

My Report:

include bcciixml_decl.

include bcciixml_impl.

TYPE-POOLS: abap.

*-- starting

start-of-selection.

*-- data

data: piXML type ref to if_ixml,

pDocument type ref to if_ixml_document,

pStreamFactory type ref to if_ixml_stream_factory,

pIStream type ref to if_ixml_istream,

pParser type ref to if_ixml_parser,

pNode type ref to if_ixml_node,

pText type ref to if_ixml_text,

string type string,

count type i,

index type i,

totalSize type i,

dsn(40) type C,

xstr type xstring.

*-- internal table

*types: BEGIN OF ITAB_DATA,

  • ITAB_EMP_ID TYPE N,

  • ITAB_EMP_NAME TYPE c,

  • ITAB_CITY TYPE c,

  • ITAB_STATE TYPE c,

  • ITAB_ZIP TYPE n,

  • END OF ITAB_DATA.

data: BIND TYPE abap_trans_resbind,

EMP_ITAB TYPE abap_trans_resbind_tab.

*-- data types for fields

data: EMP_ID TYPE STRING,

EMP_NAME TYPE STRING,

EMP_CITY TYPE STRING,

EMP_STATE TYPE STRING,

EMP_ZIP TYPE STRING.

*-- read the XML document from the frontend machine

types: begin of xml_line,

data(256) type X,

end of xml_line.

data: xml_table type table of xml_line.

data: filename type string.

filename = 'C:/Documents and Settings/Desktop/testxml.xml'. "#EC NOTEXT

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = filename

FILETYPE = 'BIN' "#EC NOTEXT

IMPORTING

FILELENGTH = totalSize

TABLES

DATA_TAB = xml_table

EXCEPTIONS

OTHERS = 11

.

*if sy-subrc <> 0.

  • message w000.

  • exit.

*endif.

*-- cnreate the main factory

pixml = cl_ixml=>create( ).

*-- create the initial document

pDocument = pixml->create_document( ).

*-- create the stream factory

pStreamFactory = pixml->create_stream_factory( ).

*-- create an input stream for the table

pIStream = pStreamFactory->create_istream_itable( table = xml_table

size = totalSize ).

*-- we are creating structure for the ITAB.

BIND-NAME = 'EMPLOYEE_ID'.

GET REFERENCE OF EMP_ID INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'EMPLOYEE_NAME'.

GET REFERENCE OF EMP_NAME INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'CITY'.

GET REFERENCE OF EMP_CITY INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'STATE'.

GET REFERENCE OF EMP_STATE INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

BIND-NAME = 'ZIP'.

GET REFERENCE OF EMP_ZIP INTO BIND-VALUE.

APPEND BIND TO EMP_ITAB.

CALL TRANSFORMATION (`ZXSLT_XML_ABAP`)

SOURCE xml = pIStream

RESULT EMP_INFO = EMP_ITAB.

My XSLT:

<xsl:transform version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="*"/>

<xsl:template match="EMPLOYEE_DATA">

<asx:abap version = "1.0" xmlns:asx = "http://www.sap.com/abapxml">

<asx:values>

<EMP_INFO>

<EMP_ITAB>

<xsl:variable name="EMP" select="EMPLOYEE_1"/>

<EMPLOYEE_ID ><xsl:value-of select="$EMP/EMPLOYEE_ID"/>

</EMPLOYEE_ID>

<EMPLOYEE_NAME><xsl:value-of select="$EMP/EMPLOYEE_NAME"/>

</EMPLOYEE_NAME>

<CITY><xsl:value-of select="$EMP/CITY"/></CITY>

<STATE><xsl:value-of select="$EMP/STATE"/>

</STATE>

<ZIP><xsl:value-of select="$EMP/ZIP"/></ZIP>

</EMP_ITAB>

</EMP_INFO>

</asx:values>

</asx:abap>

</xsl:template>

</xsl:transform>

8 REPLIES 8
Read only

athavanraja
Active Contributor
0 Likes
1,188

as a first step copy/paste the generated xml into a notepad save it as local xml file and open it in a browser, if it is not a valid format, IE will throw a error, first you need to fix it.

From the error it looks like that the XML file is not in valid format.

Regards

Raja

Read only

0 Likes
1,188

check this link for sample code.

Regards

Raja

Read only

0 Likes
1,188

Hi Raja,

Thank you very much. I tested my XSLT code by saving it as XML file. I did not get IE error while opening it. Looks like the XSLT program is correct. When i implemented the try...catch code in my program looking the sample code. i am getting the error saying

ERROR:

'ABAP XML formating error in XML node of type "element", name: "abap" '.

ALso i copied the sample code as it is. I am trying to figure out what values should i give in SELECTION-SCREEN PARAMETERS. I will update you once i could execute the code.

Thanks,

Karuna.

Read only

0 Likes
1,188

Not the XSLT program, you need to save the generated XML file into a local file and open it with IE. Its the format error of the XML file.

as for the sample program , you need to provide country name and your proxy details.

Regards

Raja

Read only

0 Likes
1,188

Hi,

I checked my data file(XML) and opened the same in IE. I was able to open it with out any error.

Thanks,

Karuna.

Read only

0 Likes
1,188

Hi Karuna,

did you solve your problem?

Regards,

Johannes

Read only

Former Member
0 Likes
1,188

If all the checks were o.k.

it may help to split the transformation

(I don't know why, so please ask someone from SAP why this makes a difference)

Replace

CALL TRANSFORMATION (`ZXSLT_XML_ABAP`)

SOURCE xml = pIStream

RESULT EMP_INFO = EMP_ITAB.

by

data: lv_string TYPE string.

CALL TRANSFORMATION (`ZXSLT_XML_ABAP`)

SOURCE xml = pIStream

RESULT XML lv_string.

CALL TRANSFORMATION id

SOURCE XML lv_string

RESULT EMP_INFO = EMP_ITAB.

Read only

Former Member
0 Likes
1,188

Change trying the declaration part of Result table

instead  of  DATA :result_table TYPE STANDARD TABLE OF char2048.

change it to

DATA :result_table TYPE STANDARD TABLE OF x255.

i hope it will work