cancel
Showing results for 
Search instead for 
Did you mean: 

need user define function for the message mapping structure

former_member187457
Active Contributor
0 Kudos

Hi All

I am new to XI.I need the java code for Udf for the following structure.

i have two input and one out put as error.

order_nos----


\

-


user define function-------error message

/

order_details----


num of orders---- i.e. 10

order_details------ i.e. whole order records details

1.i have to compare the 1st input with 2nd one means if the ist input contain 10 means there are 10 orders in 2nd input.if not then i have to give error message .

2.then i have to check the fields in 2nd input has no null values.if no values the output will be error message.

Edited by: Rohit Kumar on Dec 18, 2008 4:43 PM

Accepted Solutions (1)

Accepted Solutions (1)

SudhirT
Active Contributor
0 Kudos

Hi,

Try like this

int len = 0;
if(a.length>b.length)
len = a.length;
else
len = b.length;
for(int i=0;i<len;i++)
{
  if(b<i>.equals("") || (b.length != a.length))
result.addValue("Error Message");
else
result.addValue("SUCCESS");
}

Dont forget to use removeContext before both the inputs to UDF and then use the UDF with advance mode.

Thanks!

Edited by: Sudhir Tiwari on Dec 18, 2008 12:28 PM

former_member187457
Active Contributor
0 Kudos

Hi Sudhir

thanks for your reply.

i have taken a variable and b as a array.so its giving error

if(a.length>b.length) ^ /usr/sap/SXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map06788e70ccf911dd9eb80017a451d1ec/source/com/sap/xi/tf/_ROD_SH_REQUEST_ABS_MM_.java:206: cannot resolve symbol

symbol : variable length location: class java.lang.String len = a.length; ^ /usr/sap/SXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map06788e70ccf911dd9eb80017a451d1ec/source/com/sap/xi/tf/_ROD_SH_REQUEST_ABS_MM_.java:211: cannot resolve symbol symbol : variable length location: class java.lang.String if(b<i>.equals("") || (b.length != a.length)) ^ /usr/sap/SXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map06788e70ccf911dd9eb80017a451d1ec/source/com/sap/xi/tf/_ROD_SH_REQUEST_ABS_MM_.java:212: cannot resolve symbol symbol : variable result location: class com.sap.xi.tf._ROD_SH_REQUEST_ABS_MM_ result.addValue("Error Message"); ^ /usr/sap/SXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map06788e70ccf911dd9eb80017a451d1ec/source/com/sap/xi/tf/_ROD_SH_REQUEST_ABS_MM_.java:214: cannot resolve symbol symbol : variable result location: class com.sap.xi.tf._ROD_SH_REQUEST_ABS_MM_ result.addValue("SUCCESS").

i am not able to solve it becos i dont know java.please reply.

SudhirT
Active Contributor
0 Kudos

Rohit,

The same code i tried here its working. While creating UDF select the "Context" option and the list should contain variables "a","b" and "result".

I donno why its not working in your system.

Copy the same code as i written and use removeContext before both the inputs to UDF.

Thanks!

former_member187457
Active Contributor
0 Kudos

Hi

thanks for ur reply.

as u said i have the following.

public void Validate(String[] a,String[] b,ResultList result,Container container){

after this should just copy paste your code.

SudhirT
Active Contributor
0 Kudos

Yes.

former_member187457
Active Contributor
0 Kudos

hi

thanks for your reply

can i call u now because i am getting error that

Argument missing in function Validate

SudhirT
Active Contributor
0 Kudos

Hi,

Did you pass both the fields as input to the UDF. I guess you passed only one argument like NUM . you need to pass also the Order_Detail as second argument.

and before passing use removeContext for both arguments.

Thanks!

former_member187457
Active Contributor
0 Kudos

Hi Sudhir

thanks for your continues help.i need some help so that i can fulfill my requirmrnt

this is my message mapping xml.

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

- <ns0:methodCall_MT xmlns:ns0="http://www.dfdsf">

<num_orders>10</num_orders>

<test_mode />

- <order_x> ( which is order details)

<order_id>t78tyu8t</order_id>

<order_date />

<mfg_id />

<catalog_id />

<first_name />

<last_name />

<recipient />

<message />

<address1 />

<address2 />

<address3 />

<city />

<state />

<zip />

<country />

<country_code />

<phone />

<subtotal />

<tax />

<shipping />

<total />

<shopatron_total />

<fulfiller_total />

<shipment_id />

- <additional_info>

<in_store_pickup />

- <express_shipping>

<express_shipping_flag />

<express_shipping_text />

<express_shipping_arrival />

</express_shipping>

</additional_info>

- <discount>

<discount_description />

<discount_percentage />

<discount_total />

</discount>

<lang_id />

<currency_id />

<packing_list />

<num_items />

- <items>

<item_id />

<quantity />

<price />

<part_number />

<fulfiller_total />

<shopatron_total />

- <options>

<option_x />

</options>

</items>

</order_x>

</ns0:methodCall_MT>

this my mapping where under one element number elements are there.when i am excuting the code to check the null value its always giving the there is null val but i have filled evrything.its due to first its checking the order_x and which will be always null.uder this all data will be filled.please suggest what to change in the udf.the code given by u is working fine but its failing in this scenario because it getting the parent filed is null.

SudhirT
Active Contributor
0 Kudos

Hi Rohit,

Your mapping will look like

Num_Orders---------------------------------------------------------------->
                                                                                UDF----->Target
Order_ID(not detail)------>removeContext(Node Function)-->

Also according to your requirement the UDF will be like

int len = Integer.parseInt(a[0]);

for(int i=0;i<len;i++)
{
  if(b.length != len){
result.addValue("Error Message");
break;
}
else if(b<i>.equals(""))
result.addValue("Error Message");
else 
result.addValue("SUCCESS");
}

Thanks!

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

try the following UDF,

if(Integer.parseInt(firstInput[0]) == secondInput.length)
{
  for(int i = 0;i<secondInput.length;i++)
  {
    if(secondInput<i>.equals(""))
    {
     result.addValue("Error Message");
    }
    else
    {
      //logic to handle secondInput
    }
  }
}
else
{
  result.addValue("Error Message");
}

-Rohit

former_member193376
Active Contributor
0 Kudos

Hi

If your input is just the value of order no, then you wont need a UDF, you can do it with standard functions.

First check if 2nd value has value or not, do that by using IF THEN using a blank constant if its true then

Use another IF THEN and check if 1st input is = to 2nd, if true then pass the value of 2nd input to output.

Hope this helps

Thanks

Saiyog

former_member187457
Active Contributor
0 Kudos

Hi SG

thanks for your reply.but in my scenario i have check the order no and the order details contains the

same number .then for this i think we cant use any standard function .so i didnt get your answer.