<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Accounting systems &#187; SAP / Oracle</title>
	<atom:link href="http://accountingsystems.ie/?feed=rss2&#038;cat=8" rel="self" type="application/rss+xml" />
	<link>http://accountingsystems.ie</link>
	<description>Our free tips and tricks blog for Intact accounts, Sage, Syspro, Quickbook and bits of SAP and Oracle</description>
	<lastBuildDate>Tue, 06 Jul 2010 19:48:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Reading a SAP XML file into Access</title>
		<link>http://accountingsystems.ie/?p=30</link>
		<comments>http://accountingsystems.ie/?p=30#comments</comments>
		<pubDate>Tue, 06 Jul 2010 19:48:47 +0000</pubDate>
		<dc:creator>Patrick Jones</dc:creator>
				<category><![CDATA[SAP / Oracle]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[SAP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://accountingsystems.ie/?p=30</guid>
		<description><![CDATA[I use a free product call chilkatxml from chilkatsoft.com, The site has loads of samples but initially I found it difficult to iteriate through the record loops in the xml file.  I have detailed the code I used to load XML orders into an access database.
The first phase is to read the file into [...]]]></description>
			<content:encoded><![CDATA[<p>I use a free product call chilkatxml from <a href="http://www.chilkatsoft.com">chilkatsoft.com</a>, The site has loads of samples but initially I found it difficult to iteriate through the record loops in the xml file.  I have detailed the code I used to load XML orders into an access database.</p>
<p>The first phase is to read the file into an array and the second phase will post that array into an access database. This is similar to theExcel to Access sample but I am using an array to store the data.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Dim</span> xml <span style="color: #000080;">As</span> ChilkatXml
<span style="color: #000080;">Dim</span> rec1 <span style="color: #000080;">As</span> ChilkatXml, rec0 <span style="color: #000080;">As</span> ChilkatXml
<span style="color: #000080;">Dim</span> tmpLines(500, 10), i <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>, tmpCount <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span> <span style="color: #008000;">' change the array depth if needed
</span><span style="color: #000080;">Dim</span> tmpHeader(25) <span style="color: #008000;">' change to the number of headers filds you have
</span><span style="color: #000080;">Dim</span> rst <span style="color: #000080;">As</span> Recordset, rstStock <span style="color: #000080;">As</span> Recordset
<span style="color: #000080;">Dim</span> x <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
&nbsp;
<span style="color: #008000;">' Load the input document.
</span><span style="color: #000080;">Set</span> xml = <span style="color: #000080;">New</span> ChilkatXml
xml.LoadXMLFile tmpFile <span style="color: #008000;">' tmpfile is the XML file passed to this function
</span>
<span style="color: #008000;">'Header
</span><span style="color: #000080;">Set</span> rec1 = xml.FindChild(<span style="color: #800000;">&quot;Header&quot;</span>)
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;OrderNumber&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(1) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;CreationDate&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(2) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;CompanyCode&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(3) = Right(<span style="color: #800000;">&quot;000&quot;</span> &amp; rec1.Content, 3)
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
<span style="color: #008000;">'ship address
</span><span style="color: #000080;">Set</span> rec1 = xml.FindChild(<span style="color: #800000;">&quot;Partners&quot;</span>)
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;Identifier&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(4) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;Name1&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(5) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;Name2&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(6) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;Street&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(7) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;PostCode&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(8) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;CountryCode&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(9) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec1.FindChild2(<span style="color: #800000;">&quot;City&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpHeader(10) = rec1.Content
        rec1.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
<span style="color: #000080;">Set</span> rec1 = xml.FindChild(<span style="color: #800000;">&quot;Items&quot;</span>)
&nbsp;
<span style="color: #000080;">If</span> (rec1.FirstChild2() = 0) <span style="color: #000080;">Then</span>
    <span style="color: #000080;">Set</span> rec1 = <span style="color: #000080;">Nothing</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
<span style="color: #000080;">Set</span> rec0 = rec1.GetParent()
&nbsp;
i = 1
<span style="color: #000080;">Do</span> <span style="color: #000080;">While</span> <span style="color: #000080;">Not</span> (rec0 <span style="color: #000080;">Is</span> <span style="color: #000080;">Nothing</span>)
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;Material&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 1) = rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;Description&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 2) = rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;Quantity&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 3) = rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;DeliveryDate&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 4) = rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;PricePerUnit&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 5) = rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;ItemText&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 6) = <span style="color: #800000;">&quot;&quot;</span> &amp; rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;InfoRecordPOText&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 7) = <span style="color: #800000;">&quot;&quot;</span> &amp; rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;MaterialPOText &quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 8) = <span style="color: #800000;">&quot;&quot;</span> &amp; rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;DeliveryText&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 9) = <span style="color: #800000;">&quot;&quot;</span> &amp; rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #008000;">'now check for vendor material number
</span>    <span style="color: #000080;">If</span> (rec0.FindChild2(<span style="color: #800000;">&quot;VendorMaterialNumber&quot;</span>) = 1) <span style="color: #000080;">Then</span>
        tmpLines(i, 10) = <span style="color: #800000;">&quot;&quot;</span> &amp; rec0.Content
        rec0.GetParent2
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    <span style="color: #008000;">' Move to the next sibling. The internal reference within node is updated
</span>    <span style="color: #008000;">' to the node's next sibling. If no siblings remain, it returns 0.
</span>    <span style="color: #000080;">If</span> (rec0.NextSibling2() = 0) <span style="color: #000080;">Then</span>
        <span style="color: #000080;">Set</span> rec0 = <span style="color: #000080;">Nothing</span>
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
    i = i + 1
&nbsp;
<span style="color: #000080;">Loop</span>
&nbsp;
<span style="color: #008000;">' now write the data into the tblImport
</span><span style="color: #000080;">Set</span> rst = CurrentDb.OpenRecordset(<span style="color: #800000;">&quot;tblImportData&quot;</span>)
&nbsp;
tmpCount = 0
x = 1
<span style="color: #000080;">Do</span> <span style="color: #000080;">While</span> Len(tmpLines(x, 2) &amp; <span style="color: #800000;">&quot;&quot;</span>) &gt; 0
    rst.AddNew
    <span style="color: #008000;">'rst!O_Number = tmpHeader(1)
</span>    rst!O_Entity = tmpHeader(3)
    rst!O_Date = DateSerial(Left(tmpHeader(2), 4), Val(Left(Right(tmpHeader(2), 4), 2)), Val(Right(tmpHeader(2), 2)))
    <span style="color: #000080;">If</span> Len(tmpLines(x, 1) &amp; <span style="color: #800000;">&quot;&quot;</span>) &gt; 0 <span style="color: #000080;">Then</span>
        rst!O_Part = tmpLines(x, 1)
    <span style="color: #000080;">Else</span>
        <span style="color: #008000;">'try the vendor material number
</span>        rst!O_Part = tmpLines(x, 10)
    <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #008000;">'rst!O_AltPArt = tmpLines(x, 1)
</span>    rst!O_PartOrg = tmpLines(x, 1)
    rst!O_Desc = tmpLines(x, 2)
    rst!O_Qty = tmpLines(x, 3)
    rst!O_Price = tmpLines(x, 5)
    rst!O_Price2 = tmpLines(x, 5)
    rst!O_Extended = Val(Nz(tmpLines(x, 5), 0)) * Val(Nz(tmpLines(x, 3), 0))
    rst!O_ImpDate = <span style="color: #000080;">Date</span>
    rst!O_ShipName = tmpHeader(5)
    rst!O_Ship1 = tmpHeader(6)
    rst!O_Ship2 = tmpHeader(7)
    rst!O_Ship3 = tmpHeader(8)
    rst!O_Ship4 = tmpHeader(9)
    rst!O_Ship5 = tmpHeader(10)
    <span style="color: #008000;">'rst!O_Ship6=&quot;&quot;
</span>    rst!O_Processed = 0
    rst!O_Failed = 0
    rst!O_Validated = 0
    rst!O_Disc = 0
    rst!O_Number = tmpHeader(1) &amp; <span style="color: #800000;">&quot;-&quot;</span> &amp; rst!O_Warehouse
    <span style="color: #000080;">Set</span> rstStock = <span style="color: #000080;">Nothing</span>
&nbsp;
    rst!O_PriceList = <span style="color: #800000;">&quot;A&quot;</span>
    <span style="color: #008000;">'rst!O_FailReason
</span>    <span style="color: #008000;">'rst!O_ORder
</span>    <span style="color: #008000;">'rst!O_Master
</span>    rst!O_LineShipDate = DateSerial(Left(tmpLines(x, 4), 4), Val(Left(Right(tmpLines(x, 4), 4), 2)), Val(Right(tmpLines(x, 4), 2)))
    <span style="color: #008000;">'rst!O_OrderDate
</span>    rst!O_Inactive = 0
    rst!O_Text = tmpLines(x, 6) &amp; vbCrLf &amp; tmpLines(x, 7) &amp; vbCrLf &amp; tmpLines(x, 8) &amp; vbCrLf &amp; tmpLines(x, 9) &amp; vbCrLf
    rst.Update
    tmpCount = tmpCount + 1
    x = x + 1
<span style="color: #000080;">Loop</span>
<span style="color: #000080;">If</span> tmpCount &gt; 0 <span style="color: #000080;">Then</span>
    MsgBox <span style="color: #800000;">&quot;Order Loaded&quot;</span>
<span style="color: #000080;">Else</span>
    MsgBox <span style="color: #800000;">&quot;No order lines loaded - check XML File&quot;</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://accountingsystems.ie/?feed=rss2&amp;p=30</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
