cancel
Showing results for 
Search instead for 
Did you mean: 

Add a context change after a set of values in a context

Former Member
0 Kudos

Dear experts,
My requirement is as follows:
Scenario: Idoc to Idoc. I need to check if there are line items > 5- I need to do a split. The split is happening properly via my mapping but I have a problem at the header record level on the target- I do not get the values populated correctly. I need to add a context change after 5 values in the queue.

eg:
Say there are 2 Idocs at the source with following unique IDs: called Journal ID:

My source:
Idoc 1: Journal ID 123
Line Itme 1
Line Item 2
Idoc 2: Journal ID 124
Line item 1
Line item 2
Line item 3
Line item 4
Line item 5
Line item 6
Line item 7

So I need to get total of three Idocs in my target:
Idoc 1: Journal Entry 123
Line Item 1
Line Item 2
Idoc2: Journal Entry 124
Line item 1
Line item 2
Line item 3
Line item 4
Line item 5
Idoc3: Journal entry 124
Line item 6(new 1)
Line item 7(new 2)

The split in the target Idoc is working perfectly. But inside the header record the journal ID field(taken from Item record level) is not populating correctly. I am getting this output:

Idoc 1: Journal Entry 123
Header Record-->JournalID Field value= '123'
Line Item 1
Line Item 2
Idoc2: Journal Entry 124
Header Record-->JournalID Field value= '124'
Line item 1
Line item 2
Line item 3
Line item 4
Line item 5
Idoc3: Journal entry 124
Header Record-->JournalID Field value= Null
Line item 6(new 1)
Line item 7(new 2)

So please suggest a UDF/standard function to populate the right values inside header record--->Journal ID field.Something like the below...

public void calculate(String[] var1, ResultList result, Container container) throws StreamTransformationException{

  for ( int i = 0; i < var1.length; i++ )
  {
     if( var1[i].length() > 5) //here var1 I am passing the Journal ID
       result.addContextChange();
  }

}

Apparently this doesnt work.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The first Idoc has two line items and the second idoc has 7 line items. As the split is per 5 line item- the target has 3 Idocs.

Now the problem is that the header value in the target: REF_DOC_NO has to be created as per the number of line items and doesnt come from header record directly.

Former Member
0 Kudos

Hi Smitha,

To match the context REF_DOC_NO field with the root node i.e ACC_DOCUMENT03 you will need to use the same logic what you used for the root node along with the element logic. If the root node and the child element are in the same context the issue will be resolved.

Thanks,

Divya.

Answers (4)

Answers (4)

Former Member
0 Kudos


Thank you all for your answers.

I was able to fix this by using the below logic:

The below "Display queue" features the three inputs and the final output.

Thanks for the direction Divya.. and others. Points will be rewarded accordingly.

Former Member
0 Kudos

It doesnt work.. as I need to count the number of lineitems and split the values to the corresponding header element. So can someone give the UDF for adding context change when the number of values in a context is greater than 5?

former_member220103
Active Participant
0 Kudos

Hi,

you can add the context change with the below method:

result.addContextChange();

you can also use the constant ResultList.CC as below:

result.addValue(ResultList.CC);

Thanks,

Kanda

gagandeep_batra
Active Contributor
0 Kudos

Hi Smitha,

You can use "useoneasmany" function for that

Regards

GB

Former Member
0 Kudos

Hi Smitha,

Please provide a screen grab of the mapping so that we can understand the exact requirement

Regards,

Sriram