cancel
Showing results for 
Search instead for 
Did you mean: 

Assign a value from a previous record to a another record

Former Member
0 Kudos

Hi Experts

I have a type file CSV which has the following structure:

-


Date,Outlet,Car,Code,InOut,Time,N

20110515,9,E26,14,E,083150,1

20110515,9,E26,,S,083324,1

20110515,11,E26,15,E,103200,1

20110515,11,E26,,S,103420,1

20110515,15,E26,15,E,125247,1

20110515,15,E26,,S,130042,1

-


Can anyone tell me how to assign the value of the Code column of the previous line to the next line that has the "Code" empty (,,)?

Required to create a function? Or with a standard function and which is?

thanks

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Can anyone tell me how to assign the value of the Code column of the previous line to the next line that has the "Code" empty (,,)?

Required to create a function? Or with a standard function and which is?

Yes, this needs to be a user-defined function in message mapping.

In your message mapping, the logic is similar to this


Code -> mapWithDefault -> removeContext -> UDF -> splitByValue:eachValue -> Target

UDF is context type

argument is input


for(int a =0;a<input.length;a++){
	if(a==0){
		result.addValue(input[a]);
	}
	else{
		if(input[a].trim().equals("")){
			result.addValue(input[a-1]);
		}
		else{
			result.addValue(input[a]);
		}
  	}
}

There is an added logic, what if your first code is blank?

Hope this helps,

Mark

Former Member
0 Kudos

Hi Mark

your logic helped me

the problem is solved¡¡¡¡¡¡

thank you very much¡¡

Answers (1)

Answers (1)

Former Member
0 Kudos

I mean the following clarification

the input file has the following structure:

Date,Outlet,Car,Code,InOut,Time,N

whose values are as follows:

20110515,9,E26,14,E,083150,1

20110515,9,E26,,S,083324,1

20110515,11,E26,15,E,103200,1

20110515,11,E26,,S,103420,1

20110515,15,E26,15,E,125247,1

20110515,15,E26,,S,130042,1

I want the target structure of the output file will is as follows:

20110515,9,E26,14,E,083150,1

20110515,9,E26,14,S,083324,1

20110515,11,E26,15,E,103200,1

20110515,11,E26,15,S,103420,1

20110515,15,E26,15,E,125247,1

20110515,15,E26,15,S,130042,1

i.e. IF there is an record with the empty "Code" THEN put the "Code" of the previous record.

Thanks, I hope this clarification is sufficient to help me