Lpad not declared

Hello -

I have the following transformation codes but getting an error saying " function ‘lpad’ is not declared’

// Transforms input record into output record.
function integer transform() {

	$out.0._23_ID = "SO-" + lpad($in.0.RptTo, 8, 0);
	$out.0._26_ID = "P-" + lpad($in.0.PosNbr,8,0) + "-" + $in.0.EmplID;

	
	return ALL;
}

Hi yichuansancun,

The third argument of lpad should be a string. If you want to use zero as the filler, use it this way: lpad($in.0.RptTo, 8, “0”).

Regards,

I changed the code to the following:

$out.0._23_ID = "SO-" + lpad($in.0.RptTo, 8, "0");
$out.0._26_ID = "P-" + lpad($in.0.PosNbr,8,"0") + "-" + $in.0.EmplID;

I still get the error “Function ‘lpad’ is not declared” :frowning:

What data type do you use in fields $in.0.RptTo, $in.0.PosNbr, $out.0._23_ID and $out.0._26_ID, please? For example “Nbr” in one of the names somehow suggests number while lpad function expects it to be a string. See the documentation page for lpad function.

If nothing else helps, send me your whole graph, please.

lpad function was introduced in CloverETL 4.0. Are you by any chance using version 3.5 or earlier?

yes, i am on 3.5.2 i believe

Hi,

Our online documentation always matches to the most recent version we have. If you want to use the documentation exactly for your version, you can see it when you press F1 button directly in Designer. As my colleague mentioned, lpad is not present in CloverETL 3.5. You can use workaround like this:

//#CTL2

// Transforms input record into output record.
function integer transform() {
	string input = $in.0.field1;
	
	while (length(input) < 8) {
		input = concat("0", input);
	}
	
	$out.0.field1 = input;

	return ALL;
}

I hope this helps.