cancel
Showing results for 
Search instead for 
Did you mean: 

UDF Creation

Former Member
0 Kudos

Dear Experts,

  I am new to PI and want to build one logic using UDF in sap PI 7.1.

  I have attached the payload, where input data is coming in multiple segments, so I need to capture the data For SUMME based condition on SUMID

  If SUMID == "011'

    then

     SUMME == " " (In the given payload valuse is "2612.00").

Please provide the UDF code for this requirement..

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Why u want a UDF for this? It can be easily handle using graphical mapping?

Just for your reference, i have attached the UDF code, but don't use this as stated above use graphical mapping.

int count = 0;

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

{

if(var1[i].equals("011"))

{

result.addValue(var2[i]);

count =  count+1;

break;

}

}

if(count==0)

result.addSuppress();

Thanks

Amit Srivastava

anupam_ghosh2
Active Contributor
0 Kudos

Hi Amit,

                 If I have captured the requirement correctly then
SUMME to be propagated to the target if the value of the field SUMID in the same segment is not equal to "011". In your code you are propagating the value of SUMME to target if SUMID=011.

if(var1[i].equals("011")) 

     result.addValue(var2[i]); 

     count =  count+1; 

     break; 

So this made me little confused here.

If I have understood the requirement properly then in target the SUMME node value becomes "" but it exists if SUMID="011". Then following mapping should suffice  

after test

If no SUMME node is to be generated in target at all if value of SUMID="011" then mapping will change slightly as follows

The test results will be as shown below

Please correct me in case I am wrong, but if I go by what

Former Member
0 Kudos

Thanks Amit,

as you suggeted i used graphical mapping instead of udf, but still ur udf is helping me to und the udf creation... thanks

Former Member
0 Kudos

Hi Anupam,

Thanks for the reply,, As u said i treid the mapping and its working fine but if u see in test result, I am getting 5 line items in that one line item has the actual values(please refer screen shot) and i have a soap at receiver side and i want to avoid the multiple line items which has no values.

basically from source if it is coming n line itmes and in target also it is getting created with n line items please refer my mapping scren shot. I have just mapped source node to target node, hence it is creating same line items in the target. but i want only field in target which the value is picking( in ex : 999)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Sumit,

                 Try this mapping

Finally

Test results

Regards

Anupam

anupam_ghosh2
Active Contributor
0 Kudos

Hi Amit,

               I guess your presumption was correct. Sumit wanted to forward SUMMIE values where SUMID=011 in the same context to the target. I was unable to understand this from his initial post.

Hope you do not misunderstand me.

Regards

Anupam

Former Member
0 Kudos

Thanks anup this mapping working exactly..!!!

Thanks for you time....

Former Member
0 Kudos

Hello Anupam,

>>Hope you do not misunderstand me.

Certainly not, we are here to help and correct each other.

Thanks

Amit Srivastava

Answers (2)

Answers (2)

ambrish_mishra
Active Contributor
0 Kudos

Hi Sumit,

I assume you don't need the source value for SUMME in case if SUMID 011.

Normally in case of FIDC02 IDocs, the values are calculated in ECC based on tax codes/country codes  and not from source and this is the reason you are doing this.

So just right click on the target segment E1EDS01. Do duplicate subtree. map the additional segment E1EDS01 created to a constant null. Map SUMID to constant 011 and SUMME to constant null.

Isn't it what you need ?

Ambrish

Former Member
0 Kudos

HI Ambarish,

Thanks for your resopnse..

Actually m suing soap at recv side its a Idoc to saop and I am picking the only value from the payload wher SUMID is "011". As of i m dng with graphical mapping. thanks

former_member189420
Active Participant
0 Kudos

Hi Sumit,

I have faced this issue of suppressing the values in the target structure based on conditions.

I use the below java code to suppress the empty values. These empty values are produced upon using "if" standard function.

  public void removeEmptyValues(String[] inputQ, ResultList result, Container container) throws StreamTransformationException{

  // beginning of removeEmptyValues

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

{

          if( inputQ[i].equals("") )

          {

          }else{

          result.addValue(inputQ[i]);

          }

}

  // end of removeEmptyValues

  }

Hope it helps!

Best Regards,

Anand Patil

iaki_vila
Active Contributor
0 Kudos

Hi Sumit,

As Amit said is better to use a standard function, it's easier to maintain and you avoid further problems in a PI  upgrade.

You can use the standard booelan functions IF or IFwithoutElse depending if you need to map SUMME tag in the case that SUMID != "011':

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/frameset.htm

http://help.sap.com/saphelp_nw04/helpdata/en/5d/db0e83e8e74202a5bff527055ab7e5/content.htm

Regards.