on 08-14-2008 7:53 AM
Hi Experts,
I have the following source fields:
1 <Recordset>
<Record>
<LineIdentifier>ITEM</LineIdentifier>
<Data>D1<Data>
</Record>
<Record>
<LineIdentifier>ITEM</LineIdentifier>
<Data>D2</Data>
</Record>
2 <Recordset>
<Record>
<LineIdentifier>ITEM</LineIdentifier>
<Data>D3<Data>
</Record>
Target : 2 Idocs to be created!
For each recordset, an IDoc needs to be created. For Idoc 1, there should be 2 segment of E1EDP01 to be created(coz 2 ITEM) and Idoc 2, there should be 1 segment of E1EDP01).
I have done it as follows:
Check if LineIdentifier (context is recordset) = ITEM then map Record to UDF createItemrecord as follows
for(int i =0; i < record.length; i++)
{
result.addValue(record<i>);
}
Then map it to RemoveContext and SplitByValue. The result is Idoc 1 has 1 segment of E1EDP01 (Value D1) and IDoc 2 has 1 segment of E1EDP01 (value D2).
The expected result is => Idoc1 -> E1EDP01(D1) and E1EDP01(D2) and Idoc 2 -> E1EDP01(D1) and E1EDP01(D3)
Please explain how this can be achieve.
thanks a lot.
Rewards guaranteed!!!
Regards,
Tush
Edited by: Tush Mangad on Aug 14, 2008 8:53 AM
Recordset(context to root)---> IDoc node at target
Record(default context to Recordset)----->segment E1EDP01 no need of UDF
then continue with rest of mapping to get values from Data
The expected result is => Idoc1 -> E1EDP01(D1) and E1EDP01(D2) and Idoc 2 -> E1EDP01(D1) and E1EDP01(D3)
--->
Source is showing 1 D1, that is to be put in IDoc1, then it will not come in IDoc2
Also your source has Recordset1 that contains D1 and D2 that should go to IDoc1 and Recordset2 contains D3 that should go to IDoc2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check with the following mapping
Recordset----->Idoc
LineIdentifier->exists>createif--->E1EDP01
Then proceed with the other mappings.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have found that XSL mapping does this quite well
An example to create Sales Order IDocs
Note that square brackets in the generate statement have been interpreted by this editor as a strikethrough
-
Input file
-
<?xml version="1.0" encoding="UTF-8"?>
<input>
<row>
<ordernum>ORD1</ordernum>
<orderitem>ITEM1</orderitem>
<data>ABC</data>
</row>
<row>
<ordernum>ORD1</ordernum>
<orderitem>ITEM2</orderitem>
<data>DEF</data>
</row>
<row>
<ordernum>ORD2</ordernum>
<orderitem>ITEM1</orderitem>
<data>GHI</data>
</row>
</input>
-
XSL
-
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<!-- -->
<xsl:template match="/">
<CRMXIF_ORDER_SAVE_M01>
<xsl:apply-templates select="//input"/>
<!-- -->
</CRMXIF_ORDER_SAVE_M01>
</xsl:template>
<!-- -->
<xsl:template match="input">
<xsl:variable name="sales_order" select="//row"/>
<xsl:for-each select="$sales_order">
<xsl:if test="generate-id(.)=generate-id($sales_order[ordernum=current()/ordernum])">
<!-- New Order Number -->
<xsl:if test="position()!=1">
<xsl:text disable-output-escaping="yes"><</xsl:text>/E101CRMXIF_BUSTRANS<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:text disable-output-escaping="yes"><</xsl:text>/IDOC<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:if>
<xsl:text disable-output-escaping="yes"><</xsl:text>IDOC BEGIN=<xsl:text disable-output-escaping="yes">"</xsl:text>1<xsl:text disable-output-escaping="yes">"></xsl:text>
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
<MANDT>010</MANDT>
<DOCREL>620</DOCREL>
<STATUS>30</STATUS>
<DIRECT>1</DIRECT>
<OUTMOD>2</OUTMOD>
<IDOCTYP>CRMXIF_ORDER_SAVE_M01</IDOCTYP>
<MESTYP>CRMXIF_ORDER_SAVE_M</MESTYP>
<SNDPRT>LS</SNDPRT>
<RCVPRT>LS</RCVPRT>
</EDI_DC40>
<xsl:text disable-output-escaping="yes"><</xsl:text>E101CRMXIF_BUSTRANS SEGMENT=<xsl:text disable-output-escaping="yes">"</xsl:text>1<xsl:text disable-output-escaping="yes">"></xsl:text>
<!-- Build Sales Order BUSTRANS data -->
<xsl:call-template name="bustrans_Template">
<xsl:with-param name="bustrans" select="current()"/>
</xsl:call-template>
<!-- Build Sales Order BUSTRANS_ITEM data -->
<xsl:call-template name="bustransItem_Template">
<xsl:with-param name="bustransItem" select="current()"/>
</xsl:call-template>
</xsl:if>
<!-- -->
<!-- Same Order Number - multiple items encountered -->
<!-- Build Sales Order BUSTRANS_ITEM data -->
<xsl:if test="generate-id(.)!=generate-id($sales_order[ordernum=current()/ordernum])">
<xsl:call-template name="bustransItem_Template">
<xsl:with-param name="bustransItem" select="current()"/>
</xsl:call-template>
</xsl:if>
<!-- -->
<xsl:if test="position()=last()">
<xsl:text disable-output-escaping="yes"><</xsl:text>/E101CRMXIF_BUSTRANS<xsl:text disable-output-escaping="yes">></xsl:text>
<xsl:text disable-output-escaping="yes"><</xsl:text>/IDOC<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- -->
<xsl:template name="bustrans_Template">
<xsl:param name="bustrans"/>
<APPL_SNAME>CRMXIF_BUSTRANS</APPL_SNAME>
<!-- Business Transaction: Sales -->
<E101CRMXIF_SALES_X SEGMENT="1">
<APPL_SNAME>CRMXIF_SALES_X</APPL_SNAME>
<DATAX>X</DATAX>
<E101CRMXIF_SALES SEGMENT="1">
<APPL_SNAME>CRMXIF_SALES</APPL_SNAME>
<!-- Sold-To Party's External Reference -->
<PO_NUMBER_SOLD>
<xsl:value-of select="ordernum"/>
</PO_NUMBER_SOLD>
</E101CRMXIF_SALES>
</E101CRMXIF_SALES_X>
</xsl:template>
<!-- -->
<xsl:template name="bustransItem_Template">
<xsl:param name="bustransItem"/>
<!-- Business Transaction: Item -->
<E101CRMXIF_BUSTRANS_ITEM SEGMENT="1">
<APPL_SNAME>CRMXIF_BUSTRANS_ITEM</APPL_SNAME>
<OBJECT_TASK>I</OBJECT_TASK>
<!-- Item Number in Document -->
<ITEM_NUMBER>
<xsl:value-of select="orderitem"/>
</ITEM_NUMBER>
<!-- Product ID -->
<PRODUCT_ID>
<xsl:value-of select="data"/>
</PRODUCT_ID>
</E101CRMXIF_BUSTRANS_ITEM>
</xsl:template>
</xsl:stylesheet>
-
Result
-
<?xml version="1.0" encoding="UTF-8"?>
<CRMXIF_ORDER_SAVE_M01 xmlns:fo="http://www.w3.org/1999/XSL/Format">
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
<MANDT>010</MANDT>
<DOCREL>620</DOCREL>
<STATUS>30</STATUS>
<DIRECT>1</DIRECT>
<OUTMOD>2</OUTMOD>
<IDOCTYP>CRMXIF_ORDER_SAVE_M01</IDOCTYP>
<MESTYP>CRMXIF_ORDER_SAVE_M</MESTYP>
<SNDPRT>LS</SNDPRT>
<RCVPRT>LS</RCVPRT>
</EDI_DC40>
<E101CRMXIF_BUSTRANS SEGMENT="1">
<APPL_SNAME>CRMXIF_BUSTRANS</APPL_SNAME>
<E101CRMXIF_SALES_X SEGMENT="1">
<APPL_SNAME>CRMXIF_SALES_X</APPL_SNAME>
<DATAX>X</DATAX>
<E101CRMXIF_SALES SEGMENT="1">
<APPL_SNAME>CRMXIF_SALES</APPL_SNAME>
<PO_NUMBER_SOLD>ORD1</PO_NUMBER_SOLD>
</E101CRMXIF_SALES>
</E101CRMXIF_SALES_X>
<E101CRMXIF_BUSTRANS_ITEM SEGMENT="1">
<APPL_SNAME>CRMXIF_BUSTRANS_ITEM</APPL_SNAME>
<OBJECT_TASK>I</OBJECT_TASK>
<ITEM_NUMBER>ITEM1</ITEM_NUMBER>
<PRODUCT_ID>ABC</PRODUCT_ID>
</E101CRMXIF_BUSTRANS_ITEM>
<E101CRMXIF_BUSTRANS_ITEM SEGMENT="1">
<APPL_SNAME>CRMXIF_BUSTRANS_ITEM</APPL_SNAME>
<OBJECT_TASK>I</OBJECT_TASK>
<ITEM_NUMBER>ITEM2</ITEM_NUMBER>
<PRODUCT_ID>DEF</PRODUCT_ID>
</E101CRMXIF_BUSTRANS_ITEM>
</E101CRMXIF_BUSTRANS>
</IDOC>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
<MANDT>010</MANDT>
<DOCREL>620</DOCREL>
<STATUS>30</STATUS>
<DIRECT>1</DIRECT>
<OUTMOD>2</OUTMOD>
<IDOCTYP>CRMXIF_ORDER_SAVE_M01</IDOCTYP>
<MESTYP>CRMXIF_ORDER_SAVE_M</MESTYP>
<SNDPRT>LS</SNDPRT>
<RCVPRT>LS</RCVPRT>
</EDI_DC40>
<E101CRMXIF_BUSTRANS SEGMENT="1">
<APPL_SNAME>CRMXIF_BUSTRANS</APPL_SNAME>
<E101CRMXIF_SALES_X SEGMENT="1">
<APPL_SNAME>CRMXIF_SALES_X</APPL_SNAME>
<DATAX>X</DATAX>
<E101CRMXIF_SALES SEGMENT="1">
<APPL_SNAME>CRMXIF_SALES</APPL_SNAME>
<PO_NUMBER_SOLD>ORD2</PO_NUMBER_SOLD>
</E101CRMXIF_SALES>
</E101CRMXIF_SALES_X>
<E101CRMXIF_BUSTRANS_ITEM SEGMENT="1">
<APPL_SNAME>CRMXIF_BUSTRANS_ITEM</APPL_SNAME>
<OBJECT_TASK>I</OBJECT_TASK>
<ITEM_NUMBER>ITEM1</ITEM_NUMBER>
<PRODUCT_ID>GHI</PRODUCT_ID>
</E101CRMXIF_BUSTRANS_ITEM>
</E101CRMXIF_BUSTRANS>
</IDOC>
</CRMXIF_ORDER_SAVE_M01>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1)Create an External_definition for the Idoc including the max Occurrs attribute 4r it.Also check whether the occurance of E1EDP01 segment is greater than 0.
2)Now use this ED in the mapping.
3)Map every Recordset segment to Idoc.
4)Map every Recordset segment to E1EDP01.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.