Skip to Content
avatar image
Former Member

User-Defined Function and Context Manipulation

Hi Mapping Gurus, I need your help.

I have a user-defined function and one of my input parameter (c) is in a loop (EDI segment). So one, if I execute my function I get:

Exception:[java.lang.ArrayIndexOutOfBoundsException: 0]

If I change the context or use the remove context node function it’s working but it’s always taking the first row in consideration since I'm using c[0] . Here is the logic:

String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[0]"'";

So since c is an array [], I have tried different logic to get to the right row.

1- I tried using another parameter (e) to pass a counter or an index to my function. So each time it's looping, it's passing a new value to the function but I’m still getting the first row and I’m not to sure why?

int G = Integer.parseInt(e[0]); // e[] = My counter field

String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";

2- I tried using a parameter stored in the container:

String Num;

Num = (String)getParameter(“counter”);

if (Num == null) G = 0;

else

{

G = Integer.parseInt(Num);

G = G + 1;

}

String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";

Num = "" + G;

setParameter(e[0], Num);

and I’m still getting the first one, look like it’s using a different container each time it’s looping so the Value is always the same?

4- I created a new user-defined function with the container logic, then it’s working but I’m back to the same problem in my main function, it’s only looking at e[0] for my counter all the time.

5- I tried using the Seeburger Java Variables and guess what in the main fonction, as new UDF,... and guess what, same result!

So anybody out there that was able to get UDF's working into a multiple context scenario?

Am I missing something?

I will reward points and beer for any help!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

9 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 21, 2008 at 01:53 AM

    I'm using the counter to loop at field D_234.

    Since D_234 =

    [1234565]

    [3453324]

    [3433433]

    [3243543]

    The first loop i want to do the select with [1234565] then on the second pass select with [3453324].

    But for what ever logic I put in my select always pict the first entry in the D_234 so [1234565].

    In my function, D_234 inbound is parameter c[].

    So I was trying to pass a counter to the function to force to logic to see [3453324] on the second loop but this is what I'm not getting to work.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      try for-loop, it should loop all the values in the queue

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

      {

      //put your logic here

      };

  • Feb 21, 2008 at 12:48 AM

    Yves,

    First beer, then we will start working , juz kidding 😊

    What is the source stucture and what's the logic. If you could explain, will try to sort it out.

    raj.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 21, 2008 at 12:58 AM

    The source structure is an EDI document

    ST

    G_SLIN 1..9999999

    S_LIN 1.1

    D_234 1..1

    My logic resides in the D_234 filed. So the inbound and outbound structure is the same, I just added some lookup logic to validate/change some data sent data sent by customers before sending it to the legacy system. So here is a representation of my graphical mapping in field D_234:

    Field1----


    Field2----


    User-Defined Function -


    D_234

    D_234—RemoveContext---

    Counter----


    Add comment
    10|10000 characters needed characters exceeded

    • Yves,

      one more thing, from your code you always coded like a(0) or b(0) etc.. Actually u've to run a loop and u need to give a(i) or b(i) etc..

      for example

      for(int i=0;i<c.length;i++)
      {
      result.addValue(a<i>);
      }
      

      raj

      Edited by: Raj on Feb 20, 2008 7:12 PM

  • avatar image
    Former Member
    Feb 21, 2008 at 01:17 AM

    It does look bad!!!

    So 1, inbound and outbound structures are the same

    2- D_234 is a field under S_LIN segment. S_LIN is under G_SLIN. This what just to explain the structure.

    ST

    G_SLIN 1..9999999

    S_LIN 1.1

    D_234

    So I have 4 input parameters in my function. Field1, Field2, D_234 and a counter.

    And the result is going back to field D_234 in the outbound EDI.

    Field1----


    >

    Field2----


    > User-Defined Function-> D_234

    D_234—RemoveContext->

    Counter----


    >

    Thanks

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member
      • If your "Counter" parameter is just for incrementing your D_234 field, it is really unnecessary

      Suggest you remove it, just define a integer like what Raj suggested

      • You removed the context before UDF, have you added context by insert SplitByValue[each Value]?

      Liang

  • avatar image
    Former Member
    Feb 21, 2008 at 01:30 AM

    This is one of the text with passing a counter to the function to try to go to the right row in the array since I'm doing a remove context and I'm getting all the d_234's:

    public void ReadTable(String[] a,String[] b,String[] c,String[] d,String[] e,ResultList result,Container container){

    int G = Integer.parseInt(e[0]); // My counter

    String var;

    String DBTABLE = a[0];

    String lookUpField = d[0];

    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";

    Now this one was with the internal container logic:

    int G;

    String DBTABLE = a[0];

    String lookUpField = d[0];

    String Num;

    Num = (String)getParameter(e[0]);

    if (Num == null) G = 0;

    else

    {

    G = Integer.parseInt(Num);

    G = G + 1;

    }

    Num = "" + G;

    setParameter(e[0], Num);

    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";

    And now with the Seeburger Variables:

    int G;

    try {

    VariableBean be=VariableFactory.getVariableInstance("");

    G = Integer.parseInt(String.valueOf(be.getStringVariable("yves")));

    } catch (Exception f) {

    throw new RuntimeException(f);

    }

    String DBTABLE = a[0];

    String lookUpField = d[0];

    String WHERE_CLAUSE = "A"" = ""'"b[0]"'"" and B = ""'"c[G]"'";

    try {

    G = G + 1;

    Num = "" + G;

    VariableBean be=VariableFactory.getVariableInstance("");

    be.setStringVariable("yves",Num);

    }

    catch (Exception f) {

    throw new RuntimeException(f);

    }

    All 3 logics were returning always the first row or a counter of 1 if the logic is in the main ReadTable function.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 21, 2008 at 01:33 AM

    I am using the result.addValue at the end of the function, When I say "returning the first row" I'm talking about the first row in the field used in the select statement, not the end result on the function.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 21, 2008 at 01:38 AM

    With contexts, I get:

    Exception:java.lang.ArrayIndexOutOfBoundsException: 0

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Put some test data, and run your test, then go back to design page, display queue of your UDF, to see what are the inputs and what are the output,

      you debug from there, you should get the reason why the counter is not incremented.

      Liang

  • avatar image
    Former Member
    Feb 21, 2008 at 02:02 AM

    I think the problem with the counter is the same thing, in the first loop, the counter sends

    1 so e[0] = 1

    in the second loop

    Counter =

    1

    2

    So in the function the counter e[0] still see 1. I think?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I believe that your line:

      setParameter(e[0], Num); cause the problem.

      If you want to setParameter and getParameter from container, you should use different variable, rather than using the passed parameter, espcially, your passed parameter is constants array.

      I would like to know your UDF choose which type of cache value ? Context or Queue ?

      Liang

  • avatar image
    Former Member
    Feb 21, 2008 at 02:20 AM

    Yes !!!!!!!!!!!!!!!!!!!!!!!!

    I didn’t want to put all the logic inside the loop in the first place since I was thinking that it would always get the last one.

    So I’m now using a remove context with the entire logic in the loop and its working. So Raj was right two hours ago. Thanks to both of you.

    Next time you are in Ottawa beer is on me!

    Now, how can I split the point?

    Rgds,

    Yves

    Add comment
    10|10000 characters needed characters exceeded