cancel
Showing results for 
Search instead for 
Did you mean: 

PI Mapping issue

Former Member
0 Kudos

Hello All,

I am stuck in a recursive problem and would need your suggestions in getting it fixed.

I am mapping an ido to another. PFB the sample XML payload of a segment which occurs at least 5 times in sender payload.

Now, the problem is as follows.

If E1EDL24->POSNR starts with 0, create a new segment in target Idoc. Map the POSNR, VGPOS values.

If E1EDL24->POSNR doesnt start with 0, then check for existing segments created in target Idoc where the

VGPOS in target Idoc matches current segment HIPOS value. Add all such values and assign to the target segment.

In the below example, For the first 24 segment, a new segment will be created in Target Idoc.

However for second 24 segment, the value of LFIMG should be added to target Idoc value.

The case is same for third 24 segment.

SEt 1: One target segmet should be created with ID as 00001 and quantity as 20 + 28 = 48

<E1EDL24>

  <POSNR>00001<POSNR>

  <VGPOS>00001<VGPOS>

  <HIPOS>00001<HIPOS>

  <LFIMG>0.00<LFIMG>

</E1EDL24>

<E1EDL24>

  <POSNR>900001<POSNR>

  <HIPOS>00001<HIPOS>

  <VGPOS>00001<VGPOS>

  <LFIMG>20.0<LFIMG>

</E1EDL24>

<E1EDL24>

  <POSNR>900010<POSNR>

  <HIPOS>00001<HIPOS>

  <VGPOS>00001<VGPOS>

  <LFIMG>28.0<LFIMG>

</E1EDL24>

##-- SEt 2. One target segment should be created with ID as 00002 and quantity as 25 + 20 = 45

<E1EDL24>

  <POSNR>00002<POSNR>

  <HIPOS>00002<HIPOS>

  <VGPOS><VGPOS>

  <LFIMG>0.00<LFIMG>

</E1EDL24>

<E1EDL24>

  <POSNR>900002<POSNR>

  <HIPOS>00002<HIPOS>

  <VGPOS><VGPOS>

  <LFIMG>20.0<LFIMG>

</E1EDL24>

<E1EDL24>

  <POSNR>900002<POSNR>

  <HIPOS>00002<HIPOS>

  <VGPOS>00002<VGPOS>

  <LFIMG>25.0<LFIMG>

</E1EDL24>

Any suggestions are highly appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Magic,

Please check this blog

Please write UDF similar to this.


    public void udf_getSeg(String[] POSNER, String[] VGPOS, String[] HIPOS, String[] LFIMG, ResultList POSNR_out, ResultList VGPOS_out, ResultList HIPOS_out, ResultList LFIMG_out, Container container) throws StreamTransformationException {

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

            if (POSNER[i].startsWith("0")) {

                POSNR_out.addValue(POSNER[i]);

                VGPOS_out.addValue(VGPOS[i]);

                HIPOS_out.addValue(HIPOS[i]);

                int sum = 0;

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

                    if (VGPOS[i].equals(VGPOS[j])) {

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

                    }

                }

                LFIMG_out.addValue(sum);

            }

           

        }

    }

Former Member
0 Kudos

Thanks for your valuable inputs Vamsi. Would you please comment why you have used ResultList POSNR_out, ResultList VGPOS_out, ResultList HIPOS_out, ResultList LFIMG_out,


I didn't get you why you are using so many Out variables.

we need to check whether the POSNR is starting with 0 or not. If yes, then iterate over the EDL24 segments and then consider only the LFIMG values, whose HIPOS value matches with POSNR value. And then return the total count.

Thank you again for your suggestions.

RaghuVamseedhar
Active Contributor
0 Kudos

Magic,

Why there are so many output fields?

To get corresponding values, when POSNR does not start with "0". If we do not use all output variable, we will get wrong values. The code is sample, you can edit as per the actual requirement.

I suggest to implement the "grouping part" in the blog mentioned above in sandbox. You will get better idea about this issue.

Sample code: -


public void udf_getSeg(String[] POSNER, String[] VGPOS, String[] HIPOS, String[] LFIMG,ResultList Segment_out, ResultList POSNR_out, ResultList VGPOS_out, ResultList HIPOS_out, ResultList LFIMG_out, Container container) throws StreamTransformationException {

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

            if (POSNER[i].startsWith("0")) {

                Segment_out.addValue("");

                POSNR_out.addValue(POSNER[i]);  POSNR_out.addContextChange();

                VGPOS_out.addValue(VGPOS[i]);   VGPOS_out.addContextChange();

                HIPOS_out.addValue(HIPOS[i]);   HIPOS_out.addContextChange();

                int sum = 0;

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

                    if (VGPOS[i].equals(VGPOS[j])) {

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

                    }

                }

                LFIMG_out.addValue(sum);    LFIMG_out.addContextChange();

            }

         

        }

    }

Former Member
0 Kudos

A big thumbs up for your prompt answers.

I got what you are saying, but i think, you are missing one point at a time. This is making the scenario complex.

- If Posnr starts with 0 then target node exists. If not, no logic is required. Now we have created target node. we need to calcuate quantity.

- In the above created target node, we need to populate quantity. How should it be calculated?

- We need to iterate over the list of EDl24 segments and compare Posnr (*** of the root, which starts with 0) with Hipos (of Edl24 segments which have posnr field which doesn't start with 0) and then extract a sum of lfimg values and return it to the quantity.

Regards.

RaghuVamseedhar
Active Contributor
0 Kudos

Magic,

Please implement above UDF. Remove the context of input fields.

I am sure, you will get closer to what you want. Then you can tweak the logic.

RaghuVamseedhar
Active Contributor
0 Kudos

Magic,

Attaching screenshots.

Former Member
0 Kudos

Thanks a Lot Vamsi.

Your posts have helped me in better understanding and breaking down the problem further and address the same. The problem is resolved now with a combination of UDF's and graphical mapping. Thank you once again.

Answers (0)