Creating Simple transformation for an XML data having deep structure
Hi
I have the following XML structure..
<REQUESTS>
<REQUESTNAME>REQ123</REQUESTNAME>
<REQUESTID>1234</REQUESTID>
<CITY>NEWYORK</CITY>
<ZIPCODE>123456</ZIPCODE>
<COMPETENCIES>
<LANGUAGES>
<COMPETENCY>
<SKILL>SAP</SKILL>
<PROFICIENCY>TEST</PROFICIENCY>
<SKILL>JAVA</SKILL>
<PROFICIENCY>TEST123</PROFICIENCY>
(here we may have any number of records for SKILL&PROFICIENCY...)*
</COMPETENCIES>
</LANGUAGES>
</COMPETENCY>
</REQUESTS>
My requirement is to read the above data from an URL and push it into an internal table.
For this I'm trying to use Simple transformations but I'm facing difficulty in doing this.
Can you pl. guide me how to create the transformation and the corresponding code for this.
Best Regards
Anil
Hi
Here is the actual XML structure..
- <REQUEST>
<COUNTRY />
<ADDRESS />
<CITY />
<ASSIGNTYPE>IP</ASSIGNTYPE>
<CHARGETYPE>CH</CHARGETYPE>
<REMOTEALLOWED>Y</REMOTEALLOWED>
<SALESRATE>EUR</SALESRATE>
<SECURITY>NO</SECURITY>
<TRAVELEXP>Y</TRAVELEXP>
<MAXDAILYRATE />
<CREDENTIALS />
<EXPENDDATE />
<NEWENDDATE />
<NEWEXPENDDATE />
<REPLYBEFORE>2010-11-30</REPLYBEFORE>
<STARTDATE>2010-01-01</STARTDATE>
<ENDDATE>2010-12-31</ENDDATE>
<GCMTYPE>PM</GCMTYPE>
<GCMLEVELFROM>02</GCMLEVELFROM>
<GCMLEVELTO>08</GCMLEVELTO>
<LOCATION>FR43</LOCATION>
<MOBILITY>04</MOBILITY>
<ZIPCODE />
- <COMPETENCIES>
- <LANGUAGES>
- <COMPETENCY>
<SKILL>01106034</SKILL>
<PROFICIENCY>005103</PROFICIENCY>
</COMPETENCY>
</LANGUAGES>
- <ACTIVITIES>
- <COMPETENCY>
<SKILL>01105500</SKILL>
<PROFICIENCY>004507</PROFICIENCY>
</COMPETENCY>
</ACTIVITIES>
- <BUSINESS>
- <COMPETENCY>
<SKILL>01105729</SKILL>
<PROFICIENCY>004605</PROFICIENCY>
</COMPETENCY>
</BUSINESS>
- <INDUSTRIES>
- <COMPETENCY>
<SKILL>01105491</SKILL>
<PROFICIENCY>004901</PROFICIENCY>
</COMPETENCY>
</INDUSTRIES>
- <METHODS>
- <COMPETENCY>
<SKILL>01105591</SKILL>
<PROFICIENCY>004805</PROFICIENCY>
</COMPETENCY>
</METHODS>
- <OFFERINGS>
- <COMPETENCY>
<SKILL>01105840</SKILL>
<PROFICIENCY>005002</PROFICIENCY>
</COMPETENCY>
</OFFERINGS>
- <PRODUCTS>
- <COMPETENCY>
<SKILL>01107304</SKILL>
<PROFICIENCY>004703</PROFICIENCY>
</COMPETENCY>
</PRODUCTS>
</COMPETENCIES>
<CANDIDATES />
</REQUEST>
Here..... <SKILL></SKILL> <PROFICIENCY></PROFICIENCY> can be more than 1 entry...
For this I have created a simple transformation like below..
I have used the tcode 'XSLT_TOOL '..
In SE11 I have created a Table type 'ZCOMPETENCIES' which is having a line type 'ZLANGS'.
ZLANGS is a structure which has another structure called 'ZCOMPETENCY' and this 'ZCOMPETENCY' is having fields
SKILL & PROFICIENCY.
I have used the wizard button which u can find 'XSLT_TOOL '.. and provided the table type ZCOMPETENCIES' and it has automatically created the following transformation...
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root name="ROOT" type="?"/>
<tt:root name="COMPETENCIES" type="ddic:ZCOMPETENCIES"/>
<tt:template>
<COMPETENCIES>
<tt:loop ref=".COMPETENCIES">
<ZLANGS>
<COMPETENCY>
<SKILL tt:value-ref="COMPETENCY.SKILL"/>
<PROF tt:value-ref="COMPETENCY.PROF"/>
</COMPETENCY>
</ZLANGS>
</tt:loop>
</COMPETENCIES>
</tt:template>
</tt:transform>
I have written following code to get the data
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = gs_file
CHANGING
data_tab = gt_itab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
GET REFERENCE OF gt_person INTO gs_result_xml-value.
gs_result_xml-name = 'COMPETENCIES'.
APPEND gs_result_xml TO gt_result_xml.
TRY.
CALL TRANSFORMATION ZTEST_TRAN
SOURCE XML gt_itab
RESULT (gt_result_xml).
CATCH cx_root INTO gs_rif_ex.
gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.
ENDTRY.
Please let me know if you need any further details..
Best Regards
Anil
Similar Messages
-
To create a variant for a selection screen having invisible fields
Hello All
I am facing a peculiar problem. I have a screen for the program RSEIDOCB in which the following fields are hidden:
TAOUTPR FOR EDIDC-STATUS NO-DISPLAY,
STAINPR FOR EDIDC-STATUS NO-DISPLAY,
STAOUTRS FOR EDIDC-STATUS NO-DISPLAY,
STAINTA FOR EDIDC-STATUS NO-DISPLAY,
STAOUTES FOR EDIDC-STATUS NO-DISPLAY,
STAINTD FOR EDIDC-STATUS NO-DISPLAY,
STAOUTST FOR EDIDC-STATUS NO-DISPLAY,
STAOUTDT FOR EDIDC-STATUS NO-DISPLAY,
STAINBK FOR EDIDC-STATUS NO-DISPLAY,
STAOUTEI FOR EDIDC-STATUS NO-DISPLAY,
STAINEI FOR EDIDC-STATUS NO-DISPLAY,
STAOUTEX FOR EDIDC-STATUS NO-DISPLAY,
STAINEA FOR EDIDC-STATUS NO-DISPLAY,
STAOUTDS FOR EDIDC-STATUS NO-DISPLAY,
STAINDS FOR EDIDC-STATUS NO-DISPLAY.
I want to create a variant for the above program having values for the fields. These fields are basically for specifying the various status of the idocs. I am unable to do to so at the moment. Please help me out. Suitable points will be provided.
Regards
AnkitHi Ankit
Follow these steps..
1. in SE38 enter Program name 'RSEIDOCB'.
2. Click on variants button
3. enter variant name click on create
4. in selection screen enter default values
5. Click on attributes
4. Enter meaning
5. Press Shft + F4
6. Bottom of Screen will popup invisible fields
7. go down to screen
8. select field and click on selection variables button
(you to have to tick selection variable check box)
9. here click on down arrow button very next to field
10.you can choose values from list and assign to field.
then save variant.
Message was edited by:
Perez C -
Simple Transformation for XML created by Excel
Hello,
Excel can produce XML files quite easily in this documented format:
http://msdn.microsoft.com/en-us/library/aa140062(office.10).aspx
(in excel: file --> save as and choose XML)
Does someone has an idea of how I can read this XML using a Simple Transformation in ABAP?
Example: if this is an excel sheet with 3 columns and 3 lines
¦----
¦
¦ PERNR ¦ BEGDA ¦ ANZHL ¦
¦----
¦
¦ 12346 ¦ 20.02.2009 ¦15 ¦
¦----
¦
¦ 2356 ¦ 25.02.2009 ¦12 ¦
¦----
¦
this is the XML
The goal would be to transform this XML into an internal table. Any idea is appreciated.
Koen Van LoockeHi Keon,
Please find the below link
[Help|http://help.sap.com/abapdocu/en/ABAPCALL_TRANSFORMATION.htm]
[Help|http://help.sap.com/abapdocu/en/ABENABAP_ST.htm]
Please find the code below
[Code|https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/exportingdatatoExcel-XMLtotherescue]
Thanks
Kalyan -
How to create an XQuery for an XML type data source
Hi,
1.I have data contained in an XML format.
Hence I have created a physical data source for XML type data.
2.I have created a logical view to broker data from several disparate physical data sources.I have called this as UnifiedView.
3.I have created a function called getUnifiedView() to obtain data from all the physical sources
4.Upto this point, I have not faced any problems.
5.However when i try writing a simple XQuery for the physical XML datasource such as
$Sh-data/PublicIdentifiers/MSISDN="1234567"
I get result as (For example):
<HSS>
<MSISDN> 1234567 111111 222222 </MSISDN>
</HSS>
Could you please help me getting the where clause output?
I have attached the schema and XML files used for further information.
Regards
VidyaHi mReiche,
I later on resolved the previously mentioned error and try out the XQuery as suggested by you.
for $MSISDN in ns0:Sh-data()/PublicIdentifiers/MSISDN
where $MSISDN="1234567"
return
<HSS>
<MSISDN>{data($MSISDN)}</MSISDN>
</HSS>
It works! Thanks.
Now i am trying to retrieve data from 2 XML documents and an LDAP query.
I have the following data sources:
1.LDAP queried by Java Function
2.HSS xml
3.Presence xml
I want to match the telephoneNumber of the LDAP with MSISDN in the HSS.xml.
Next i want to match the SIP_URI in the HSS.xml with Contact of the Presence.xml
Given below is the XQuery which i have written to achieve the above:
for $x0 in ns5:FindDN($str_mailId)
for $Sh-Data in ns2:Sh-Data()
where $x0 = $Sh-Data/PublicIdentifiers/MSISDN
for $presence in ns3:presence()
where $Sh-Data/Sh-IMS-Data/SCSCFName = $presence/ns4:tuple/ns4:contact
return
On executing this XQuery i am getting the following error:
java.lang.NullPointerException: null
at weblogic.xml.query.types.XQueryAtomicType.commonSuperTypeOf(XQueryAtomicType.java:150)
at weblogic.xml.query.types.XQueryType.comparisonTypeOf(XQueryType.java:324)
at weblogic.xml.query.runtime.compare.GeneralAtomicComparison.compare(GeneralAtomicComparison.java:50)
at weblogic.xml.query.runtime.compare.ComparisonIterator.fetchNext(ComparisonIterator.java:50)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.logic.BoolEffValue.exec(BoolEffValue.java:51)
at weblogic.xml.query.runtime.logic.BoolEffValue.fetchNext(BoolEffValue.java:47)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.core.IfThenElse.fetchNext(IfThenElse.java:79)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.core.CountMapIterator.fetchNext(CountMapIterator.java:162)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.core.CountMapIterator.fetchNext(CountMapIterator.java:162)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.sequences.Exists.fetchNext(Exists.java:40)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.core.IfThenElse.fetchNext(IfThenElse.java:79)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.core.LetIterator.fetchNext(LetIterator.java:133)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.core.LetIterator.fetchNext(LetIterator.java:133)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.querycide.QueryAssassin.fetchNext(QueryAssassin.java:54)
at weblogic.xml.query.iterators.GenericIterator.peekNext(GenericIterator.java:151)
at weblogic.xml.query.runtime.qname.InsertNamespaces.fetchNext(InsertNamespaces.java:161)
at weblogic.xml.query.iterators.GenericIterator.next(GenericIterator.java:113)
at weblogic.xml.query.runtime.core.QueryIterator.fetchNext(QueryIterator.java:127)
at weblogic.xml.query.iterators.GenericIterator.hasNext(GenericIterator.java:134)
at weblogic.xml.query.xdbc.util.Serializer.serializeItems(Serializer.java:142)
at com.bea.ld.server.QueryInvocation.getResult(QueryInvocation.java:461)
at com.bea.ld.EJBRequestHandler.executeFunction(EJBRequestHandler.java:346)
at com.bea.ld.ServerBean.executeFunction(ServerBean.java:108)
Please find attached the XML documents which i am using.
Could you pls let me know how to resolve this. -
Simple Transformation - ABAP 2 XML
Dear all,
Finally I was able to transform an internal table to xml using ST. The question is: Can I create different structured XML-files using the same (structured) internal table. Or is there some kind of a 1:1 relationship (between an ITAB structure + XML structure)?
1) Data declaration
TYPES: BEGIN OF ty_curr,
tcurr TYPE tcurr_curr,
gdatu TYPE gdatu_inv,
ukurs TYPE ukurs_curr.
TYPES: END OF ty_curr.
DATA: gt_tcurr TYPE TABLE OF ty_curr.
2) Data selection
Select * into corresponding fields of table gt_tcurr from tcurr where...
3) Transformation ABAP 2 XML
CALL TRANSFORMATION z_tcurr
SOURCE root = gt_tcurr
RESULT XML g_xml_string.
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<tt:serialize>
<rates>
<tt:loop name="line" ref=".ROOT">
<currency>
<tt:value ref="$line.tcurr"/>
</currency>
<date>
<tt:value ref="$line.gdatu"/>
</date>
<rate>
<tt:value ref="$line.ukurs"/>
</rate>
</tt:loop>
</rates>
</tt:serialize>
</tt:template>
</tt:transform>
Result (XML)
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<currency>USD</currency>
<date>01.01.2010</date>
<rate>-1.1868</rate>
<currency>EUR</currency>
<date>01.01.2010</date>
<rate>-1.1791</rate>
<currency>USD</currency>
<date>02.01.2010</date>
<rate>-1.1864</rate>
<currency>EUR</currency>
<date>02.01.2010</date>
<rate>-1.1864</rate>
</rates>:
so far so good... BUT; if I want to get another XML structure
Example 1) -> sorted by currency
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<currency>USD
<date>01.01.2010</date>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<rate>-1.1868</rate>
</currency>
<currency>EUR
<date>01.01.2010</date>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<rate>-1.1868</rate>
</currency>
</rates>
Example 2) -> sored by date
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<date>01.01.2010</date>
<currency>USD</currency>
<rate>-1.1868</rate>
<currency>EUR</currency>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<currency>USD</currency>
<rate>-1.1868</rate>
<currency>EUR</currency>
<rate>-1.1868</rate>
</rates>
How can I achieve output example 1+2 using the same internal table as a source? Is this possible? I guess this can be solved within the transformation, right? Any help appreciated.
Best regards
BennoThanks for all answers so far. Changing the sequence is not a "problem". What I want to achieve is to change hierarchy of the xml. I'll try to explain again with a simple example:
ITAB (structure):
name; birthday; ***; first name
ITAB (content):
Smith; 01.01.1970; M; Paul
Smith; 01.01.1970; F; Stefanie
Smith; 01.02.1980; F; Barbara
White; 01.02.1980; M; Steve
I want to pass the itab exactly the way it is (ok, sorting is allowed). Question: Can I achieve the following XML's using ST? I guess/hope this can be solved with variables/groups/condition statements within the transformation coding?
Example xml- 1) Sorted/Grouped by Name/***
<person>
<name>Smith
<***>M
<birthday>01.01.1970</birthday><first name>Paul</first name>
</***>
<***>F
<birthday>01.01.1970</birthday><first name>Stefanie</first name>
<birthday>01.02.1980</birthday><first name>Barbara</first name>
</***>
</name>
<name>White
<***>M
<birthday>01.02.1980</birthday><first name>Steve</first name>
</***>
</name>
</person>
Exampe xml-2 ) Sorted/Grouped by Birthday (Names only)
<person>
<birthday>01.01.1970
<first name>Paul</first name>
<first name>Stefanie</first name>
</birthday>
<birthday>01.02.1980
<first name>Barbara</first name>
<first name>Steve</first name>
</birthday>
</person> -
Creating an XML From a Deep Structure using XSL Transformation
Hi ABAPers,
I have a requirement to use XSL Transformations on an ABAP deep type structure.
Currently i have an API that fills in this deep structure and by using CALL TRANSFORMATION ID.... i will get the BIG XML having having 100s of nodes . But actualy form the deep structure i need only some NODES (say 50)... So i tried writing an XSLT
in the transaction STRANS.. but on using this TRANSFORMATION which i wrote i am getting an error messgae like INVALID XML...
Am i going in right track or is there a good solution...
My sample transformation is as below...
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:value-of select="DATA/NODE_ELEMENTS/UUID_KEY/UUID"/>
<xsl:value-of select="DATA/NODE_ELEMENTS/SEMANTICAL_NAME"/>
<xsl:value-of select="DATA/NODE_ELEMENTS/STRUCT_CAT"/>
<xsl:value-of select="DATA/NODE_ELEMENTS/USAGE_CAT"/>
<xsl:value-of select="DATA/NODE_ELEMENTS/RESTRICTED_IND"/>
<xsl:value-of select="VALUES/DATA/NODE_ID"/>.
</xsl:template>
</xsl:transform>
Please help me in solving this issue....
Thanks,
Linda.Hi Linda,
I am replying based on your sample code.
Try the below following suggestions.
here 'GRPHDR' is the node where I am selecting the data.
IGRPHDR is the name of the reference.
First calling the transformation in you program.
TYPES: BEGIN OF tl_hdr,
msgid(20) TYPE c,
END OF tl_hdr.
DATA : t_hdr TYPE STANDARD TABLE OF tl_hdr.
GET REFERENCE OF t_hdr INTO l_result_xml-value.
l_result_xml-name = 'IGRPHDR'.
APPEND l_result_xml TO t_result_xml.
TRY.
CALL TRANSFORMATION yfi_xml_read
SOURCE XML it_xml_data
RESULT (t_result_xml).
CATCH cx_root INTO l_rif_ex.
l_var_text = l_rif_ex->get_text( ).
l_bapiret-type = 'E'.
l_bapiret-message = l_var_text.
APPEND l_bapiret TO errormsgs.
EXIT.
ENDTRY.
in XSL transformation
First write a block of statement to specify from which node you are taking the data.
No matter it is a node or sub-node.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<IGRPHDR> " reference name of internal table
<xsl:apply-templates select="//GrpHdr"/>
</IGRPHDR>
</asx:values>
</asx:abap>
</xsl:template>
Next select the data from the nodes under the nodes specified in the transformation.
here msgid is the field i am selecting for value.
<xsl:template match="GrpHdr">
<item>
<MSGID> " field in the internal table t_hdr where data has to go
<xsl:value-of select="MsgId"/>
</MSGID>
</item>
</xsl:template>
reply back if further clarification is needed.
Thanks and regards,
Kannan N -
CPO XSL Transform for CPSC Form data with Grid
Does anyone have an XSL Transform worked out that conveniently parses the CPSC Form output from Service Link when it has a grid in it?
For example the data from CPSC Service Link might look like:
<root>
<Common>
<Action ClassID="">Some Action</Action>
<RequisitionID>123</RequisitionID>
</Common>
<Attributes/>
<FormData>
<Dictionary.Field>Some Data</Dictionary.Field>
<DictionaryWithGrid-1.Field1>somevalue</DictionaryWithGrid-1.Field1>
<DictionaryWithGrid-1.Field2>someothervalue</DictionaryWithGrid-1.Field2>
<DictionaryWithGrid-1.Field3>yetanothervalue</DictionaryWithGrid-1.Field3>
<DictionaryWithGrid-2.Field1>somevalue2</DictionaryWithGrid-2.Field1>
<DictionaryWithGrid-2.Field2>someothervalue2</DictionaryWithGrid-2.Field2>
<DictionaryWithGrid-2.Field3>yetanothervalue2</DictionaryWithGrid-2.Field3>
</FormData>
</root>
So the desired output would be
<Row>
<Field1>somevalue</Field1>
<Field2>someothervalue</Field2>
<Field3>yetanothervalue</Field3>
</Row>
<Row>
<Field1>somevalue2</Field1>
<Field2>someothervalue2</Field2>
<Field3>yetanothervalue2</Field3>
</Row>
I'm having difficulty getting the right XSL select when the tag is something like 'DictionaryWithGrid-#.Field'.
Thanks!That worked great, Svetlana! Thank you very much for the help.
I made some slight mods to make it even more portable and intuitive for XSL/XML beginners.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<!-- Replace CHANGEME below with the name of the CPSC Form Dictionary to transform -->
<xsl:variable name="Dictionary">CHANGEME</xsl:variable>
<xsl:template match="root">
<Table>
<xsl:call-template name="ProcessOne">
<xsl:with-param name="pos" select="1" />
</xsl:call-template>
</Table>
</xsl:template>
<xsl:template name="ProcessOne">
<xsl:param name="pos" />
<xsl:variable name="RowName" select="concat($Dictionary, '-', $pos)" />
<xsl:if test="FormData/*[starts-with(name(), $RowName)] != ''">
<Row>
<xsl:for-each select="FormData/*[starts-with(name(), $RowName)]">
<xsl:if test="starts-with(name(.), $RowName)">
<xsl:variable name="FieldName" select="substring-after(name(.), '.')"/>
<xsl:element name="{$FieldName}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</Row>
<xsl:call-template name="ProcessOne">
<xsl:with-param name="pos" select="number($pos+1)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet> -
Script for parsing xml data and inserting in DB
Thank you for reading.
I have the following example XML in an XML file. I need to write a script that can insert this data into an Oracle table. The table does not have primary keys. The data just needs to be inserted.
I do not have xsd file in this scenario. Please suggest how to modify Method 1 https://community.oracle.com/thread/1115266?tstart=0 mentioned so that I can call the XML mentioned below and insert into a table
Method 1
Create or replace procedure parse_xml is
l_bfile BFILE;
l_clob CLOB;
l_parser dbms_xmlparser.Parser;
l_doc dbms_xmldom.DOMDocument;
l_nl dbms_xmldom.DOMNodeList;
l_n dbms_xmldom.DOMNode;
l_file dbms_xmldom.DOMNodeList;
l_filen dbms_xmldom.DOMNode;
lv_value VARCHAR2(1000);
l_ch dbms_xmldom.DOMNode;
l_partname varchar2(100);
l_filename varchar2(1000);
l_temp VARCHAR2(1000);
TYPE tab_type IS TABLE OF tab_software_parts%ROWTYPE;
t_tab tab_type := tab_type();
BEGIN
l_bfile := BFileName('DIR1', 'SoftwareParts.xml');
dbms_lob.createtemporary(l_clob, cache=>FALSE);
dbms_lob.open(l_bfile, dbms_lob.lob_readonly);
dbms_lob.loadFromFile(dest_lob => l_clob, src_lob => l_bfile, amount => dbms_lob.getLength(l_bfile));
dbms_lob.close(l_bfile);
dbms_session.set_nls('NLS_DATE_FORMAT','''DD-MON-YYYY''');
l_parser := dbms_xmlparser.newParser;
dbms_xmlparser.parseClob(l_parser, l_clob);
l_doc := dbms_xmlparser.getDocument(l_parser);
dbms_lob.freetemporary(l_clob);
dbms_xmlparser.freeParser(l_parser);
l_nl := dbms_xslprocessor.selectNodes(dbms_xmldom.makeNode(l_doc),'/PartDetails/Part');
FOR cur_emp IN 0 .. dbms_xmldom.getLength(l_nl) - 1 LOOP
l_n := dbms_xmldom.item(l_nl, cur_emp);
t_tab.extend;
dbms_xslprocessor.valueOf(l_n,'Name/text()',l_partname);
t_tab(t_tab.last).partname := l_partname;
l_file := dbms_xslprocessor.selectNodes(l_n,'Files/FileName');
FOR cur_ch IN 0 .. dbms_xmldom.getLength(l_file) - 1 LOOP
l_ch := dbms_xmldom.item(l_file, cur_ch);
lv_value := dbms_xmldom.getnodevalue(dbms_xmldom.getfirstchild(l_ch));
if t_tab(t_tab.last).partname is null then t_tab(t_tab.last).partname := l_partname; end if;
t_tab(t_tab.last).filename := lv_value;
t_tab.extend;
END LOOP;
END LOOP;
t_tab.delete(t_tab.last);
FOR cur_emp IN t_tab.first .. t_tab.last LOOP
if t_tab(cur_emp).partname is not null and t_tab(cur_emp).filename is not null then
INSERT INTO tab_software_parts
VALUES
(t_tab(cur_emp).partname, t_tab(cur_emp).filename);
end if;
END LOOP;
COMMIT;
dbms_xmldom.freeDocument(l_doc);
EXCEPTION
WHEN OTHERS THEN
dbms_lob.freetemporary(l_clob);
dbms_xmlparser.freeParser(l_parser);
dbms_xmldom.freeDocument(l_doc);
END;
<TWObject className="TWObject">
<array size="240">
<item>
<variable type="QuestionDetail">
<questionId type="String"><![CDATA[30]]></questionId>
<questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
<country type="String"><![CDATA[GB]]></country>
<questionText type="String"><![CDATA[Please indicate]]></questionText>
<optionType type="String"><![CDATA[RadioButton]]></optionType>
<answerOptions type="String[]">
<item><![CDATA[Yes]]></item>
<item><![CDATA[No]]></item>
</answerOptions>
<ruleId type="String"><![CDATA[CRP_GB001]]></ruleId>
<parentQuestionId type="String"></parentQuestionId>
<parentQuestionResp type="String"></parentQuestionResp>
</variable>
</item>
<item>
<variable type="QuestionDetail">
<questionId type="String"><![CDATA[40]]></questionId>
<questionType type="questionType"><![CDATA[COUNTRY]]></questionType>
<country type="String"><![CDATA[DE]]></country>
<questionText type="String"><![CDATA[Please indicate]]></questionText>
<optionType type="String"><![CDATA[RadioButton]]></optionType>
<answerOptions type="String[]">
<item><![CDATA[Yes]]></item>
<item><![CDATA[No]]></item>
</answerOptions>
<ruleId type="String"><![CDATA[CRP_Q0001]]></ruleId>
<parentQuestionId type="String"></parentQuestionId>
<parentQuestionResp type="String"></parentQuestionResp>
</variable>
</item>
</array>
</TWObject>Reposted as
Script to parse XML data into Oracle DB -
Simple Transformation ST, upload xml file to internal table
Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens?Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens? -
Create Report with CR4E and XML Data Source
Hi all,
I have a problem when create a report with CR4E that should use a XML data source. It is not possible to choose fields from the field explorer, because ther are no fields from the XML-file. Is there a general problem when using an ODA data source in CR4E? At the moment I can only create reports with a database as data source.
Please help me with a tip.
Thanks
ArnoldHi,
After Installing CR4E Version 2 the code snippet for creating a XML-report not works as JSP. Has anywhere a hint to resolve the problem or a complete JSP-file?
reportClientDocument = new ReportClientDocument();
java.lang.NoClassDefFoundError: com/crystaldecisions/reports/common/data/CrystalResultSet
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument.<init>(Unknown Source)
org.apache.jsp.XMLDataSource_jsp._jspService(XMLDataSource_jsp.java:64)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Thanks
Arnold Meier -
Help required in building up the Java Bean for an XML data
Hi ,
I want to build a Java bean which will actually represent an xml data . The class will be named as User and it will typically represent the data in the follwing xml:
<user>
<cwsId>barbete</cwsId>
<firstName>William</firstName>
<lastName>Barber</lastName>
<status>true</status>
<role>
<roleCode>1000000177</roleCode>
<roleName>Customer Administrator</roleName>
</role>
<language>en</language>
<country>US</country>
<preferences>
<equipmentGroup>2717</equipmentGroup>
<dateFormat>MON-dd-yyyy</dateFormat>
<timeFormat>HH:MI AM</timeFormat>
<timeZone>-12:00</timeZone>
<daylightSavings>Y</daylightSavings>
<location>NC</location>
<recordsPerPage>10</recordsPerPage>
<historyPeriod>3</historyPeriod>
<distanceUnit>MILE</distanceUnit>
<fuelUnit>G</fuelUnit>
<unitIdDisplay>E</unitIdDisplay>
<smuUpdate>W</smuUpdate>
<countries>
<country>
<countryCode>GB</countryCode>
<countryName>UNITED KINGDOM</countryName>
</country>
<country>
<countryCode>US</countryCode>
<countryName>UNITED STATES</countryName>
</country></countries>
</preferences>
</user>
Now for single child nodes like cwsId of the main user node i have kept properties like
private String cwsId;
But i am not sure as to how to represent the nodes which contain subnodes like "preferences"node. Any ideas?What is the standard practice?One thing you could do is create an object model first, which will contain all the data for your user.
then all you need in the bean is a Hashtable with the name of the user as a key, and the user-object (which is actually the complete object model) as a value.
with the XML stated by you, you would get an object model something like this:
Class User
String cwsid;
String firstName;
ArrayList<Role> roles = new ArrayList<Role>(); //I'm assuming a user can have more then one role.
ArrayList<Country> countries = new ArrayList<Country>();
class Role {
String code;
String name;
class Country {
String code;
String name;
}And so on for all the varioous elemets of your XML. -
Report design for hierarchical xml data
I need to create a report that shows hierarchical xml data. I already have an xml saved to a database. How would I go bout creating a design for such a report? Should I be doing groups on every parent with children? Any example?
ThanksHi markgoldin,
I tested the issue in my local machine by following steps:
1. Created a table and store the xml into the table with the following query:
CREATE TABLE xmlTbl (id INT, xmlVal xml);
INSERT INTO xmlTbl values(1,
'<Customers>
<Customer ID="11">
<FirstName>Bobby</FirstName>
<LastName>Moore</LastName>
</Customer>
<Customer ID="20">
<FirstName>Crystal</FirstName>
<LastName>Hu</LastName>
</Customer>
</Customers>'
2. Created a stored procedure to retrieve data from the table with the following query:
create procedure xml_report
as
DECLARE @xmlDoc XML;
SELECT @xmlDoc = xmlVal FROM xmlTbl WHERE id=1;
SELECT T.c.value('(@ID)','int') AS ID,
T.c.value('(FirstName[1])','varchar(99)') AS firstName,
T.c.value('(LastName[1])','varchar(99)') AS lastName
FROM @xmlDoc.nodes('/Customers/Customer') T(c)
GO
3. In the Report Data pane, right-click Data Sources and click Add Data Source.
4. For an embedded data source, verify that Embedded connection is selected. From the Type drop-down list, select a data source type; for example, Microsoft SQL Server or OLE DB. Type the connection string directly or click Edit to open the Connection
Properties dialog box and select Server name and database name from the drop down list.
5. For a shared data source, verify that Use shared data source reference is selected, then select a data source from the drop down list.
6. Right-click DataSets and click Add Dataset, type a name for the dataset or accept the default name, In Data source, select the name of an existing shared data source, select StoredProcedure in Query type, then select xml_report from stored procedure
name drop down list.
7. In the Toolbox, click Table, and then click on the design surface.
8. Drag the Date field from the dataset to the cells in the table.
The following screenshot is for your reference:
For more information about how to use the xml data type methods, please refer to the following document:
http://msdn.microsoft.com/en-us/library/ms190798.aspx
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu -
Creating MDM repository for Material Master Data
Hello MDM Gurus,
I am new to SAP MDM. I want to create MDM repository for Material Master. What I unddertand is, I can create repository using Bussiness Content shiped with MDM software. I will copy *.a2a file to archive folder of MDM server and unarchive repository. I have following question for you.
1. HOw do I use export maps and import maps which I found in Busines contenst\Material folder?
2. How do I use MDM Lookup Tables which is xml document in Busines contenst\Material folder?
3. Why is the use of MDMGX_55520_Material.txt file which I found in Busines contenst\Material folder?
4. What is the use of *.xsd files and how can I use them?
Thanks,
BhupeshHi Bhupesh
1. HOw do I use export maps and import maps which I found in Busines contenst\Material folder?
save all the map files on your loacl machine. open import manager and select file-> Import, browse to the .map file and save the map with a meaningful name. now next time connect to the source file you want to import and OPEN the map saved.
2. How do I use MDM Lookup Tables which is xml document in Busines contenst\Material folder?
Businees content contains the standard ECC refernce tables like countries, regions etc which can be refreshed from ECC. for this you have to configure MDMGX, defining all the ports in MDM and in ECC the tables from which data has to be refreshed. refer to below threads for details.
Extract Data usnig MDMGX
How to Export Materials from ERP to MDM 7.1 via MDMGX?
3. Why is the use of MDMGX_55520_Material.txt file which I found in Busines contenst\Material folder?
This helps us in configuring the table extraction from ECC, refer to thread-> Extract Data usnig MDMGX
4. What is the use of *.xsd files and how can I use them?
Schema files are used for syndicating the records from MDM to source system. Say we want to syndicate material master from MDM to ECC and in ECC they will be posted via MATMAS05 IDoc. these schemas are the structure of IDoc which will contain the values which will be syndicated from MDM.
Let me know if you know some more details.
regards
Ravi -
Query with bind var created under apex to generate xml data
Hi all;
BiP: 10.1.3.4
Apex: 4
DB 10G
Goal: want to generate a report by running a query with bind variables under apex.
problem: when attempted to create a query under shared components in apex, at the downloading xml data stage, I always get "no data found" eror. Thus I can't save xml data for further report work. This only occurs when bind var involved. I have tticked "incl. session variables" and added the item but to no avail.
Does anyone know how to do this and get the xml data to recive the bind variable ?
Thanks.
luluTo get the xml data, sql query has to return something. Why the sql is not returning anything can be better investigated outside the BI Publisher with special tool like SQL Developer or TOAD. There you have to run your query and make it working. One of the steps would be to try the sql without the parameter, see what data it brings back and go from there. One of possibilities why the parameter kills the output may be the NULL values involved, but you need to try the sql outside the BIP first.
-
XSL transform question from XML date datatype to SQL date datatype
Just to give an idea, I am reading some employee information in a CSV format and I have created the fileadapter to read it and parse it into coherent information where each comma separated value corresponds to a column in an employee table. One of the columns is of the date object in the database.
So my my variable is created with a list of employees and then fed into the invoke that calls a dbadapter that does the insert. I am using a transformation to get the values from one variable into the other simply because of namespace conflicts. However the xml date will not match the sql date object as to be expected...but how do I work around it? I have a few ideas but I am not sure they are worth mentioning.
Any suggestions?@@Version : ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
May 14 2014 18:34:29
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
(1 row(s) affected)
Compatibility level is set to 110 .
One of the limitation states - XML columns with a depth of more than 128 nested nodes
How do i verify this ? Thanks .
Rajkumar Yelugu
Maybe you are looking for
-
Zen Vision:M files disappe
Greetings: I recently uploaded some videos to my Zen Vision:M. They all appeared on my Zen for awhile, but the last time I went to look at them all but disappeared. I plugged my Zen into the computer and used Media Explorer to browse to the video fol
-
How do I use a JDBC Resource set-up in Sun Java System Appliation Server?
How do I use a JDBC Resource set-up in Sun Java System Appliation Server 8.2? I created a JDBC Resource labeled "jdbc/__PetroPool" that is backed by a Connection Pool labeled "PetroPool". Since this is set-up in Sun Java System Appliation Server 8.2,
-
Bangladesh VAT Requirement in FMCG
Dear Gurus, I have a VAT requirement in Bangladesh for an FMCG company. In this company the following setup exists: 2 Manufacturing Plants (which has its own VAT registration No.) Central Sales Depot (which has its own VAT registration No.), this CSD
-
Hi, We have some vendors who have the same TIN numbers but different addresses. When filing with IRS for 1099, do we need to combine the amounts for each of the duplicate vendors or send it separately? Thanks. S.Vijay
-
Hi, before the printout I modified the quantity of the purchase order. Now system shows both the old quantity and the new quantity values in the printout. I don't need this information in printout, how to modify the customizing so that system will no