cancel
Showing results for 
Search instead for 
Did you mean: 

Context udf :array

Former Member
0 Kudos

Hello sdn

I want to convert this udf into context udf : i have opened a new thread as previous thread was growing too big.

requirement is:

Eg : if source text field value is : ST - 102RP34;RP - 234ST89;VT - 90789ST;

Then in target side i want to create a sement for qualifier RP and its corresponding field should have a value : 234ST89

In the below context function ,a is being passed,qualifier is returned. but these are single values although we need to pass and retrun an array of values.

public void qualifier(String[] input,ResultList result,Container container)

{

String element, qualifier ="";

StringTokenizer token1 = new StringTokenizer( input, ";");

while (token1.hasMoreTokens())

{

element = token1.nextToken();

StringTokenizer token2 = new StringTokenizer( element, "-" );

qualifier = token2.nextToken();

result.addValue(qualifier);

}

}

}

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Hello,

Could you please reply us your source and target structure with occurrences? It will be more helpful to suggest the soln.

Thanks,

raj

Former Member
0 Kudos

Hello sdn

source is a text field having value : ST - 102RP34;RP - 234ST89;VT - 90789ST;

Then in target side i want to create a segment for qualifier RP and its corresponding field should have a value : 234ST89

Thanks

Edited by: Guest1 guest on Oct 31, 2008 7:11 PM

Former Member
0 Kudos

I will give shot for last time..modify the UDF as below..


public void qualifier(String[] input, ResultList result,Container container)
{
String element, qualifier ="";
StringTokenizer token1 = new StringTokenizer( input, ";");
while (token1.hasMoreTokens())
{
element = token1.nextToken();
StringTokenizer token2 = new StringTokenizer( element, "-" );
qualifier = token2.nextToken();
 if ( qualifier.equals("RP"))   // or u can pass constant that will have this qualifier
 {    value = token2.nextToken();   //
      result.addValue(value);
 }
}
}
}

GUI looks like this.

Text Element ---> UDF ---> PR Element

Edited by: Anand on Oct 31, 2008 7:17 PM

Former Member
0 Kudos

Error message :

cannot resolve symbol symbol : constructor StringTokenizer (java.lang.String[],java.lang.String) location: class java.util.StringTokenizer StringTokenizer token1 = new StringTokenizer(a, ";");

cannot resolve symbol symbol : variable value location: class com.sap.xi.tf._MAP1_ { value = token2.nextToken(); //

cannot resolve symbol symbol : variable value location: class com.sap.xi.tf._MAP1_ result.addValue(value);

justin_santhanam
Active Contributor
0 Kudos

Dear Guest,

Please don't repeat the same sentence again and again. we understood ur reqmt, we are asking for the structure. I mean the XML elements.

raj.

Former Member
0 Kudos

>

> Error message :

>

> cannot resolve symbol symbol : constructor StringTokenizer (java.lang.String[],java.lang.String) location: class java.util.StringTokenizer StringTokenizer token1 = new StringTokenizer(a, ";");

>

import java.util.StringTokenizer; //add this line beginning of the function.

>

> cannot resolve symbol symbol : variable value location: class com.sap.xi.tf._MAP1_ { value = token2.nextToken(); //

>

>

> cannot resolve symbol symbol : variable value location: class com.sap.xi.tf._MAP1_ result.addValue(value);


value = token2.nextToken(); 
change to
String value = token2.nextToken(); 

Former Member
0 Kudos

Hello sdn

IDOC -File

xml structure

Source:

E1EDL43 (Repeating segment)

SEGMENT

TDID ST-102RP34;RP-234ST89;VT-90789ST;

Target:

MSG (Repeating segment)

D_108 102RP34

MSG (Repeating segment)

D_108 234ST89

MSG (Repeating segment)

D_108 90789ST

Thanks

justin_santhanam
Active Contributor
0 Kudos

Dear Guest,

Thanks for your understanding! Could you please let me know whether you are looking to achieve something like below?


Source:
<?xml version="1.0" encoding="UTF-8"?>

<ns0:Source xmlns:ns0="urn:xitest">
   <E1EDL43>
      <SEGMENT>
         <TDID>ST-102RP34;RP-234ST89;VT-90789ST;</TDID>
      </SEGMENT>
   </E1EDL43>
   <E1EDL43>
      <SEGMENT>
         <TDID>ST-555RP34;RP-777ST89;VT-34589ST;QT-987RP34;</TDID>
      </SEGMENT>
   </E1EDL43>
</ns0:Source>


<?xml version="1.0" encoding="UTF-8"?>
<ns0:Target xmlns:ns0="urn:xitest">
   <MSG>
      <D_108>234ST89</D_108>
   </MSG>
   <MSG>
      <D_108>777ST89</D_108>
   </MSG>
   </ns0:Target>

Thanks,

raj.

Edited by: Raj on Oct 31, 2008 2:57 PM

Former Member
0 Kudos

Hello Raj

Yes I am looking for something like this.

Just that currently E1EDL43 is not repeating.

Source

Source:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Source xmlns:ns0="urn:xitest">

<E1EDL43>

<SEGMENT>

<TDID>ST-102RP34;RP-234ST89;VT-90789ST;</TDID>

</SEGMENT>

</E1EDL43>

</ns0:Source>

Target one more MSG segment: MSG segment is created for each qualifier : ST,RP and VT

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Target xmlns:ns0="urn:xitest">

<MSG>

<D_108>102RP34</D_108>

</MSG>

<MSG>

<D_108>234ST89</D_108>

</MSG>

<MSG>

<D_108>90789ST</D_108>

</MSG>

</ns0:Target>

Thanks

justin_santhanam
Active Contributor
0 Kudos

Please follow the below logic.

Create two UDF's

UDF1 - gen_MSG

Cache : Queue

Argument :TDID


int count =0;

for(int i =0;i<TDID.length;i++)
{
StringTokenizer st  = new StringTokenizer(TDID<i>, ";");
count = count+ st.countTokens();
}

for(int i=0;i<count;i++)
{
result.addValue("");
}

UDF2 - gen_element

Cache : Queue

Argument :TDID


String temp1="";
String temp2="";
for(int i =0;i<TDID.length;i++)
{
StringTokenizer st  = new StringTokenizer(TDID<i>, ";");

while(st.hasMoreTokens())
{
temp1 = st.nextToken();
temp2= temp1.substring(temp1.indexOf("-")+1, temp1.length());
result.addValue(temp2);
}
}

Mapping Logic


TDID [Change Context to higher node] --->Trim[ Standard Text Function]---> gen_MSG[UDF1] --->MSG


TDID [Change Context to higher node] --->Trim[ Standard Text Function]---> gen_element[UDF2] --->D_108

I've checked the codes and it's working fine.

I hope it helps!

Thanks,

raj.

Edited by: Raj on Oct 31, 2008 3:17 PM

Former Member
0 Kudos

Hi Guest

In your previous post i have provided a code that returns exactly what you are looking for

To use that you need to use import statement in UDF and import import java.util.StringTokenizer

Mapping logic is already given above by Raj. That will work

Thanks

Gaurav

Former Member
0 Kudos

Hello Raj

The above code works.

Just that had to add splitbyvalue in field level mapping.

Another req is that if we add one more field in target

Source:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Source xmlns:ns0="urn:xitest">

<E1EDL43>

<SEGMENT>

<TDID>ST-102RP34;RP-234ST89;VT-90789ST;</TDID>

</SEGMENT>

</E1EDL43>

</ns0:Source>

Target one more MSG segment: MSG segment is created for each qualifier : ST,RP and VT

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Target xmlns:ns0="urn:xitest">

<MSG>

<D_107>ST</D_107>

<D_108>102RP34</D_108>

</MSG>

<MSG>

<D_107>RP</D_107>

<D_108>234ST89</D_108>

</MSG>

<MSG>

<D_107>VT</D_107>

<D_108>90789ST</D_108>

</MSG>

We need another udf for this D_107 which needs the qualifier ?

Thanks

justin_santhanam
Active Contributor
0 Kudos

Yes you are correct. Please follow the below logic.

UDF3 - gen_element2

Cache : Queue

Argument :TDID



String temp1="";
String temp2="";
for(int i =0;i<TDID.length;i++)
{
StringTokenizer st  = new StringTokenizer(TDID<i>, ";");
 
while(st.hasMoreTokens())
{
temp1 = st.nextToken();
temp2= temp1.substring(0,temp1.indexOf("-"));
result.addValue(temp2);
}
}

raj.

Former Member
0 Kudos

Hello Raj/Anand/Gaurav

Thank You.

Raj :It works : For D_107 :

Even the below line of code was working

temp2= temp1.substring(temp1.indexOf("-") -2, temp1.indexOf("-"));

I have one issue though,I dont know whether it is related to udf or something else ( Cache)

if i have xml :

Source:

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Source xmlns:ns0="urn:xitest">

<E1EDL43>

<SEGMENT>

<TDID>Ab-102RP34;RP-234ST89;ST-St01;RP-234ST89</TDID>

</SEGMENT>

</ns0:Source>

In the above xml : when i run the test tool in mapping,it fails for the first time. If i remove the ST-St01,it is successfull or even if i delete the"-" and put again the"-" it works. Is this some general issue with XI /cache or something with the udf? The "-" seems to be the problem ,if i delete it and put it again ,it runs fine?

The combination of ST-St01 gives problem.

Any suggestions?

Thanks

Edited by: Guest1 guest on Oct 31, 2008 11:31 PM

justin_santhanam
Active Contributor
0 Kudos

Hello,

There is no issues with the UDF for sure. Could you please activate all the objects and give a try?

raj.

Former Member
0 Kudos

Hi

I understand there r no issues with the udf.

i activated ,closed XI and opened again too.

I guess in the IDOC when it comes ST-Sto1,it looks like a "-" but it might be some other symbol.

How i make it to work is : by deleting the "-" in ST-St01 and putting again the "-".Can we automate this ? it is only happening at ST-St01,other segments work fine.

Symbol might be different although it looks like a "-"

Any suggestions ,how i could check or some quick fix?

Thanks

justin_santhanam
Active Contributor
0 Kudos

Hello,

What do you mean by some other symbol? Do you know exactly what symbol you are getting?

raj.

Former Member
0 Kudos

Hello

I looked in Xml and yes it is different

For ST-St01,we have a longer "-" similar to "_" but it comes as a dash and not as an underscore.

So for ST-St01 could we replace it by "-" .

XML Eg :

<TDID>RP-RP01;STu2013Sto2;VT-ST09</TDID>

Thanks

Edited by: Guest1 guest on Nov 1, 2008 12:35 AM

justin_santhanam
Active Contributor
0 Kudos

In your Mapping logic for DS_108 and DS_107 target fields, after the trim function( which I have given in my previous replies) apply replaceAll function, it must replace the special character with whichever value want.

raj.

Former Member
0 Kudos

Thanks Raj /Anand/Gaurav.

Will close this thread and award the points.

Answers (0)