cancel
Showing results for 
Search instead for 
Did you mean: 

Segment does not repeat based on values in a context

Former Member
0 Kudos

Hi

I have a E1FISEG segment with occurrence 0...999.

My source message is as below

Invoice

     VendorLine

     GLLine

          Taxcode

          Taxamt

     GLLine

          Taxcode

          Taxamt

This segment needs to repeat as below

1. Once for Vendor data

    This is working. VendorLine mapped to E1FISEG.

2. Once for every GL Line.

     For this I have duplicated the subtree for the above segment - E1FISEG[1].

     This is working fine. GLLine mapped to E1FISEG[1]

3. The GLLines can have different tax codes. I have to calculate the total of tax amount per tax code within an invoice. I have done this using below mapping.

For this I have duplicated the subtree once more to get E1FISEG[2].

I am able to sort the values per tax code for the tax amount as indicated below.

I now need to sum the amount per tax code - sum(V0) = 0; sum(V1) = 50, sum(V2) = 20.

I need to create one E1FISEG[2] for every sum that is greater than 0 - thus here I expect 2 E1FISEG[2] segments in output.

Please help.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Nobendu

Did the udf and mapping - however I see only one E1FISEG in the target. Please could you guide me further since I am stuck at this point and new to udfs / contexts.

See diagram below

Former Member
0 Kudos

Just to add that I have kept the execution type as All values of a context for the UDF

nabendu_sen
Active Contributor
0 Kudos

Hi Girish,

Use the below code in UDF with other Node Functions as mentioned in the screenshot. It should work.

  1. double sum = 0.00;
  2. for (int i=0;i<taxcode1.length;i++)
  3. {   
  4.       sum = 0.00;
  5.      for (int j=0;j<taxcode2.length;j++)
  6.      {
  7.        
  8.         if (taxcode1[i].equals(taxcode2[j]))
  9.         {
  10.               sum = sum + Double.parseDouble(taxamnt[j]);
  11.         }
  12.       }
  13.              if (sum > 0.00)
  14.             result.addValue("");
  15. }

nabendu_sen
Active Contributor
0 Kudos

Hi Girish,

Try with UDF, would be much easier than normal graphical mapping.

nabendu_sen
Active Contributor
0 Kudos

You can try something like below. <taxcode1> and <taxcode2> both have same input. After that UDF SplitbyValue. May be syntax error present, check in your editor.

public void SumAmount(String[] taxcode1, String[] taxamnt, String[] taxcode2 ResultList result, Container container) throws StreamTransformationException{

for (int i=0;i<taxcode1.length;i++)

{

     for (int j=0;j<taxcode2.length;j++)

     {

        int sum = 0;

        if (taxcode1[i].equals(taxcode2[j]))

        {

               sum = sum + Integer.parseInt(taxamnt[j]);

        }

        if (sum > 0)

        result.addValue("");

     }

  

}