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 Using XSLT

Former Member
0 Likes
507

Hello friends,

I am trying a ABAP program (posted on SDN) to convert XML into ABAP (internal table) and not having any luck. Either it is my table/structure declaration or XSLT. Could any of you experts give me a hand with it please?

Thanks in advance..but points on help!

Here is my XML:

And my ABAP program:

REPORT ZTESTXMLREAD.

TYPE-POOLS: abap, ixml.

class cl_ixml definition load.

TYPES: BEGIN OF t_dc40,

docnum(17) TYPE C,

status(2) TYPE C,

END OF t_dc40.

TYPES: BEGIN OF t_emkt,

spras(2) TYPE C,

maktx(35) TYPE C,

END OF t_emkt.

TYPES: BEGIN OF t_emrm,

matnr(12) TYPE C,

ersda(8) TYPE C,

ernam(25) TYPE C,

emktx TYPE t_emkt,

END OF t_emrm.

TYPES: BEGIN OF t_mm,

dc40 TYPE t_dc40,

emrm TYPE t_emrm,

END OF t_mm.

DATA: l_ixml TYPE REF TO if_ixml,

l_streamfactory TYPE REF TO if_ixml_stream_factory,

l_istream TYPE REF TO if_ixml_istream.

DATA: l_filename TYPE string.

DATA: it_airplus TYPE STANDARD TABLE OF t_mm,

wa_airplus TYPE t_mm.

*Errorvariables

DATA: xslt_err TYPE REF TO cx_xslt_exception,

err_string TYPE string.

PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:Test.XML'.

START-OF-SELECTION.

  • Creating the main iXML factory

l_ixml = cl_ixml=>create( ).

  • Creating a stream factory

l_streamfactory = l_ixml->create_stream_factory( ).

  • Creating input stream

l_istream = l_streamfactory->create_istream_uri( 'file://c:Test.xml' ).

  • here we use the CALL TRANSFORMATION method which calls

TRY.

CALL TRANSFORMATION ZTestXSLT

SOURCE xml l_istream

RESULT xml_output = it_airplus

.

  • catch any error, very helpful if the XSLT isn't correct

CATCH cx_xslt_exception INTO xslt_err.

err_string = xslt_err->get_text( ).

WRITE: / 'Transformation error: ', err_string.

EXIT.

ENDTRY.

  • setting a breakpoint to watch the workarea

  • by the internal table "it_airplus"

break-point.

LOOP AT it_airplus INTO wa_airplus.

ENDLOOP.

Hello friends,

I am trying a ABAP program (posted on SDN) to convert XML into ABAP (internal table) and not having any luck. Either it is my table/structure declaration or XSLT. Could any of you experts give me a hand with it please?

Thanks in advance..but points on help!

Here is my XML:

And my ABAP program:

REPORT ZTESTXMLREAD.

TYPE-POOLS: abap, ixml.

class cl_ixml definition load.

TYPES: BEGIN OF t_dc40,

docnum(17) TYPE C,

status(2) TYPE C,

END OF t_dc40.

TYPES: BEGIN OF t_emkt,

spras(2) TYPE C,

maktx(35) TYPE C,

END OF t_emkt.

TYPES: BEGIN OF t_emrm,

matnr(12) TYPE C,

ersda(8) TYPE C,

ernam(25) TYPE C,

emktx TYPE t_emkt,

END OF t_emrm.

TYPES: BEGIN OF t_mm,

dc40 TYPE t_dc40,

emrm TYPE t_emrm,

END OF t_mm.

DATA: l_ixml TYPE REF TO if_ixml,

l_streamfactory TYPE REF TO if_ixml_stream_factory,

l_istream TYPE REF TO if_ixml_istream.

DATA: l_filename TYPE string.

DATA: it_airplus TYPE STANDARD TABLE OF t_mm,

wa_airplus TYPE t_mm.

*Errorvariables

DATA: xslt_err TYPE REF TO cx_xslt_exception,

err_string TYPE string.

PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:Test.XML'.

START-OF-SELECTION.

  • Creating the main iXML factory

l_ixml = cl_ixml=>create( ).

  • Creating a stream factory

l_streamfactory = l_ixml->create_stream_factory( ).

  • Creating input stream

l_istream = l_streamfactory->create_istream_uri( 'file://c:Test.xml' ).

  • here we use the CALL TRANSFORMATION method which calls

TRY.

CALL TRANSFORMATION ZTestXSLT

SOURCE xml l_istream

RESULT xml_output = it_airplus

.

  • catch any error, very helpful if the XSLT isn't correct

CATCH cx_xslt_exception INTO xslt_err.

err_string = xslt_err->get_text( ).

WRITE: / 'Transformation error: ', err_string.

EXIT.

ENDTRY.

  • setting a breakpoint to watch the workarea

  • by the internal table "it_airplus"

break-point.

LOOP AT it_airplus INTO wa_airplus.

ENDLOOP.

2 REPLIES 2
Read only

athavanraja
Active Contributor
0 Likes
462

check my code sample in this thread

Read only

0 Likes
462

Thank you Durairaj, as a matter of fact my program is based on your post (one that you pointed me to). For whatever reason I'm not having luck figuring it out (may be just a bit of work pressure) could you please hlep me a bit more by pointing me to where in my program code/xslt I'm going wrong? I somehow feel that it could be my table structure or xslt.

I would really appreciate it!

Thanks again,

erfan.