cancel
Showing results for 
Search instead for 
Did you mean: 

Help with UDF

sendhil_kumar
Active Participant
0 Kudos

Hi,

My requirement is if Year (String data type) is between 2001 and 2009 and Price(String again) between 4000 and 6000 then populate the target field with "Okay".

Or if the year is between 2010 and Current Year (Dynamic) and price between 8000 and 10000 then Populate the target field with Okay

if both not satisfied "Not Okay".

Also note that the Year and Price is under Details node, which might have multiple instances in the source.

Can you please help me with UDF for this requirement.

--

Sendhil

Accepted Solutions (1)

Accepted Solutions (1)

sendhil_kumar
Active Participant
0 Kudos

Hi All,

I understand, it can be acheived using standard functions, the reason I am asking here is to understand the multiple functions in UDFs.

1. How to acheive the less than and Greater than for string data types.

2. What would be return Value for returning Sting "Okay or Not OKay"

3. UDF is based on Context or Queue, if so how it is handled.


I should have put it in the first place, my Bad.

Inorder to understand these questions, I was asking UDF which would give a clear idea. Please provide your inputs.


My Source Structure.


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

<ns0:MT_SRC_ZIP_FCC xmlns:ns0="http://vodafone.com/sendhil/test">
   <Header>
      <Brand>Test</Brand>
      <Model>Test</Model>
   </Header>
   <Details>
      <Year>1999</Year>
      <Price>4000</Price>
   </Details>
   <Details>
      <Year>2000</Year>
      <Price>9000</Price>
   </Details>
   <Details>
      <Year>1985</Year>
      <Price>1000</Price>
   </Details>
</ns0:MT_SRC_ZIP_FCC>

--

Sendhil

former_member182412
Active Contributor
0 Kudos

Hi Sendhil,

Use below UDF and execution type is "All Values of Context". Pass year and price fields to the UDF.


public void mapBuyOption(String[] year, String[] price, ResultList result, Container container) {

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

            int yearInt = Integer.parseInt(year[i]);

            int priceInt = Integer.parseInt(price[i]);

            int currentYear = Calendar.getInstance().get(Calendar.YEAR);

            if ((yearInt >= 2001 && yearInt <= 2009 && priceInt >= 4000 && priceInt <= 6000)

                    || (yearInt >= 2010 && yearInt <= currentYear && priceInt >= 8000 && priceInt <= 10000)) {

                result.addValue("Okay");

            } else {

                result.addValue("Not Okay");

            }

        }

    }

Regards,

Praveen.

sendhil_kumar
Active Participant
0 Kudos

Thanks Praveen, That cleared my doubts.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

Do it in the below way in graphical mapping

Output of second if-else block will be input to the else in first if-else block.

Replace id with year and refname with price.

Let me know if u have any doubts.

Thanks,

Indrajit

iaki_vila
Active Contributor
0 Kudos

HI Sendhil,

You can do it with standard functions, try to use the boolean function If and And, also the arithmetic greater and less. You can set the constants with the constant function to set the years.

Check examples here Standard Functions in PI 7.0 - Process Integration - SCN Wiki

And SAP documentation here Standard Functions - Managing Services in the Enterprise Services Repository - SAP Library

Regards.

former_member182412
Active Contributor
0 Kudos

Hi Sendhil,

I dont see any multiple occurrences in your structure, if there is no multiple occurrences then you can achieve this with standard functions.

Regards,

Praveen.

giridhar_vegi
Participant
0 Kudos

Hi sendhil ,

               i think it is possible with standard functions.

Thanks

Giridhar