cancel
Showing results for 
Search instead for 
Did you mean: 

Issue With Java code in UDF

Former Member
0 Kudos

Hi All,

i have a very weird behaviour in SAP PI 7.0 with java code in UDF

the Code has  which will put Max Day of the month of the respective year (following the actual calendar) for a given date & month

Input (mm/yyyy)

What we want (yyyymmdd)

02/2016

20160229 (February 29 2016)

02/2015

20160228 (February 28 2015)

06/2015

201506230 (June 30 2015)

Below is the Java code

Calendar c = Calendar.getInstance();

int mon = Integer.parseInt(month)-1; //Month Starts from 0-Jan till 11-Dec in Java

int yr = Integer.parseInt(year);

         c.set(Calendar.MONTH, mon);

          c.set(Calendar.YEAR, yr);

int days = c.getActualMaximum(Calendar.DAY_OF_MONTH);

String lastDay = Integer.toString(days);

return (year+month+lastDay);



For Certain dates, For Example 02/2018 it is sent as 31022018 which is incorrect


I dont see any issue in Java code


Also This issue is very Rare Occurrence, It occured 250+ times in 750000 times


Please let me know if any one know any pointers about this.




Accepted Solutions (0)

Answers (2)

Answers (2)

engswee
Active Contributor
0 Kudos

Hi Sree

I tested your UDF code on my PO 7.4 system and it works fine. But like you said, the issue occurrence is very rare. Additionally, PI 7.0 runs on Java 1.4 whilst PO 7.4 is on 1.6.

Anyway, I just wanted to share with you my own experience working with Date and Time in Java. Apparently in the Java community, the standard date and time classes prior to Java 8 are considered to be poor. I'm not sure if this might contribute to the inconsistent results you are getting, especially since Java 1.4 is really old.

The de facto standard for Java date and time libraries prior to Java 8 is Joda Time. Check it out at the following link.

Joda-Time - Home

You can try using their libraries in your UDF instead and see if it solves the inconsistent result issue.

Rgds

Eng Swee

Former Member
0 Kudos

Hi Goutham,

I was able to achieve your requirement with standard functions only. The Input I gave is in format mm/yyyy  and the output in yyyy/mm/dd(lastdate of the month).

mapping

and the fix values as below :

and the input and output are as below :