cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping logic to increment value with every segment

Former Member
0 Kudos

Hi,

I have a incoming date 2011/12/21/10:00:00 this comes in a segment with 1:1 occurance. I need to use this field and increment date by one day in a target field with unbound occurance.

Say if the target node occurs three times. I should populate 2011/12/22/10:00:00     2011/12/23/10:00:00    2011/12/24/10:00:00 respectively.

How do we store a initial segment value and increment it?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello,

is it a graphical mapping? if yes you could simply build a function on your own!

Regards,

Thomas

Former Member
0 Kudos

Yaa. It's graphical mapping

Former Member
0 Kudos

then go to the ESR and select your software-componenten, then go to the mapping and to tab functions. There you can add a function an fill in the source code on the right side. Just add a variable:

Type: Argument

Name: Input

Java-Type: String

Now u can fill in the source code.

At the end you go to the mapping itself and choose at the very bottom "Functions: User-Defined" and you should find your function.

Regards

Former Member
0 Kudos

yup i want that UDF please. I am not good at java

Former Member
0 Kudos

Hi prabhas,

In function, make argument as string .Use the code below to increment the date value by one and return the value . Make sure you import the java.text.* .

DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

Date date = new Date  () ;

try

{

date = ( Date )formatter.parse(var1);

}

catch ( ParseException  e){}

Calendar clndr = Calendar.getInstance();

clndr.setTime(date);

clndr.add(clndr.DATE, 1);

date = clndr.getTime();

String strDate = formatter.format(date);

return strDate;

Use this code . to increment date .

thanks and regards,

Anup Banerjee

Former Member
0 Kudos

hi Anup,

Thanks it is working but is incrementing the date for first time and assigning the same value for other segments too.

My input structure is

<date> 1:1

   <Records>1:unbound

How many times the records segment occur those many times we need to increase the date. the current code you gave is applying the same start date to all occurences of record.

Date value is  2001/11/11-12:00:00 If i got 3 occurance of Records segment then the code should populate.  2001/11/12-12:00:00

               2001/11/13-12:00:00

               2001/11/14-12:00:00

Currently i am getting 2001/11/12-12:00:00

                                2001/11/12-12:00:00

                                2001/11/12-12:00:00

Former Member
0 Kudos

You can combine your source field with a UseOneAsMany to get the the number of records you need. Use the Records node in the context of the root node. Then change your UDF to take all values of the queue. Then adapt your UDF, to something like this::

DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

Date date = new Date  () ;

//get the date

try

{

date = ( Date )formatter.parse(var1[0]);

}

catch ( ParseException  e){}

//for every record, add 1...n to the first date and add it to the result queue

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

{

Calendar clndr = Calendar.getInstance();

clndr.setTime(date);

clndr.add(clndr.DATE, i);

date = clndr.getTime();

String strDate = formatter.format(date);

result.addValue(strDate);

}

Former Member
0 Kudos

Hi,

Wer does i include my second Var here. Didn't get it?