‎2006 May 17 2:31 PM
I have XML file and I parsed it. After that I have like this lines :
ELEMENT : flights NUM_CHILDREN: 8 ROOT: #document NAME2:
#document
ELEMENT : airline NUM_CHILDREN: 2 ROOT: #document NAME2:
flights
ATTRIBUTE: code = AA
ATTRIBUTE: name = American Airlines
ELEMENT : flight NUM_CHILDREN: 5 ROOT: #document
NAME2: airline
ATTRIBUTE: number = 0017
ELEMENT : from NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
ATTRIBUTE: airport = JFK
VALUE : NEW YORK,US NAME2: from
ELEMENT : to NUM_CHILDREN: 1 ROOT: #document NAME2:
flight
ATTRIBUTE: airport = SFO
VALUE : SAN FRANCISCO,US NAME2: to
ELEMENT : departure NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
VALUE : 110000 NAME2: departure
ELEMENT : arrival NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
VALUE : 140100 NAME2: arrival
ELEMENT : type NUM_CHILDREN: 1 ROOT: #document
NAME2: flight
VALUE : Scheduled NAME2: type
ELEMENT : flight NUM_CHILDREN: 5 ROOT: #document
How can I parse this lines in my internal table ( have flight,arrival,airport ... fields)
Thanks
‎2006 May 17 2:33 PM
hi
use this fm
<b>SMUM_XML_PARSE</b>
plz reward if useful
‎2006 May 17 2:52 PM
Hi Mehmet,
Use the following code snippet which may solve your problem. It will fetches data from XML and inturn places into Internal table.
Report XML_TO_INTERNALTABLE.
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0,
a(100) TYPE c,
END OF itab.
DATA: xml_out TYPE string .
DATA : BEGIN OF upl OCCURS 0,
f(255) TYPE c,
END OF upl.
DATA: xmlupl TYPE string .
*-Fetch Data
SELECT * FROM t001 INTO TABLE t001.
*- XML
CALL TRANSFORMATION ('ID')
SOURCE tab = t001[]
RESULT XML xml_out.
*- Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = xml_out
i_tabline_length = 100
TABLES
et_table = itab.
*-Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'BIN'
filename = 'd:\xx.xml'
TABLES
data_tab = itab.
REFRESH t001.
CLEAR t001.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\XX.XML'
filetype = 'BIN'
TABLES
data_tab = upl.
LOOP AT upl.
CONCATENATE xmlupl upl-f INTO xmlupl.
ENDLOOP.
*- XML
CALL TRANSFORMATION ('ID')
SOURCE XML xmlupl
RESULT tab = t001[].
Thanks,
Vinay
‎2006 May 18 8:58 AM
Dear Vinaykumar
Thanks for your valuable help. I have a question. You are calling your ID transformation. Can I create my own transformation type (Because my XSL file is different)
Thanks
‎2006 May 18 9:02 AM
Mehmet,
For transformation rules you need to create an XSLT program in the transaction XSLT_TOOL.You must then give this program name with the CALL TRANSFORMATION statement. Here ID is a sample SAP XSLT program.
The answer is that YES .. you can create your own XSLT program.
Please reward if helpful.
Cheers
Nishanth
‎2006 May 18 9:36 AM
Dear Nishanth
Thanks I have been creating my XSLT but my xsl file have special type. It is for Indicative Exchange Rates. First table relase Indicative Exchange Rates. Second table (in the same xsl) give me Cross Rates when I use this XSLT in my program it's give me
Runtime errors XSLT_BAD_SOURCE_CONTEXT
Exception CX_XSLT_RUNTIME_ERROR
Occurred on 18.05.2006 at 11:33:26
There is no help text for this dump
Either the text was inadvertently deleted or the release of
the kernel differs from the release of the database
Refer to the Note system for further information on this dump.
I am calling my xslt with this lines:
CALL TRANSFORMATION ('ZKUR')
SOURCE XML xmlupl
RESULT tab = zexchange[].
What is your recommend If anybody want see my XSL fiel I will send it via email. My mail mavsar$@$gmail.com (Please $)
I must this xsl file because it is Central Bank Indicative Exchange Rates file.
Thanks for all person
‎2006 May 18 12:03 PM
Mehmet,
Before calling the XSLT program make sure that you have declared the source XML file as type STRING or XSTRING.You can also pass it as an internal table which contains only CHAR type fields.
Also ensure that your XSLT program does not have any syntactic errors.
Test your XSLT program using transaction XSLT before using the same in your program.
If the extension of the source file is not XML save it as .XML before using it in the program.
Please let me know once you are done with all this.If the problem still persists paste your XML input file so that we can analyze it further.
Please reward helpful answers.
Cheers
Nishanth
‎2007 May 21 10:23 AM
Hi experts,
the result of the method SMUM_XML_PARSE is nice. So I have all the XML-elements and XML-values (also attributes) in the table:
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING xml_input = l_xml_x1
TABLES xml_table = it_result_xml
return = return
Line| Hier| Type| cname| cvalue
7 3 |A |DIRECT_DEBIT_QUALIFIER
8 4 |V |INVOICE_DATE
9 4 | |INVOICE_NUMBER
10 5 |V |NUMBER
But I want it in my own structure. Can I generate or read out "cname" and "cvalue" into my own Datatyp?
TYPES: BEGIN OF t_ap,
inv_date(8),
inv_number TYPE t_inv_number,
credit_debit_qualifier(1)
END OF t_ap.
DATA: it_ap TYPE STANDARD TABLE OF t_ap.
I also tried the CALL TRANSFORMATION method, but I get an error "No valid result context supplied". The "l_xml_x1" variable is an XSTRING and contains the XML file.
DATA: it_trans_xml TYPE abap_trans_resbind_tab,
CALL TRANSFORMATION zfi_airplus_xslt
SOURCE xml l_xml_x1
RESULT (it_trans_xml)
The xslt-programm looks like this:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/abapxml" version="1.0">
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml">
<asx:values>
<it_ap>
<xsl:for-each select="INVOICE_HEAD">
<t_ap_kopf>
<invoice_date><xsl:value-of select="INVOICE_DATE"/></invoice_date>
<t_ap_inv_num>
<number><xsl:value-of select="NUMBER"/></number>
<extension><xsl:value-of select="EXTENSION"/></extension>
<sequence><xsl:value-of select="SEQUENCE"/></sequence>
</t_ap_inv_num>
...
...
Regards,
Steffen
‎2007 May 21 10:59 AM
post the sample xml file, will come up with the xslt for the same.
‎2007 May 21 11:18 AM
hi raja,
here it is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="invoice_btm.xsl"?>
<INVOICES_BTM xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="invoice_btm.xsd">
<INVOICE_BTM>
<INVOICE_HEAD LANGUAGE="DE" DIRECT_DEBIT_QUALIFIER="NO">
<INVOICE_DATE>20040112</INVOICE_DATE>
<INVOICE_NUMBER>
<NUMBER>0306299999</NUMBER>
<EXTENSION>0</EXTENSION>
<SEQUENCE>0</SEQUENCE>
</INVOICE_NUMBER>
...
...
I also tried this
RESULT invoice_date = wa_ap-head-inv_date
invoice_number = wa_ap-head-inv_number-number
This runs trought without a error, but without a value in my "wa" too.
<b>EDIT:</b>
do i need to catch the first 3 lines in the XML file? "invoice_btm"
Regards, Steffen
‎2007 May 21 11:39 AM
The XSLT program (name:Y_XML_2_ITAB_SIMPLE)
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:template match="INVOICES_BTM">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<OUTPUT>
<xsl:for-each select="INVOICE_BTM">
<items>
<INV_DATE>
<xsl:value-of select="INVOICE_HEAD/INVOICE_DATE"/>
</INV_DATE>
<INV_NO>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/NUMBER"/>
</INV_NO>
<INV_EXT>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/EXTENSION"/>
</INV_EXT>
<INV_SEQ>
<xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/SEQUENCE"/>
</INV_SEQ>
</items>
</xsl:for-each>
</OUTPUT>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>program to test the XSLT
REPORT y_xml_2_itab_simple
NO STANDARD PAGE HEADING.
TYPES: BEGIN OF stru ,
inv_date(10) ,
inv_no(50) ,
inv_ext(10) ,
inv_seq(10) ,
END OF stru .
DATA: outtab TYPE STANDARD TABLE OF stru .
DATA: xslt_error TYPE REF TO cx_xslt_exception,
xslt_message TYPE string .
DATA: xml_string TYPE string .
CLEAR xml_string .
CONCATENATE
`<?xml version="1.0" encoding="ISO-8859-1"?>`
`<INVOICES_BTM xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="invoice_btm.xsd">`
`<INVOICE_BTM>`
`<INVOICE_HEAD LANGUAGE="DE" DIRECT_DEBIT_QUALIFIER="NO">`
`<INVOICE_DATE>20040112</INVOICE_DATE>`
`<INVOICE_NUMBER>`
`<NUMBER>0306299999</NUMBER>`
`<EXTENSION>1</EXTENSION>`
`<SEQUENCE>01</SEQUENCE>`
`</INVOICE_NUMBER>`
`</INVOICE_HEAD>`
`</INVOICE_BTM>`
`<INVOICE_BTM>`
`<INVOICE_HEAD LANGUAGE="DE" DIRECT_DEBIT_QUALIFIER="NO">`
`<INVOICE_DATE>20040113</INVOICE_DATE>`
`<INVOICE_NUMBER>`
`<NUMBER>0306299888</NUMBER>`
`<EXTENSION>2</EXTENSION>`
`<SEQUENCE>02</SEQUENCE>`
`</INVOICE_NUMBER>`
`</INVOICE_HEAD>`
`</INVOICE_BTM>`
`</INVOICES_BTM>`
INTO xml_string .
TRY .
CALL TRANSFORMATION (`Y_XML_2_ITAB_SIMPLE`)
SOURCE XML xml_string
RESULT output = outtab.
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
ENDTRY.
break-point .Regards
Raja
‎2007 May 21 1:02 PM
‎2007 May 21 1:22 PM
Sure a lot! But I already looking for the right implementation in my programm.
In my programm I upload the XML file via GUI_UPLOAD into a internal table and convert this into one big XSTRING variable. maybe this is wrong, I have to check this....
I switch this thread as answered if I can cut the gordian knot..
‎2007 May 21 1:25 PM
since you have the xml content in xstring just pass that variable to call transformation (it can handle both xstring and string)
‎2007 May 21 1:49 PM
ok, can I use a deep structure in my abap program?
something like that:
TYPES: BEGIN OF t_ap_head,
inv_date(8),
inv_number TYPE t_inv_number,
credit_debit_qualifier(1),
credit_debit_label(10),
billing_currency(3),
base_currency(3),
due_date(8),
inv_parties TYPE t_inv_parties,
inv_qualifier(4),
END OF t_ap_head.
TYPES: BEGIN OF t_ap_detail,
cust_cardnumber(30),
cust_name(30),
END OF t_ap_detail.
TYPES: BEGIN OF t_ap,
head TYPE t_ap_head,
detail TYPE t_ap_detail,
END OF t_ap.
DATA: it_ap TYPE STANDARD TABLE OF t_ap.
I cannot imagine how to declare this in the XSLT program?!?
‎2007 May 21 8:04 PM
yes its very much possible. check for sample code in these threads
https://forums.sdn.sap.com/click.jspa?searchID=2715061&messageID=2586184
‎2007 May 22 10:19 AM
alright, THANKS so much for your help.
I've made two ciritcal mistakes:
1) didn't write the ABAP Variables uppercase in the XSLT file
2) it is extremely a must have to paste the "<items>" tag....
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" version="1.0">
<xsl:template match="INVOICES_BTM">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<XML_OUTPUT>
<xsl:for-each select="INVOICE_BTM">
<items>
<HEAD>
<INV_DATE><xsl:value-of select="INVOICE_HEAD/INVOICE_DATE"/></INV_DATE>
<INV_NUMBER>
<NUMBER> <xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/NUMBER"/> </NUMBER>
<EXTENSION><xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/EXTENSION"/></EXTENSION>
<SEQUENCE> <xsl:value-of select="INVOICE_HEAD/INVOICE_NUMBER/SEQUENCE"/> </SEQUENCE>
</INV_NUMBER>
<CREDIT_DEBIT_QUALIFIER> <xsl:value-of select="INVOICE_HEAD/CREDIT_DEBIT_QUALIFIER"/></CREDIT_DEBIT_QUALIFIER>
<CREDIT_DEBIT_LABEL> <xsl:value-of select="INVOICE_HEAD/CREDIT_DEBIT_LABEL"/> </CREDIT_DEBIT_LABEL>
<BILLING_CURRENCY> <xsl:value-of select="INVOICE_HEAD/BILLING_CURRENCY"/> </BILLING_CURRENCY>
<BASE_CURRENCY> <xsl:value-of select="INVOICE_HEAD/BASE_CURRENCY"/> </BASE_CURRENCY>
<DUE_DATE> <xsl:value-of select="INVOICE_HEAD/DUE_DATE"/> </DUE_DATE>
<INV_PARTIES>
<PAYEE>
<PARTYCODE><xsl:value-of select="INVOICE_HEAD/INVOICE_PARTIES/PAYEE/PARTYCODE"/></PARTYCODE>
<ADDRESS>
<ADDRESSLINE> <xsl:value-of select="INVOICE_HEAD/INVOICE_PARTIES/PAYEE/ADDRESS/ADDRESSLINE"/></ADDRESSLINE>
<POST_CODE>
.....
.....
but now it works, also with the deep structure!
regards, steffen
‎2007 May 22 10:32 AM
glad to know.
didn't write the ABAP Variables uppercase in the XSLT file
yes the abap variable has to be in upper case.
2) it is extremely a must have to paste the "<items>" tag....
item tag is to split it into records.
Raja
‎2007 May 23 9:40 AM
Hi Raja,
i thought now I understand the xml topic but I cannot convert the multiple elements (with attributes) from the XML file into my ABAP Table.
I tried this coding but it won't work well:
....
<PARTYCODE><xsl:value-of select="INVOICE_HEAD/INVOICE_PARTIES/PAYEE/PARTYCODE"/></PARTYCODE>
<ADDRESS>
<ADDRESSLINE>
<xsl:for-each select="ADDRESSLINE">
<items>
<xsl:value-of select="INVOICE_HEAD/INVOICE_PARTIES/PAYEE/ADDRESS/ADDRESSLINE"/>
</items>
</xsl:for-each>
</ADDRESSLINE>
<POST_CODE>
...
...
<PARTYCODE>LASG</PARTYCODE>
<ADDRESS>
<ADDRESSLINE LINE="1">Company address</ADDRESSLINE>
<ADDRESSLINE LINE="2">postadd 1552</ADDRESSLINE>
<POST_CODE>
...
regards,
Steffen
‎2007 May 23 10:01 AM
where is the problem ?
getting the attribute value?
provide me the itab definition to which you want to send the xml values to and sample xml file.
‎2007 May 23 10:19 AM
TYPES: BEGIN OF t_inv_number,
number(30),
extension(3),
sequence(1),
END OF t_inv_number.
TYPES: BEGIN OF t_inv_part_address,
addressline(50),
post_code(6),
city(12),
state_code(6),
country_code(6),
country(12),
END OF t_inv_part_address.
TYPES: BEGIN OF t_inv_part_payee,
partycode(10),
address TYPE t_inv_part_address,
END OF t_inv_part_payee.
TYPES: BEGIN OF t_inv_part_invoicee,
billing_level(50),
partycode(10),
address TYPE t_inv_part_address,
END OF t_inv_part_invoicee.
TYPES: BEGIN OF t_inv_parties,
payee TYPE t_inv_part_payee,
invoicee TYPE t_inv_part_invoicee,
END OF t_inv_parties.
TYPES: BEGIN OF t_ap_head,
inv_date(8),
inv_number TYPE t_inv_number,
inv_parties TYPE t_inv_parties,
END OF t_ap_head.
DATA: it_ap TYPE STANDARD TABLE OF t_ap_head.
with this table structure and the XSLT program (posted above), the value for "addressline" is empty after running the CALL TRANSFORMATION.
here the debugger view for table. addressline is empty so I think my XSLT isn't correct.
HEAD-INV_PARTIES-PAYEE-ADDRESS-ADDRESSLINE
HEAD-INV_PARTIES-PAYEE-ADDRESS-POST_CODE 63235
HEAD-INV_PARTIES-PAYEE-ADDRESS-CITY could_be_anywhere
‎2011 Jan 06 2:23 PM