2009 Aug 04 1:55 PM
Hi,
I need to extract invoice with header and item (more than 1) into XML file.
So, I found [this document|http://www.heidoc.net/joomla/development-mainmenu-31/22-sapxslt/15-sapxslt] that explain how to extract from [Abap to Xml |http://www.heidoc.net/joomla/development-mainmenu-31/22-sapxslt/15-sapxslt] a simple flat with one level structure.
I'm novice with XSLT transformation language.
I'm not able to generate a loop that create for each header a list of item data.
Please, there's anyone can help me with this problem?
Any Example code?
2009 Aug 04 2:05 PM
2009 Aug 04 2:18 PM
Yes, i do a call transformation but the result is like this:
- HEADER1
- ITEM1
-HEADER1
- ITEM2
This is not correct because header is the same.
the correct result that i need is:
- HEADER1
- ITEM1
- ITEM2.
I'm on a 4.7 release.
2009 Aug 04 2:21 PM
How does the type definition of the variable looks like you are transforming?
2009 Aug 04 2:41 PM
This is the Program. <br />
TYPE-POOLS: abap.<br />
CONSTANTS gs_file TYPE string VALUE 'C:\tempo\customer.xml'.<br />
<br />
TYPES: BEGIN OF ts_person,<br />
cust_id(4) TYPE n,<br />
firstname(20) TYPE c,<br />
lastname(20) TYPE c,<br />
codfisc(16),<br />
campo1(16),<br />
END OF ts_person.<br />
Table for the XML content<br />
DATA: gt_itab TYPE STANDARD TABLE OF char2048.<br />
Table and work area for the data to fill the XML file with<br />
DATA: gt_person TYPE STANDARD TABLE OF ts_person,<br />
gs_person TYPE ts_person.<br />
Source table that contains references<br />
of the internal tables that go into the XML file<br />
<br />
DATA: gt_source_itab TYPE abap_trans_srcbind_tab,<br />
gs_source_wa TYPE abap_trans_resbind.<br />
For error handling<br />
DATA: gs_rif_ex TYPE REF TO cx_root,<br />
gs_var_text TYPE string.<br />
Fill the internal table<br />
gs_person-cust_id = '3'.<br />
gs_person-firstname = 'Bill'.<br />
gs_person-lastname = 'Gates'.<br />
gs_person-codfisc = 'ELFO1234'.<br />
gs_person-campo1 = 'TEST'. "ITEM<br />
APPEND gs_person TO gt_person.<br />
<br />
gs_person-cust_id = '3'.<br />
gs_person-firstname = 'Bill'.<br />
gs_person-lastname = 'Gates'.<br />
gs_person-codfisc = 'ELFO1234'.<br />
gs_person-campo1 = 'TEST2'. "ITEM<br />
APPEND gs_person TO gt_person.<br />
<br />
GET REFERENCE OF gt_person INTO gs_source_wa-value.<br />
gs_source_wa-name = 'IPERSON'.<br />
APPEND gs_source_wa TO gt_source_itab.<br />
<br />
GET REFERENCE OF gt_person INTO gs_source_wa-value.<br />
gs_source_wa-name = 'IRIGA'.<br />
APPEND gs_source_wa TO gt_source_itab.<br />
<br />
Perform the XSLT stylesheet<br />
TRY.<br />
CALL TRANSFORMATION z_prova<br />
SOURCE (gt_source_itab)<br />
RESULT XML gt_itab.<br />
<br />
CATCH cx_root INTO gs_rif_ex.<br />
<br />
gs_var_text = gs_rif_ex->get_text( ).<br />
MESSAGE gs_var_text TYPE 'E'.<br />
ENDTRY.<br />
The XML is not displayed.<br />
Could you help me, please?<br />
Edited by: Stefano Pastorelli on Aug 4, 2009 3:42 PM
Edited by: Stefano Pastorelli on Aug 4, 2009 3:43 PM
Edited by: Stefano Pastorelli on Aug 4, 2009 3:45 PM
Edited by: Stefano Pastorelli on Aug 4, 2009 3:47 PM
Edited by: Stefano Pastorelli on Aug 4, 2009 3:48 PM
2009 Aug 04 3:21 PM
next time please enclose the code in appropriate tags, you can find them on the right side whly creating a post.
second you should use xstring for the result xml in the transformation result.
third i can not understand the gt_source_itab, why dont you use the binding like
iperson = abapvar1 iriga = abapvar2
To avoid errors with your transforamtion z_prova first try to use transformation ID. If the xml is correct the change the xslt again to transform the xlm to your needs.
CALL TRANSFORMATION ID
SOURCE iperson = gt_person uriga = gt_person
RESULT XML xxml.
xxml should be declared like
DATA:
xxml type xstring.
As you are on 4.7 you will have problems tith xstring, the debugger cant show it in readable format. So ypou have to use string at first changing to xstring if everything is ok. Another way of cheking the xml is the function
call function 'DISPLAY_XML_STRING'
exporting
xml_string = xxml
* TITLE =
* STARTING_X = 5
* STARTING_Y = 5
exceptions
no_xml_document = 1
others = 2.
if sy-subrc > 0.
message 'Cant display XML' type 'A'.
endif.
but i dont know if this FM is available on 4.7