cancel
Showing results for 
Search instead for 
Did you mean: 

PI help

Former Member
0 Kudos

Hello,

I am new to SAP PI.

I am creating  a scenario where - 

source message format is as below :

<Record>

<text>

emp id, joining_date [dd.mm.yy],name,address,reporting_date [dd.mm.yy]

</text>

</Record>

destination message format is as below :

<Record>

<emp id>

<joining_date [yyyymmdd]>

<name>

<address>

<reporting_date [yyyymmdd]   ---- if reporting date is less than 2 days from current date, 00000000 will get populated in this field.

</Record>


I am facing problem in UDF creation in java message mapping.

Can anyone please guide me regarding this ?


Regards,

Murari

Accepted Solutions (1)

Accepted Solutions (1)

umesh_badveli
Participant
0 Kudos

Hi Murari

Use the UDF given by Praveen and output of UDF for joining_date ,reporting_date use date transform function to get yyyymmdd.

and please elaborate the logic for reporting_date

Regards

Umesh

Former Member
0 Kudos

Hello Umesh,

the logic for reporting_date, if reporting date is less than two days than current date, 00000000 needs to be populated.

If greater than/equal to  two days, reporting date to be transformed as per yyyymmdd format.


regards,

Murari

former_member182412
Active Contributor
0 Kudos

Hi Murari,

I think 7.0 does not support multiple result list.

Use below mapping for emp_id(CopyValue with 0), joing_date(CopyValue with 1), name(CopyValue with 2), address(CopyValue with 3).

Use below UDF for splitString.

Use below mapping for reporting_date (CopyValue with 4)

reportingDate UDF:

You need to mention the below imports, PI 7.0 is different you need import these.

Regards,

Praveen.

Former Member
0 Kudos

Hello Praveen,


How to get CopyValue function ?

I am not getting it in the list of functions.

Plz revert.


Regards,

Murari

former_member182412
Active Contributor
0 Kudos

Hi Murari,

You can find it under Constants functions.

Regards,

Praveen.

Former Member
0 Kudos

Hello Praveen,


Also during UDF generation I am not getting any throws generated for exception handling.

Also not able to modify the same. Plz suggest.


Regards,

Murari

former_member182412
Active Contributor
0 Kudos

Hi Murari,

You can write the code no need to include the throws keyword because those are the differences in 7.0 and above versions.

Regards,

Praveen.

Former Member
0 Kudos

Hello Praveen,

I have created UDF and also done mapping.
But while Activating changes for mapping object MM_EmpData I am getting following error :

Activation of the change list canceled Check result for Message Mapping MM_EmpData | urn:wbsedcl.test.tcskolempreceiverlist:  Starting compilation  Source code has syntax error:  /usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapeb3f82c0c8d711e5a503001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:99: ';' expected for(String field : fields) ^ /usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapeb3f82c0c8d711e5a503001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:103: illegal start of expression } ^ 2 errors

Please suggest.

Regards,

Murari

former_member182412
Active Contributor
0 Kudos

Hi Murari,

Make sure the UDF code is like below.


public void splitString(String[] text, ResultList result, Container container){

String[] fields = text[0].split(",");

  for (String field : fields) {

  result.addValue(field);

  }

Regards,

Praveen.

Former Member
0 Kudos

Refer screen shot of UDF screen. It's same as you mentioned.

Pls suggest.

former_member182412
Active Contributor
0 Kudos

Hi Murari,

Ok enhanced for loop came from java 5, your PI version uses java 1.4 that is why enhanced for loop is not recognizing. Change the code like below.


public void splitString(String[] text, ResultList result, Container container) {

  String[] fields = text[0].split(",");

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

  result.addValue(fields[i]);

  }

  }

Regards,

Praveen.

Former Member
0 Kudos

Hi Praveen,

Thanks. Issue with java version only due to non recognition of enhanced for loop.

Code complied successfully.

Will be in touch for any further help.

Regards,

Murari

Former Member
0 Kudos

Hello Praveen,

For report date function I am facing error with import statement, please find below processing logs and advise:

        Activation of the change list canceled

Check result for Message Mapping MM_EmpData | urn:wbsedcl.test.tcskolempreceiverlist:

Starting compilation

Source code has syntax error:
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd2ac03f0c8e611e5964b001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:3: ';' expected
import com.sap.aii.mappingtool.tf3.*;import com.sap.aii.mappingtool.tf3.rt.*;import java.util.*;import java.io.*; import java.lang.reflect.*;import com.sap.aii.mappingtool.tf7.rt.*;import com.sap.aii.mapping.lookup.*;import java.text.ParseException;import java.util.*java.text.SimpleDateFormat;import com.sap.aii.mapping.api.*;import java.lang.reflect.*;import import;import java.io.*;
^
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd2ac03f0c8e611e5964b001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:3: <identifier> expected
import com.sap.aii.mappingtool.tf3.*;import com.sap.aii.mappingtool.tf3.rt.*;import java.util.*;import java.io.*; import java.lang.reflect.*;import com.sap.aii.mappingtool.tf7.rt.*;import com.sap.aii.mapping.lookup.*;import java.text.ParseException;import java.util.*java.text.SimpleDateFormat;import com.sap.aii.mapping.api.*;import java.lang.reflect.*;import import;import java.io.*;
^
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd2ac03f0c8e611e5964b001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:3: '.' expected
import com.sap.aii.mappingtool.tf3.*;import com.sap.aii.mappingtool.tf3.rt.*;import java.util.*;import java.io.*; import java.lang.reflect.*;import com.sap.aii.mappingtool.tf7.rt.*;import com.sap.aii.mapping.lookup.*;import java.text.ParseException;import java.util.*java.text.SimpleDateFormat;import com.sap.aii.mapping.api.*;import java.lang.reflect.*;import import;import java.io.*;
^
3 errors


Regards

Murari

former_member182412
Active Contributor
0 Kudos

Hi Murari,

Just enter these two packages only in imports section of the UDF.

java.text.*;java.util.*;

Regards,

Praveen.

former_member186851
Active Contributor
0 Kudos

was about to type the same Praveen..

Former Member
0 Kudos

Hello Praveen,

The import issue resolved after adding only two imports java.text.*;java.util.*;

But facing compilation issue due to return statement.

Below is my reportdate UDF :

public String reportingDate(String Reporting_Date,Container container){

SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");

try {

     Calendar c=Calendar.getInstance();

    c.setTime(sdf.parse(Reporting_Date));

   Calendar c1=Calendar.getInstance();

    c1.setTime(new Date());

    c1.add(Calendar.DATE,-2);

    if (c.before(c1))

       return  "00000000";

   else

     return Reporting_Date;

}

catch (ParseException pe)

{

  pe.getMessage();

}

}

Below is the compilation error got while activating message mapping :

Activation of the change list canceled

Check result for Message Mapping MM_EmpData | urn:wbsedcl.test.tcskolempreceiverlist:

Starting compilation

Source code has syntax error:
/usr/sap/WDX/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map88d5cf40c96d11e58fde001517f85c58/source/com/sap/xi/tf/_MM_EmpData_.java:134: missing return statement
}
^
1 error


Please advise.


Regards,

Murari

Former Member
0 Kudos

Hello Praveen,

Compilation error is resolved by placing the return statement in correct position. Also joining date and report date format is changing as expected. Thanks a lot.

Will be in touch for any further help.

Regards,

Murari

former_member186851
Active Contributor
0 Kudos

The below code should help

SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");

String out;

try {

     Calendar c=Calendar.getInstance();

    c.setTime(sdf.parse(Reporting_Date));

   Calendar c1=Calendar.getInstance();

    c1.setTime(new Date());

    c1.add(Calendar.DATE,-2);

    if (c.before(c1))

      out = "00000000";

   else

    out = Reporting_Date;

}

catch (ParseException pe)

{

  pe.getMessage();

}


return out;
}

former_member182412
Active Contributor
0 Kudos

Hi Murari,

Glad to hear that your problem was resolved, don't forget to close the thread as per below blog.

Regards,

Praveen.

Former Member
0 Kudos

Hello Praveen,

Can I create a document based on this discussion thread ?

If possible please advise me the steps.

Regards,

Murari

former_member186851
Active Contributor
0 Kudos

Murari,

Your discussion will be saved in your SCN account for future reference.

You can check it out anytime.:)

If your query is solved please close the thread.

Answers (2)

Answers (2)

former_member182412
Active Contributor
0 Kudos

Hi Murari,

You can create the UDF like below, use execution type Context in your case.

UDF Code:


public void splitString(String[] text, ResultList empId, ResultList joining_date, ResultList name, ResultList address,

  ResultList reporting_date, Container container) throws StreamTransformationException {

  String[] fields = text[0].split(",");

  empId.addValue(fields[0]);

  joining_date.addValue(fields[1]);

  name.addValue(fields[2]);

  address.addValue(fields[3]);

  reporting_date.addValue(fields[4]);

  }

You can do the mapping like below.

Mapping result:

Regards,

Praveen.

Former Member
0 Kudos

Hello Praveen/Raghuraman,

Thanks for reply. I am facing one problem while creating UDF.

I have selected Context as cache and I have got one Argument field and one Result field.

When I click on Add, only Arguments are adding, Results are not adding. Refer Screen shot above.

As I require one argument type and multiple result type.

Please revert.

Regards,

Murari

former_member186851
Active Contributor
0 Kudos

Hello Murari,

One output ,that is ResultList will hold all the values. So its not required to add multiple outputs.

Former Member
0 Kudos

Hello Raghuraman,

But as per UDF generation given by Praveen, Multiple values needs to be defined.

How to define multiple values under one result. Please revert.

Regards,

murari

former_member186851
Active Contributor
0 Kudos

Hello Murari,

Try the below UDF

    public static String compareDates(String JoiningDate,String CurrentDate) 
    { 
          String difference=""; 
     try 
     { 
           String pattern = "dd.mm.yy"; 
           long  diff; 
           final long  MilliSecondsInADay=1000 * 60 * 60 * 24 ; 
           java.text.SimpleDateFormat Dateformat = new java.text.SimpleDateFormat(pattern); 
           java.util.Date JoiningDate= Dateformat.parse(EndDate); 
           java.util.Date CurrentDate= Dateformat.parse(startDate); 
           diff=(JoiningDate.getTime()-StartDate.getTime())/MilliSecondsInADay; 
           if(diff==-2) 
           { 
                 difference = "00000000"
           } 
           else
           {
     } 
     catch(java.text.ParseException e) 
     { 
           e.printStackTrace(); 
     } 
     return difference; 
    }

In case if the difference is not equal to 2 what you want to return?.

Former Member
0 Kudos

Hello Raghuraman,

Thanks for reply.

But I require creating UDF for splitting a string into parts present in source message <text> tag and how to map splitted parts into destination message format. Please guide.

Also regarding that date difference, if the difference is not equal to 2  I want to return the date as yyyymmdd format.

Regards,

Murari

former_member186851
Active Contributor
0 Kudos

Hello Murari,

You can refer the below link

Former Member
0 Kudos

Hello Raghuraman,

Basically that logic part related to split of a string by a delimiter (,) and store it into a String Array and adding the string array indexes into result (ResultList object) I have written in java code.

But I have stuck below :

1. I have created a source data type DT_Employee with record as a subelement and text as a subelement of it with type string.

2. I have created a destination data type DT_Employee_Receiver with Record as subelement and following as a attributes :   Emp_No (integer), Joining_date(date), name(String),address (string),reporting_date(date).

3.Now I have tried to do message mapping with Source and  Destination with  a UDF creation. I know about the java logic of splitting of string and store into some array and result list.

But I am stuck in doing the actual mapping between source and destination. Please guide.

  Also while creating UDF the return type of the method is coming as default void and I am not able to change it. below is the method :

    public void empname(String[] Text,ResultList result,Container container){

        String[] arg = Text[0].split(",");

        for(int j=0; j<arg.length; j++)

          {

             result.addValue(arg[j]);

             }

         }

How I will return the result list and map with destination.

Please help.

Regards

Murari

former_member186851
Active Contributor
0 Kudos

Hello Murari,

Did you select the udf Type as for all values of queues?

Former Member
0 Kudos

Hello Raghuraman,

I have not got any option of selecting udf type while creating function.

Using SAP PI 7.0.

Please revert.

Regards,

Murari

former_member186851
Active Contributor
0 Kudos

Hello Murai,

You will see just above the code area,

three options will be available.

1.Single values

2.All values of queues

3.All Values of contexts

Former Member
0 Kudos

Hello Raghuraman,

While Creating the function I have three options as cache :

1. Value 2. Context 3. Queue

I have selected Context.

Please revert.

Regards,

Murari

former_member186851
Active Contributor
0 Kudos

Yes Murari,correct.

You can use queue or context.

Queue-All the values in the queue

Context-All the values in every context of the queue.

select accordingly and use the UDF.