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

ABAP to XML using XSLT

Former Member
0 Likes
713

I's is possible to create a XML files with XLST Transformations using nested internal tables?

I want do create a XML file that represents the structure of a Sales Order (Header + Items):

TYPES: BEGIN OF s_order,

vbak TYPE vbak,

vbap TYPE vbap OCCURS 0,

END OF s_order.

DATA: gs_vbap TYPE vbap,

gt_vbap TYPE STANDARD TABLE OF vbap.

DATA: gs_order TYPE s_order,

gt_order TYPE STANDARD TABLE OF s_order.

gs_vbap-vbeln = 100.

gs_vbap-posnr = 10.

gs_vbap-matnr = 'MAT1'.

APPEND gs_vbap TO gt_vbap.

gs_vbap-posnr = 20.

gs_vbap-matnr = 'MAT2'.

APPEND gs_vbap TO gt_vbap.

gs_order-vbap = gt_vbap.

APPEND gs_order TO gt_order.

GET REFERENCE OF gt_order INTO gs_source_wa-value.

gs_source_wa-name = 'ORDER'.

APPEND gs_source_wa TO gt_source_itab.

TRY.

CALL TRANSFORMATION z_abap_to_xml

SOURCE (gt_source_itab)

RESULT XML gt_itab.

CATCH cx_root INTO gs_rif_ex.

gs_var_text = gs_rif_ex->get_text( ).

MESSAGE gs_var_text TYPE 'E'.

ENDTRY.

The XML result should be something like this:

<ORDER>

<VBELN>100</VBELN>

--- vvv ---

<VBAP>

<POSNR>10</POSNR>

<MATNR>MAT1</MATNR>

</VBAP>

<VBAP>

<POSNR>20</POSNR>

<MATNR>MAT2</MATNR>

</VBAP>

--- ^^^ ---

<ORDER>

The area between --- vvv --- and --- ^^^ --- should be dynamic, according with the number of entries of the nested internal table. I'm using the instruction "for-each" in the XSLT transformation, however that doesn't seems to work with internal tables

Any help?

Thanks in advance,

Nuno

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
579

I's is possible to create a XML files with XLST Transformations using nested internal tables?

I want do create a XML file that represents the structure of a Sales Order (Header + Items):

TYPES: BEGIN OF s_order,

vbak TYPE vbak,

vbap TYPE vbap OCCURS 0,

END OF s_order.

DATA: gs_vbap TYPE vbap,

gt_vbap TYPE STANDARD TABLE OF vbap.

DATA: gs_order TYPE s_order,

gt_order TYPE STANDARD TABLE OF s_order.

gs_vbap-vbeln = 100.

gs_vbap-posnr = 10.

gs_vbap-matnr = 'MAT1'.

APPEND gs_vbap TO gt_vbap.

gs_vbap-posnr = 20.

gs_vbap-matnr = 'MAT2'.

APPEND gs_vbap TO gt_vbap.

gs_order-vbap = gt_vbap.

APPEND gs_order TO gt_order.

GET REFERENCE OF gt_order INTO gs_source_wa-value.

gs_source_wa-name = 'ORDER'.

APPEND gs_source_wa TO gt_source_itab.

TRY.

CALL TRANSFORMATION z_abap_to_xml

SOURCE (gt_source_itab)

RESULT XML gt_itab.

CATCH cx_root INTO gs_rif_ex.

gs_var_text = gs_rif_ex->get_text( ).

MESSAGE gs_var_text TYPE 'E'.

ENDTRY.

The XML result should be something like this:

<ORDER>

<VBELN>100</VBELN>

--- vvv ---

<VBAP>

<POSNR>10</POSNR>

<MATNR>MAT1</MATNR>

</VBAP>

<VBAP>

<POSNR>20</POSNR>

<MATNR>MAT2</MATNR>

</VBAP>

--- ^^^ ---

<ORDER>

The area between --- vvv --- and --- ^^^ --- should be dynamic, according with the number of entries of the nested internal table. I'm using the instruction "for-each" in the XSLT transformation, however that doesn't seems to work with internal tables

Any help?

Thanks in advance,

Nuno

2 REPLIES 2
Read only

Former Member
0 Likes
580
Read only

Former Member
0 Likes
579

Dear Nuno,

You can perform XSLT transformations only on tables of flat structure.

You'll need to hand over both tables VBAP and VBAK to the stylesheet and create the nested XML structure within the XSLT.

Best wishes,

Jan