Skip to Content
avatar image
Former Member

Processing multiple order for File2B1 scenario

Hi Experts,

I'm trying to build a scenario step to import sales orders via flat file (CSV).

File will have following columns

OrderReference,CustomerCode,ItemCode, Quantity

Sample data is

121,C001,Item001,11

121,C001,Item025,21

122,C025,Item002,23

123,C004, Item025,13

123,C004,Item026,55

How to post the above 3 sales order at SAP?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

8 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 22 at 04:58 PM

    Hi Huan,

    Bravo, this http://xsltransform.net/pNEhB38 works like a charm.

    Thanks,

    Bala

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 19 at 12:17 PM

    Hello Balakumar,

    1. There is a free self-paced course by SAP named "In Action - Integration Framework for SAP Business One"

    The link is: https://open.sap.com/courses/ifb1

    There it is well explained and you can get a record of achievement.

    I recommend you have the course first.

    2. There is a video in YouTube show you how to read file in B1i

    The link is: https://www.youtube.com/watch?v=SvO-h0ejvBw

    Hope these help

    Best Regards.

    Huan Yang

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 19 at 04:56 PM

    Hi Huan Yang ,

    Thanks for the response.

    I already completed this course, "In Action - Integration Framework for SAP Business One".

    I was able to read the file from the scenario step.

    My only challenge is to group the above sample 5 lines into 3 Documents.

    My sender payload is showing as 5 individual rows. I'm unable to transform these 5 lines into tree structure as

    <Document>

    <Document_Lines>

    Regards,

    Bala

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 20 at 02:46 AM

    Hello Balakumar,

    It's great that you already know how to read the file from the scenario step.

    I think the current obstacle for you is how to put the data into B1 system.

    If you want to make 5 lines into 3 Documents, then you need to call 3 times B1 DI.

    You may use B1 batch call or 3 B1 DI Object Call or 3 B1 Service Layer call.

    For each xform, you may set different orders' information.

    For example:

    Order No.1 xform

    	<xsl:template name="transform">
    		<Documents>
    			<row>
    				<CardCode>C001</CardCode>
    				<NumAtCard>121</NumAtCard>
    				<DocDate>20190220</DocDate>
    				<DocDueDate>20190220</DocDueDate>
    				<TaxDate>20190220</TaxDate>
    			</row>
    		</Documents>
    		<Document_Lines>
    			<row>
    				<ItemCode>Item001</ItemCode>
    				<Quantity>11</Quantity>
    				<Price>100</Price>
    			</row>
    			<row>
    				<ItemCode>Item025</ItemCode>
    				<Quantity>21</Quantity>
    				<Price>100</Price>
    			</row>
    		</Document_Lines>
    	</xsl:template>
    
    

    Order No.2 xform

    	<xsl:template name="transform">
    		<Documents>
    			<row>
    				<CardCode>C025</CardCode>
    				<NumAtCard>122</NumAtCard>
    				<DocDate>20190220</DocDate>
    				<DocDueDate>20190220</DocDueDate>
    				<TaxDate>20190220</TaxDate>
    			</row>
    		</Documents>
    		<Document_Lines>
    			<row>
    				<ItemCode>Item002</ItemCode>
    				<Quantity>23</Quantity>
    				<Price>100</Price>
    			</row>
    		</Document_Lines>
    	</xsl:template>
    

    Order No.3 xform

    	<xsl:template name="transform">
    		<Documents>
    			<row>
    				<CardCode>C004</CardCode>
    				<NumAtCard>123</NumAtCard>
    				<DocDate>20190220</DocDate>
    				<DocDueDate>20190220</DocDueDate>
    				<TaxDate>20190220</TaxDate>
    			</row>
    		</Documents>
    		<Document_Lines>
    			<row>
    				<ItemCode>Item025</ItemCode>
    				<Quantity>13</Quantity>
    				<Price>100</Price>
    			</row>
    			<row>
    				<ItemCode>Item026</ItemCode>
    				<Quantity>55</Quantity>
    				<Price>100</Price>
    			</row>
    		</Document_Lines>
    	</xsl:template>
    

    Hope these help

    Best Regards.

    Huan Yang


    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20 at 07:34 AM

    Hi Huan Yang,

    Thanks for your detailed reply. The solution will work only if the incoming file always has three Orders.

    This is just an example, in reality, the incoming file can have multiple orders with multiple lines which are not fixed.

    To be precise, how to use Muenchian Grouping in xsl transform atom since <xsl:for-each-group> is not supported :(

    To post the Orders into SAP, I'll use the For - Each atom. FYI please, since the no. of orders are not fixed.

    My incoming Payload is

    <Payload>
      <row xmlns="">
        <OrderRef>1</OrderRef>
        <CustomerCode>C0001</CustomerCode>
        <ItemCode>IT001</ItemCode>
        <Quantity>11</Quantity>
      </row>
      <row xmlns="">
        <OrderRef>1</OrderRef>
        <CustomerCode>C0001</CustomerCode>
        <ItemCode>IT002</ItemCode>
        <Quantity>21</Quantity>
      </row>
      <row xmlns="">
        <OrderRef>1</OrderRef>
        <CustomerCode>C0001</CustomerCode>
        <ItemCode>IT003</ItemCode>
        <Quantity>31</Quantity>
      </row>
      <row xmlns="">
        <OrderRef>2</OrderRef>
        <CustomerCode>C0002</CustomerCode>
        <ItemCode>IT002</ItemCode>
        <Quantity>12</Quantity>
      </row>
      <row xmlns="">
        <OrderRef>2</OrderRef>
        <CustomerCode>C0002</CustomerCode>
        <ItemCode>IT001</ItemCode>
        <Quantity>22</Quantity>
      </row>
    </Payload>
    

    Desired output is

    <Payload>
       <Document>
          <Ref>1</Ref>
          <CardCode>C0001</CardCode>
          <Lines>
             <Item>
                <ItemCode>IT001</ItemCode>
                <Qty>11</Qty>
             </Item>
             <Item>
                <ItemCode>IT002</ItemCode>
                <Qty>21</Qty>
             </Item>
             <Item>
                <ItemCode>IT003</ItemCode>
                <Qty>31</Qty>
             </Item>
          </Lines>
       </Document>
       <Document>
          <Ref>2</Ref>
          <CardCode>C0002</CardCode>
          <Lines>
             <Item>
                <ItemCode>IT002</ItemCode>
                <Qty>12</Qty>
             </Item>
             <Item>
                <ItemCode>IT001</ItemCode>
                <Qty>22</Qty>
             </Item>
          </Lines>
       </Document>
    </Payload>

    Check this link for working example: XSLTransform

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Balakumar,

      If the source xml is like this:

      <Payload>
      	<row xmlns="">
      		<OrderRef>1</OrderRef>
      		<CustomerCode>C0001</CustomerCode>
      		<ItemCode>IT001</ItemCode>
      		<Quantity>11</Quantity>
      	</row>
      	<row xmlns="">
      		<OrderRef>1</OrderRef>
      		<CustomerCode>C0001</CustomerCode>
      		<ItemCode>IT002</ItemCode>
      		<Quantity>21</Quantity>
      	</row>
      	<row xmlns="">
      		<OrderRef>1</OrderRef>
      		<CustomerCode>C0001</CustomerCode>
      		<ItemCode>IT003</ItemCode>
      		<Quantity>31</Quantity>
      	</row>
      	<row xmlns="">
      		<OrderRef>2</OrderRef>
      		<CustomerCode>C0002</CustomerCode>
      		<ItemCode>IT002</ItemCode>
      		<Quantity>12</Quantity>
      	</row>
      	<row xmlns="">
      		<OrderRef>2</OrderRef>
      		<CustomerCode>C0002</CustomerCode>
      		<ItemCode>IT001</ItemCode>
      		<Quantity>22</Quantity>
      	</row>
      </Payload>
      

      You may use the following xsl:

      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet xmlns:b1e="urn:com.sap.b1i.sim:b1event" xmlns:b1ie="urn:com.sap.b1i.sim:b1ievent" xmlns:b1im="urn:com.sap.b1i.sim:b1imessage" xmlns:bfa="urn:com.sap.b1i.bizprocessor:bizatoms" xmlns:jdbc="urn:com.sap.b1i.adapter:jdbcadapter" xmlns:js="com.sap.b1i.bpc_tools.Javascript" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:sim="urn:com.sap.b1i.sim:entity" xmlns:uplt="urn:com.sap.b1i.xcellerator:upltdoc" xmlns:utils2="com.sap.b1i.bpc_tools.Utilities" xmlns:vpf="urn:com.sap.b1i.vplatform:entity" xmlns:xci="urn:com.sap.b1i.xcellerator:intdoc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" bfa:force="" vpf:force="" jdbc:force="" rfc:force="" b1ie:force="" b1e:force="" xci:force="" sim:force="" utils2:force="" b1im:force="" uplt:force="" js:force="">
      	<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
      	<xsl:param name="atom"/>
      	<xsl:param name="sessionid"/>
      	<xsl:variable name="msg" select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role='S']"/>
      	<xsl:variable name="vpSender" select="/vpf:Msg/vpf:Header/vpf:Sender/@Id"/>
      	<xsl:variable name="vpObject" select="/vpf:Msg/vpf:Header/vpf:Sender/@ObjId"/>
      	<xsl:variable name="vpReceiver" select="/vpf:Msg/vpf:Header/vpf:ReceiverList/vpf:Receiver[./@handover='P']/@Id"/>
      	<xsl:template match="/">
      		<vpf:Msg>
      			<xsl:copy-of select="/vpf:Msg/@*"/>
      			<xsl:copy-of select="/vpf:Msg/vpf:Header"/>
      			<vpf:Body>
      				<xsl:copy-of select="/vpf:Msg/vpf:Body/*"/>
      				<vpf:Payload Role="X" id="{$atom}">
      					<xsl:call-template name="transform"/>
      				</vpf:Payload>
      			</vpf:Body>
      		</vpf:Msg>
      	</xsl:template>
      	<xsl:template name="transform">
      		<!--place_here_your_B1_ServiceLayerEntity_Schema -->
      		<xsl:for-each select="/Payload/row[not(preceding::row/CustomerCode = ./CustomerCode)]">
      			<xsl:variable name="cardCode">
      				<xsl:value-of select="CustomerCode"/>
      			</xsl:variable>
      			<BOM>
      				<BO>
      					<Documents>
      						<row>
      							<CardCode>
      								<xsl:value-of select="$cardCode"/>
      							</CardCode>
      							<NumAtCard>
      								<xsl:value-of select="OrderRef"/>
      							</NumAtCard>
      						</row>
      					</Documents>
      					<Document_Lines>
      						<xsl:for-each select="/Payload/row[./CustomerCode=$cardCode]">
      							<row>
      								<ItemCode>
      									<xsl:value-of select="ItemCode"/>
      								</ItemCode>
      								<Quantity>
      									<xsl:value-of select="Quantity"/>
      								</Quantity>
      							</row>
      						</xsl:for-each>
      					</Document_Lines>
      				</BO>
      			</BOM>
      		</xsl:for-each>
      	</xsl:template>
      </xsl:stylesheet>
      

      And the result will be like this:

      <?xml version="1.0" encoding="UTF-8"?>
      <vpf:Msg xmlns:b1e="urn:com.sap.b1i.sim:b1event" xmlns:b1ie="urn:com.sap.b1i.sim:b1ievent" xmlns:b1im="urn:com.sap.b1i.sim:b1imessage" xmlns:bfa="urn:com.sap.b1i.bizprocessor:bizatoms" xmlns:jdbc="urn:com.sap.b1i.adapter:jdbcadapter" xmlns:js="com.sap.b1i.bpc_tools.Javascript" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:sim="urn:com.sap.b1i.sim:entity" xmlns:uplt="urn:com.sap.b1i.xcellerator:upltdoc" xmlns:utils2="com.sap.b1i.bpc_tools.Utilities" xmlns:vpf="urn:com.sap.b1i.vplatform:entity" xmlns:xci="urn:com.sap.b1i.xcellerator:intdoc">
      	<vpf:Body>
      		<vpf:Payload Role="X" id="">
      			<BOM>
      				<BO>
      					<Documents>
      						<row>
      							<CardCode>C0001</CardCode>
      							<NumAtCard>1</NumAtCard>
      						</row>
      					</Documents>
      					<Document_Lines>
      						<row>
      							<ItemCode>IT001</ItemCode>
      							<Quantity>11</Quantity>
      						</row>
      						<row>
      							<ItemCode>IT002</ItemCode>
      							<Quantity>21</Quantity>
      						</row>
      						<row>
      							<ItemCode>IT003</ItemCode>
      							<Quantity>31</Quantity>
      						</row>
      					</Document_Lines>
      				</BO>
      			</BOM>
      			<BOM>
      				<BO>
      					<Documents>
      						<row>
      							<CardCode>C0002</CardCode>
      							<NumAtCard>2</NumAtCard>
      						</row>
      					</Documents>
      					<Document_Lines>
      						<row>
      							<ItemCode>IT002</ItemCode>
      							<Quantity>12</Quantity>
      						</row>
      						<row>
      							<ItemCode>IT001</ItemCode>
      							<Quantity>22</Quantity>
      						</row>
      					</Document_Lines>
      				</BO>
      			</BOM>
      		</vpf:Payload>
      	</vpf:Body>
      </vpf:Msg>
      

      I also put the code in http://xsltransform.net/pNEhB38

      Then you may know how to generate variable numbers' orders

      Hope these help

      Best Regards.

      Huan Yang

  • Feb 20 at 01:03 PM

    Hello Balakumar,

    1. You may use xpath to transform the input payload to several <Documents>...</Documents>.

    I saw you already made it.

    2. You may use a for-each to generate B1 order

    3. You may use B1 batch call

    Hope these help

    Best Regards.

    Huan Yang


    for-each.jpg (97.6 kB)
    for-each2.jpg (114.2 kB)
    b1-batch.jpg (75.5 kB)
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 20 at 08:52 PM

    Hello Huan Yang ,

    I'm unable to implement the transformation of incoming payload into several documents.

    Yes, this link shows a working example but I'm unable to implement in B1i transformation atom.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 21 at 10:41 AM

    Hi Huan Yang,

    Below is my transformation atom which is not working :(

    <xsl:template name="transform">
            <xsl:key name="groups" match="row" use="OrderRef"></xsl:key>
            <xsl:template match="/vpf:Msg/vpf:Body/vpf:Payload[./@Role='S']">
                <xsl:copy>
                    <xsl:apply-templates select="row[generate-id() = generate-id(key('groups', OrderRef)[1])]"></xsl:apply-templates>
                </xsl:copy>
            </xsl:template>
            <xsl:template match="/vpf:Msg/vpf:Body/vpf:Payload[./@Role='S']/row">
                <Document>
                    <Ref>
                        <xsl:value-of select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role='S']/row/OrderRef"></xsl:value-of>
                    </Ref>
                    <CardCode>
                        <xsl:value-of select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role='S']/row/CustomerCode"></xsl:value-of>
                    </CardCode>
                    <Lines>
                        <xsl:for-each select="key('groups',.//OrderRef)">
                            <Item>
                                <ItemCode>
                                    <xsl:value-of select=".//ItemCode"></xsl:value-of>
                                </ItemCode>
                                <Qty>
                                    <xsl:value-of select=".//Quantity"></xsl:value-of>
                                </Qty>
                            </Item>
                        </xsl:for-each>
                    </Lines>
                </Document>
            </xsl:template>
        </xsl:template>
    Add comment
    10|10000 characters needed characters exceeded