Skip to Content
author's profile photo Former Member
Former Member

java udf

Hello sdners

I need help with a java udf.

I am not sure how to write in java ,the udf for belwo scenario and wheter it will be value or context or que function.

Scenario is file to idoc

Source

DHP

D1 : Invoice

PLK

P1 : AB

P2 : 123

PLK

P1 : CD

PLK

P1 : DE

P2 : 456

Requirement is : To substring ( first 4 chars) of D1 coming in DHP segment and concatenate with P2 if qualifier is DE in P1 then map this logic to a field in target.

Important point to consider is that if we see that second PLK segment does not have P2 so we cannot do something like we extract a<i> and then take b<i> corresponding since the queue for P2 had 2 values whereas queue for P1 has 3 values.

Can we achieve this ?

Thank you.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 09, 2008 at 01:24 AM

    Hi Dennis

    What i understand is

    You need to check D1(substring 4 character of DHP) concatenate P2( or PLK) = DE (in PLK P1) then map to target

    with this if the P1 and P2 are not present in equal number you dont want to map it or something else ??

    Thanks

    Gaurav

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Dennis

      public void returnTarget(String[] P1, String[] P2, ResultList result,Container container)
      {
          //write your code here
      String output="";
       
        for(int i=0;i<P1.length;i++){
      			if(P1<i>.equalsIgnoreCase("DE")){
      				for(int j=0;j<P2.length;j++){
      					output=output+P2[j];
      				}
      				
      			}
      		}
      result.addValue(output);
      } 

      Try using the UDF then removeContext and concatenate it to result of D1 substring (0,4) and map to target.

      Thanks

      Gaurav

  • author's profile photo Former Member
    Former Member
    Posted on Oct 09, 2008 at 01:28 PM

    Hello

    I want this whole logic in a java udf as I have some other logi also to be performed ,so with so many boxes it would look very unreadable.

    Thank You.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 09, 2008 at 01:49 PM

    Hello,

    Please try below mentioned UDF, using some standard functions as:

    1. SubString function: For providing first 4 character of D1, these should be used as one input parameter to udf.

    2. MapwithDefault function: Provide P2 value as input to these function. The output of these function would serve as 2nd input to our udf.

    Use the below mention logic:

    Input values to this udf are: Input,P1, P2

    {start of code}

    int i ;

    String output;

    for(i=0;i<P1.length;i++)

    {

    if(P1<i>.equals("DE"))

    {

    output = Input[0] + P2<i>;

    result.addValue(output);

    }

    }{End of code}

    BR,

    Rahul

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 09, 2008 at 02:11 PM

    Hello,

    It would not be so tough.

    Just keep the context of P2 to its immediate parent node. Use mapWithdefault function and then use remove context function. Now u would be getting exact number of values as in P1.

    BR,

    Rahul

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.