Hello,
I’d like to be able to perform the following action in CTL2, but I can’t seem to figure out how… I’m afraid it isn’t possible.
for (each assignment in $0.*){
newValue = trim value
if newValue == “”
$0.current_key = null
}
Basically, I want to set to null any empty values for all incoming assignments and don’t want to have to explicitly name each member.
Any help would be much appreciated.
Hello,
unfortunately it is not possible in CTL, because the language doesn’t support iteration over record’s fields. But it can be written really easy in java:
import org.jetel.component.DataRecordTransform;
import org.jetel.data.DataField;
import org.jetel.data.DataRecord;
import org.jetel.exception.TransformException;
import org.jetel.metadata.DataFieldMetadata;
import org.jetel.util.string.StringUtils;
public class NullBlankValues extends DataRecordTransform {
@Override
public int transform(DataRecord[] arg0, DataRecord[] arg1)
throws TransformException {
arg1[0].copyFieldsByName(arg0[0]);
DataField currentField;
for (int i = 0; i < arg1[0].getNumFields(); i++) {
currentField = arg1[0].getField(i);
if (currentField.getType() == DataFieldMetadata.STRING_FIELD && StringUtils.isEmpty((CharSequence) currentField.getValue())) {
currentField.setNull(true);
}
}
return 0;
}
}
By the way: how do you get these blank values? If you read them from the file it’s just enough to set trim attribute on DataReader to true.