CTL1 to CTL2 Conversion: Function 'Today' is not declared

Hello. I’m using the Tranform Editor of IBM Initiate Workbench 9.7.0 to convert the CTL in a Reformat transformer from CTL1 to CTL2. The transformer is reading in a .txt file made by a Reformat in Phase 0 of the graph and applying a random birthdate to each record. Works fine in CTL1. The Editor is giving me an error when I convert to the randomDate code: Function ‘Today’ is not declared

I’m using the today() function. So, somewhere I don’t have my transform pointed to some global cache of functions. Any help would be appreciated.

Code that works as is:

//#TL

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

$0.* := $0.*; // stage all fields ‘as is’ to output port 0
$0.BirthDate := random_date($0.BirthDate,today(),“yyyyMMdd”,0); // convert birthdate to a random date

}

New Code with ‘is not declared’ error:

//CTL2

// Transforms input record into output record.
function int transform() {
$0.BirthDate = $0.BirthDate;
$0.Name = $0.Name;

$0.BirthDate = randomDate($0.BirthDate,today(),“yyyyMMdd”,0); // convert birthdate to a random date

return 0;
}

The Properties for this transformer is generic (perhaps my problem)
Basic
Transform: //CTL2//Transforms input…
Transform URL:
Transform class:
Transform source charset: ISO-8859-2 (from Dataparser DEFAULT_CHARSET_DECODER in default Properties)

Advanced
Error actions:
Error log

Visual
Component name: MASK PII
Description: Mask PII - Birthdate is randomized
Location: Point(294,188)
Size: (Dimension(0,0)

Common
ID: REFORMAT2
Component type: REFORMAT
Specification: Recevies data thrugh input port, transforms them in a user specific way,…
Phase: 1
Enabled: enabled
Pass through Input port:
Pass through Output port:

Again, I need a hint where to find today() function. Thanks.

Hello, wavodavo,

firstly, I would like to recommend you using CTL2 syntax for variables in CTL2 code ($0.BirthDate vs. $out.0.BirthDate) to prevent any potential name collisions. But regarding your question, I can see possible issue in randomDate argument types. random_date in CTL1 uses dates while randomDate in CTL2 uses strings. You can find more information here:

http://doc.cloveretl.com/documentation/UserGuide/topic/com.cloveretl.gui.docs/docs/date-functions-ctl1.html
http://doc.cloveretl.com/documentation/UserGuide/index.jsp?topic=/com.cloveretl.gui.docs/docs/date-functions-ctl2.html

Function today() is unchanged and returns date type value so to be able to use it in CTL2, you should wrap it in date2str function. By the way, randomSeed as the fourth argument exists no more in CTL2, see the second link.

Best regards,

Thank you for your speedy reply. I’ll check the links. Consider my problem solved. If not, I’ll be ba-a-a-ack. 8)

I’m ba-a-a-ack.

In spite of yur expert advice, I still can’t complete my conversion from CTL1 to CTL2 because I’m still getting the error: Function ‘today’ is not declared

I have now made my transform function as simple as possible (see below). I declare a date variable and try to assign today’s date to it.

Am I missing an import statement to point me to global date variables?

Here is the code:

//CTL2

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

date Tday = today();

return 0;
}

// Called to return a user-defined error message when an error occurs.
// function getMessage() {}

// Called during component initialization.
// function init() {}
// Called after the component finishes.
// function finished() {}

I’m using the Transform Editor of IBM Initiate Workbench 9.7.0.

The Properties for this transformer is generic (perhaps my problem)
Basic
Transform: //CTL2//Transforms input…
Transform URL:
Transform class:
Transform source charset: ISO-8859-2 (from Dataparser DEFAULT_CHARSET_DECODER in default Properties)

Advanced
Error actions:
Error log

Visual
Component name: MASK PII
Description: Mask PII - Birthdate is randomized
Location: Point(294,188)
Size: (Dimension(0,0)

Common
ID: REFORMAT2
Component type: REFORMAT
Specification: Recevies data through input port, transforms them in a user specific way,…
Phase: 1
Enabled: enabled
Pass through Input port:
Pass through Output port:

I appreciate your help. Thanks

Hello again,

content of your transform() function seems OK, you do not miss anything here. But try to use integer instead of int in function signature:


function integer transform() {
	date Tday = today();
	return 0;
}

If this does not help you, please, try to create some new test project (already in CTL2) and to type exactly the same code as above. It may be possible that some strange relicts persisted from the previous modifications of your CTL code.

Best regards,