In the reformat I want to do a replace on all the fields in one go:
Say for example,
function integer transform() {
$out.0.* = replace($in.0.*,"abcdefg","abc");
return ALL;
}
But when I use the above code it throws error as “Function replace(string,string,string) is not applicable for the arguments (record(TRN_045_ROL_TYPE),string,string)”.
Can you pls help me on this?
Hi,
You can try the following code example, it will let you replace all fields in go:
// Transforms input record into output record.
function integer transform() {
integer count = 0;
while(count < length($in.0))
{
setStringValue($out.0.*,count,replace(getStringValue($in.0,count),"abcdefg","abc"));
count++;
}
return ALL;
}
Cheers,
As you see from the error message:
Function replace(string,string,string) is not applicable for the arguments (record(TRN_045_ROL_TYPE),string,string)".
You cannot change all of the fields in one single operation. You will have to step through the fields one by one.
Try:
//#CTL2
// Transforms input record into output record.
integer columncounter;
function integer transform() {
/* first copy all fields */
copyByPosition($out.0,$in.0);
/* Then step through the fields */
for(columncounter = 0; columncounter < length($in.0); columncounter++)
{
if (getFieldType($in.0, columncounter) == "string")
{
setStringValue($out.0,columncounter, replace(getStringValue($in.0, columncounter),"abcdef","abc"));
}
} // end for next
return ALL;
}