cancel
Showing results for 
Search instead for 
Did you mean: 

Idoc mapping to group similar items under one idoc

former_member190543
Participant
0 Kudos

Hi,

I have a file to multiple idoc scenario.

My Source structure:

Msg type

   Data Type

          Header (1)  (field1, field 2, field 3 etc)

          ITEM( 0 to U)  (field X, field Y, field Z etc)

Target structure:

Idoc Type

     IDOC (1 to U)

     Begin

     Idoc Ports (1) (field a1, field a2, field a3 etc)

     Idoc_HDR (1) (field1, field Y, field 3 etc)

           Idoc_ITM (1 to 99999999)  (field X, field Z etc)

Idocs are generated only for some ITEM lines of source and so the value of field X is used and mapped to IDOC node using createif.

Rest of the mapping is done normally and works fine and creating multiple idocs if there are multiple ITEM lines in the source file. This mapping is doesn't work if I want to create multiple Idoc-ITMs

My requirement is to create multiple Idoc_ITM nodes under one parent IDOC node for for all ITEMs relating to one "field Y" of source. At the moment I am creating 4 idocs for the below example, but I want 3 like below:

For example:

Source file:

Country, city, date

emp1, department1, roleA

emp2, department1, roleB

emp3, department2, roleC

emp4, department3, roleC

Required Target file:

IDOC 1

Idoc_HDR

  Country, department1, date

  Idoc_ITM

  emp1, department1, roleA

  Idoc_ITM

  emp2, department1, roleB

IDOC 2

Idoc_HDR

  Country, department2, date

  Idoc_ITM

  emp3, department2, roleC

IDOC 3

Idoc_HDR

  Country, department3, date

  Idoc_ITM

  emp4, department3, roleC

How can achieve it please?

Many thanks.

Ramesh.

Accepted Solutions (1)

Accepted Solutions (1)

Muniyappan
Active Contributor
0 Kudos

Hi,

check if this helps you.

still you can simplify this mapping i.e in formatbyexample section.

Regards

Muni.

former_member190543
Participant
0 Kudos

Hi Muni,

Thank you very much for your time. I really appreciate your help.

Just a silly question, how did you manage to use the collapsecontexts function twice? Is it only for illustration or can we actually do this?

Thanks,

Ramesh.

Muniyappan
Active Contributor
0 Kudos

Hi Ramesh,

Are you talking about field1 mapping?

i did not get your question.

Regards,

Muni.

former_member190543
Participant
0 Kudos

Hi Muni,

Under the header mapping, just before the "useOneAsMany" you used the output of collapseContexts function twice. How is that possible?

Also, I did everything you mentioned. In the header mapping, we mapped the field Y to field2. It is giving me an error "Too many values in first queue in function useOneAsMany. It must have the same number of contexts as second queue.] in class com.sap.aii.mappingtool.flib3.NodeFunctions method useOneAsMany"

The field 2 in the target header occurs only once but it occurs many times in the source. How do we overcome this problem?

I think I am getting close to this.

Many thanks for your help.

Ramesh.

Muniyappan
Active Contributor
0 Kudos

Hi ramesh,

It is possible.

Can you please paste your use one as many  mapping screen shot?

Also share your input xml here.

Regards,

Muni.

former_member190543
Participant
0 Kudos

Hi Muni,

I can't use the collapsecontexts twice in the mapping. Is it to do with the PI version we are in?

I will send you the source XML to your email address if you can provide it.

Many thanks.

Ramesh.

former_member184720
Active Contributor
0 Kudos

Hi Ramesh - If you are unable to map from collapse context  to splitby value..

just right click on collapse context -> copy

then on a empty area right click and insert.. then map it to split by value.... it's the same

Muniyappan
Active Contributor
0 Kudos

Hi Ramesh,

you don't have to send it to my mail id.

please paste source and target xml here. that would be enough.

even you can attach the xml in the thread.

Regards,

Muni.

former_member190543
Participant
0 Kudos

Hi Muni,

The source and required target xmls are here: I made it a bit simpler for better understanding and space.

If you want the xml of the source message structure, I can send that too.

Source:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:expense_source_msg xmlns:ns0="http://dtsp.com/postexpense">

   <Online_Expenses>

      <Expenses_Header>

         <Constant/>

         <BatchDate>20140320<BatchDate/>

         <Record_Count/>

         <Amount_Total/>

      </Expenses_Header>

      <Expenses_Item>

         <Employee_ID>test1<Employee_ID/>

         <Employee_Name>RAMESH<Employee_Name/>

         <price>10.00<price/>

         <Org_Unit>z1<Org_Unit/>

         <Type>Price<Type/>   

      </Expenses_Item>

      <Expenses_Item>

         <Employee_ID>test2<Employee_ID/>

         <Employee_Name>ANKIT<Employee_Name/>

         <price>20.00<price/>

         <Org_Unit>z2<Org_Unit/>

         <Type>Price<Type/>   

      </Expenses_Item>

      <Expenses_Item>

         <Employee_ID>test3<Employee_ID/>

         <Employee_Name>SIVA<Employee_Name/>

         <price>30.00<price/>

         <Org_Unit>z2<Org_Unit/>

         <Type>Price<Type/>   

      </Expenses_Item>

   </Online_Expenses>

Required Target:

</ns0:concur_online_expense_source_msg>

<?xml version="1.0" encoding="UTF-8"?>

<ZFI204_AR_INV01>

   <IDOC BEGIN="1">

      <EDI_DC40 SEGMENT="EDI_DC40">

         <TABNAM>EDI_DC40</TABNAM>

         <DIRECT>2</DIRECT>

         <IDOCTYP>ZFI204_AR_INV01</IDOCTYP>

         <MESTYP>ZFI204_AR_INV</MESTYP>

         <RCVPRN/>

      </EDI_DC40>

      <Z1ZFI204_HDR SEGMENT="Z1ZFI204_HDR">

         <DOCUMENT_TYPE>KX</DOCUMENT_TYPE>

         <DOCUMENT_DATE>20140320</DOCUMENT_DATE>

         <POSTING_DATE>20140320</POSTING_DATE>

         <COMPANY_CODE>z1</COMPANY_CODE>    

         <Z1ZFI204_ITM SEGMENT="Z1ZFI204_ITM">

            <NET_INVOICE_AMOUNT>10.00</NET_INVOICE_AMOUNT>

            <EMPLOYEE_NAME>RAMESH</EMPLOYEE_NAME>

            <EMPLOYEE_NUMBER>test1</EMPLOYEE_NUMBER>

         </Z1ZFI204_ITM>

      </Z1ZFI204_HDR>

   </IDOC>

   <IDOC BEGIN="1">

      <EDI_DC40 SEGMENT="EDI_DC40">

         <TABNAM>EDI_DC40</TABNAM>

         <DIRECT>2</DIRECT>

         <IDOCTYP>ZFI204_AR_INV01</IDOCTYP>

         <MESTYP>ZFI204_AR_INV</MESTYP>

         <RCVPRN/>

      </EDI_DC40>

      <Z1ZFI204_HDR SEGMENT="Z1ZFI204_HDR">

         <DOCUMENT_TYPE>KX</DOCUMENT_TYPE>

         <DOCUMENT_DATE>20140320</DOCUMENT_DATE>

         <POSTING_DATE>20140320</POSTING_DATE>

         <COMPANY_CODE>z2</COMPANY_CODE>    

         <Z1ZFI204_ITM SEGMENT="Z1ZFI204_ITM">

            <NET_INVOICE_AMOUNT>20.00</NET_INVOICE_AMOUNT>

            <EMPLOYEE_NAME>ANKIT</EMPLOYEE_NAME>

            <EMPLOYEE_NUMBER>test2</EMPLOYEE_NUMBER>

         </Z1ZFI204_ITM>

         <Z1ZFI204_ITM SEGMENT="Z1ZFI204_ITM">

            <NET_INVOICE_AMOUNT>30.00</NET_INVOICE_AMOUNT>

            <EMPLOYEE_NAME>SIVA</EMPLOYEE_NAME>

            <EMPLOYEE_NUMBER>test3</EMPLOYEE_NUMBER>

         </Z1ZFI204_ITM>

      </Z1ZFI204_HDR>

   </IDOC>

</ZFI204_AR_INV01>

former_member190543
Participant
0 Kudos

Hi Hareesh,

I did copy the path, but still wondered in which version of PI is that possible? I mean taking the output of collapseContexts and mapping it to two different functions.

former_member184720
Active Contributor
0 Kudos

Hi Ramesh - It's available from 7.1

Mapping Output of Intermediate Fields to Multiple Target Fields

Muniyappan
Active Contributor
0 Kudos

Hi Ramesh,

check this mapping. it should work for you.

Regards,

Muni.

former_member190543
Participant
0 Kudos

Hi Muni,

I will try that now.

What should be the mapping for the "IDOC" node and "Z1ZFI204_HDR" node?

I have mapped createif condition to "IDOC" node (0 to unbounded) as I want to use only ITEM lines with field Org_Unit which has value starting with "z"

So,  If ---> first letter of "Org_Unit" equals to "z"  ----> createIf  ----> IDOC  (0 to unbound)

Can I leave it like that? and also what should be mapped to Z1ZFI204_HDR?

Many thanks mate.

Muniyappan
Active Contributor
0 Kudos

Hi,

Yes. you can try that. also you have to use similar logic for Z1ZFI204_ITM node.

for Z1ZFI204_HDR you can map any constant so that whenever you Idoc node gets created it will get created. i believe there is no logic for this node to be created.


Regards,

Muni.

former_member190543
Participant
0 Kudos

Hi Muni,

I have been trying different combinations, but the target fields are not being populated. Before I come to that there is a basic problem which is critical.

As you already may have understood, I have to create an idoc for every selected item line of the source. I am doing the selection by using createif and map it to the IDOC node. I also want all the items lines (Z1ZFI204_ITM) to be packed under one Z1ZFI204_HDR for item lines having same "Org_Unit".

Now the basic problem lies in the IDOC node. It is creating a separate Idoc for every line item no matter what the "Org_Unit" is. Is there a way to combine createif with other functions to achieve this?

PS: Apologies for giving different field names. I just made it simpler earlier, but looks like I am getting no where with that. This is the original mapping. I can give you the exact source and target xmls, but the source has many unused fields and is very long.

Many thanks.

I won't forget your help.

engswee
Active Contributor
0 Kudos

Hi Ramesh

You should use the function equalS under group "Text" when comparing with a AlphaNumeric constant.

Rgds

Eng Swee

Muniyappan
Active Contributor
0 Kudos

Hi Ramesh,

please share your sender and receiver xml. Me or someone else will be able to help you. sometimes you don't need written logic when you have source and target xml.

from your reply


you want to create separate idoc for selected line item of source.

say if you have 10 selected line items then it will create 10 idocs. this is not an issue.

but when coming to Z1ZFI204_HDR and Z1ZFI204_ITM these are mandatory. so each idoc must be having at least  one Z1ZFI204_HDR and one or more Z1ZFI204_ITM.

let us say you have 10 Org_Units for ten line items. for example z1,z1,z1, z1,z1,z1, z1,z1,z1,z2.

when you group these then it will give only 2. i.e z1 and z2.

this is going to cause issue as for 10 idocs you need Z1ZFI204_HDR nodes to be created.

you may need to check your logic. if you are creating idoc based on Org_Units then it will not cause any issue.

say in my above example you will get 2 idocs.

1st idoc will have z1,z1,z1, z1,z1,z1, z1,z1,z1 under Z1ZFI204_ITM.

2nd idoc will have z2 under Z1ZFI204_ITM.

Regards,

Muni.

former_member190543
Participant
0 Kudos

Hi Muni,

That is exactly how I want it. Multiple Idocs for different Org_Units and/or one idoc (with multiple ITEMs) for unique Org_Units.

I have attached the xsds for both Source and target. The actual fields are slightly different as I wanted to make them look easy. Attached are the originals.

The Org_Unit we were talking about is actually "Employee_Org_Unit_2" under "AR_Expenses_Item" node of source and is mapped to "COMPANY_CODE" under Z1ZFI204_HDR of target. The IDOC node creation is dependant on the contents of the field "Tax_Authority_Label" under "AR_Expenses_Item" node of source.



Many thanks.

Ramesh.

former_member190543
Participant
0 Kudos

Hi Muni,

I finally got it working

I have mapped "Org_Unit" to IDOC by formatByExample. Mapped a constant to Z1ZFI204_HDR. Mapped all fields under the Header directly. Mapped the item line condition to Z1ZFI204_ITM. Mapped all fields under the item lines of source to target fields under Z1ZFI204_ITM directly.

Many thanks for your time.

Regards,

Ramesh.

former_member190543
Participant
0 Kudos

Hi Eng,

I am using equalsS under "Text", but it is displayed like that as I am using 7.0  .

Thanks anyway

Muniyappan
Active Contributor
0 Kudos

Hi Ramesh,

Glad to hear you made it.

test the message mapping thoroughly to make sure everything works fine.

Regards,

Muni.

Answers (2)

Answers (2)

abranjan
Active Participant
0 Kudos

Hi Ramesh,

Based on the example provided by you, if you want 3 IDocs instead of 4, try the following in multimapping:

1. If the file is sorted

    In message mapping, take the queue of Field Y

      => Split by value (value change)              (Map it to Idoc_ITM)

      => Collapse Context    

      => Map to IDoc node of target structure. (Also, map the same to Idoc_HDR)

2. If the file is not sorted, sort it first and then follow the above point.

Hope this helps.

Thanks,

Abhishek

Muniyappan
Active Contributor
0 Kudos

you have to use below methods to create multiple idocs

File to Multiple IDOC Splitting without BPM - Process Integration - SCN Wiki