Advanced Training For WLOADCTL: Understanding Functions and Logical Expressions

Overview
The introduction of functions and logical expressions makes the design of workflows and schedulers more flexible.
This article covers the following topics:
Introduction to functions and logical expressions
Logical operators
Scope of application for functions and logical expressions
The difference between function calls and variable references
Function reference list
1. Introduction to Functions and Logical Expressions
Let's start with a simple example from a workflow definition:
<serial>
<name>MainModul_rootnode</name>
<begin>
<nulljob>
<name>startctljob</name>
<jobdesc>Start trigger control node</jobdesc>
<!--Point 1-->
<condition>if($(startdatetime)<=systime('yyyymmddhhmiss')) CTL_DOIT else CTL_WAIT</condition>
</nulljob>
<sh>
<name>job12</name>
<progname>$HOME/shellpath/job12.sh</progname>
<!--Point 2-->
<para>$(substr('$(startdatetime)',0,8))</para>
<maxnum>3</maxnum>
<!--Point 3-->
<ignoreerr>dayofweek() in (1,3,5)</ignoreerr>
</exe>
<flow>
<modivarv>
<name>passflow</name>
<!--Point 4-->
<para>varname=startdatetime,varvalue=$(addday('$(startdatetime)','yyyymmddhhmiss',1))</para>
<jobdesc>Flip: modify variable</jobdesc>
</modivarv>
<end>
</serial>
Code Walkthrough
Point 1 : The job executes only when the value of the
startdatetimevariable is<=to the corresponding system time.Point 2 : The
substrfunction extracts the first 8 characters from the value of thestartdatetimevariable.Point 3 : The
ignoreerrattribute specifies that if the current day is Monday, Wednesday, or Friday, the job will be allowed to pass after 3 consecutive failures. Otherwise, the job fails and the downstream workflow does not continue.Point 4 : The
adddayfunction adds one day to the existing value ofstartdatetime.
2. Logical Operators
Logical expressions are mainly used within the condition and ignoreerr attributes. The table below lists the logical operators supported by WLOADCTL and their meanings.
| No. | Operator | Meaning |
|---|---|---|
| 1 | > |
Greater than |
| 2 | < |
Less than |
| 3 | >= |
Greater than or equal to |
| 4 | <= |
Less than or equal to |
| 5 | == |
Equal to |
| 6 | and |
Logical AND |
| 7 | or |
Logical OR |
| 8 | in |
Within (a set) |
| 9 | nin |
Not within (a set) |
3. Scope of Application for Functions and Logical Expressions
progname — Program Name
For custom jobs, the program name refers to the executable entity associated with the job, for example, the Job name in a DataStage job, the corresponding program name in Informatica, a shell script name, or a stored procedure name. There are some special job nodes such as begin, end, nulljob, and include do not require this attribute.
para — Runtime Parameters
The para attribute defines the entry parameters that a job program needs at runtime, for instance, command-line arguments for a shell script, or entry parameters for a DataStage job at execution time.
Across different job types, WLOADCTL represents these parameters uniformly as strings within its module code. This format is intuitive for command-line-style programs (shell scripts, executables, Java programs, etc.). For example, a shell program might actually run as:
sh /home/myshellpath/test.sh -user abc -password cba;
Here, -user abc -password cba are parameters.
However, for jobs that require a specialized runtime platform, such as DataStage, the parameter format expected by the underlying program isn't directly visible to us. For these job types, parameters are converted into the required format via a dedicated plugin, following a specific convention.
Below is an example showing how parameters are applied to jobs:
<dsjob>
<name>SubModul0_JobNode2</name>
<progname>DSJob1</progname>
<para>user = $user:password = $password</para> <!-- DataStage job parameters -->
</dsjob>
<proc>
<name>SubModul0_JobNode2</name>
<progname>DSJob1</progname>
<para>workdate=$workdate</para> <!-- Stored procedure task parameters -->
</proc>
exppara — Environment Parameters
There are some differences between environment parameters and runtime parameters.
Environment parameters refer to information that must be available at runtime, regardless of the job's own parameters. For example, when a DataStage job runs, it needs to know which project it belongs to. Similarly, when a stored procedure runs, it needs database name, username, and password information. These are treated as environment parameters as well. Some job types (such as shell scripts) don't require any environment parameters at all, since they can simply be executed directly.
The key distinction between environment parameters and runtime parameters is: environment parameters are what the runtime platform itself needs in order to execute the program correctly, while runtime parameters are what the program's internal logic needs. Below is an example of environment parameters applied to a stored procedure job and a DataStage job:
<proc>
<name>shelljob</name>
<progname>proc_job1</progname>
<para>workdate=$workdate</para>
<!-- Stored procedure environment parameters -->
<exppara>user=$(user),password=$(password)</exppara>
</proc>
<dsjob>
<name>dsjob1</name>
<progname>ds_job1</progname>
<para>user=$(user),password=$(password),workdate=$(workdate)</para>
<!-- DataStage job environment parameters -->
<exppara>projectname=ocrm</exppara>
</dsjob>
Beyond the three attributes discussed above (progname, para, exppara), attributes that support function usage include:
| No. | Attribute Name | Description |
|---|---|---|
| 1 | progname |
Program name |
| 2 | para |
Program entry parameters |
| 3 | exppara |
Program environment parameters |
| 4 | agentid |
Agent name |
| 5 | hostuser |
Remote host user credentials (used for agentless remote scheduling) |
| 6 | condition |
Custom conditional strategy |
| 7 | ignoreerr |
Error-ignoring strategy |
| 8 | jobdesc |
Job description |
4. Function Calls vs. Variable References
Within a workflow, you can reference either a function's return value or a private/public variable's value. While the two share similarities, there are also important differences:
Referring a function's return value works the same way as referring a variable, both are simply "value references."
A variable reference must always be wrapped in
$(), regardless of context.Usually, A function's return value doesn't have to be wrapped in
$()unless they are used inside anifcondition or nested within another function call.
5. Function Reference List
5.1 String Functions
| Function | Description | Parameters | Return Value |
|---|---|---|---|
substr |
Extracts a substring | Param 1: source string | |
| Param 2: start position (0-indexed) | |||
| Param 3: end position | The extracted substring | ||
addstr |
Concatenates strings | Param 1: source string 1 | |
| Param 2: source string 2 | The concatenated string | ||
strlen |
Returns string length | Param 1: source string | The length of the string |
strcmp |
Compares two strings | Param 1: source string 1 | |
| Param 2: source string 2 | Non-zero: false | ||
| Zero: true | |||
upper |
Converts to uppercase | Param 1: source string | The uppercase string |
lower |
Converts to lowercase | Param 1: source string | The lowercase string |
5.2 Date/Time Functions
| Function | Description | Parameters | Return Value |
|---|---|---|---|
systime |
Gets the current system date/time in the specified format | Format notation: yyyy = year, mm = month, dd = day, hh = hour, mi = minute, ss = second |
The formatted date/time |
addyear |
Adds/subtracts years | Param 1: base date/time | |
| Param 2: format of the base date/time | |||
Param 3: increment (use single quotes for negative values, e.g. '-1') |
The modified date/time | ||
addmonth |
Adds/subtracts months | (same parameter pattern as above) | (same return as above) |
addday |
Adds/subtracts days | (same parameter pattern as above) | (same return as above) |
addhour |
Adds/subtracts hours | (same parameter pattern as above) | (same return as above) |
addminute |
Adds/subtracts minutes | (same parameter pattern as above) | (same return as above) |
addsecond |
Adds/subtracts seconds | (same parameter pattern as above) | (same return as above) |
formattime |
Converts between date/time formats | Param 1: date/time to convert | |
| Param 2: source format | |||
| Param 3: target format | The reformatted date/time | ||
dayofweek |
Determines the day of the week for a given date | Can be omitted (defaults to system time) | |
| Param 1: specified date | |||
| Param 2: date format | Day-of-week value: 0 = Sunday, 1 = Monday, ... 6 = Saturday | ||
isendofmonth |
Checks whether a date is the last day of the month | Can be omitted (defaults to system time) | |
| Param 1: specified date | |||
| Param 2: date format | 0: false | ||
| 1: true |
5.3 Other Functions
| Function | Description | Parameters | Return Value |
|---|---|---|---|
getjresult |
Gets a job's execution result | Param 1: job name | |
| Param 2: workflow name (omit for the current workflow) | The specified job's execution result | ||
getjstate |
Gets a job's current status | Param 1: job name | |
| Param 2: workflow name (omit for the current workflow) | The job's status code (see the job status table below) | ||
getjretmsg |
Gets a job's return message | Param 1: job name | |
| Param 2: workflow name (omit for the current workflow) | The job's returned message | ||
getvarv |
Gets a variable's value | — | — |
execcmd |
Executes a shell command and returns its exit code | The system command | The command's exit code |
getstdout |
Executes a shell command and captures standard output | The system command | The command's standard output |
exp |
Evaluates an arithmetic (+ - * /) expression |
The expression | The computed result |
if |
Evaluates a true/false condition | Logical comparison expressions: >, <, ==, <=, >=, plus logical AND/OR |
1: true |
| 0: false |
5.4 getjstate — Job Status Reference Table
The table below lists all possible status values returned by getjstate for a job within the current workflow:
| Status Code | Status Name | Description |
|---|---|---|
| -1 | NetErr | Network error |
| -2 | NOCOMMFILE | Communication file does not exist |
| -3 | NOPLUGIN | No execution plugin available |
| -4 | CTLNODEERR | Control node error |
| -5 | MSGERR | Message queue error |
| -7 | SYSOERR | Other system error |
| -8 | NOISSUE | Program not yet published |
| -9 | ROUTEERR | Routing error |
| -10 | NONETINFO | No network configuration info |
| -90 | REDO | System busy |
| -100 | OTHER | Not yet executed |
| 1 | INIT | Currently executing |
| 2 | WAITMANRUN | Currently in a wait/loop state |
| 5 | SYSBUSS | Error — requires re-execution |
| 10 | RUNNING | Error — will not re-execute |
| 11 | CYCLE | Successfully executed |
| 20 | ERR | Skipped for this cycle (period-based) |
| 25 | BRKERR | Passed via ignored error |
| 29 | FAILED | Passed as invalid/void |
| 40 | SUCCESS | Successfully executed |
| 41 | OKPERIOD | Skipped for this cycle per schedule |
| 42 | IGNOREERR | Passed with an ignored error (warning) |
| 43 | DISABLE | Passed as disabled |
| 44 | FORCEOK | Force-passed |
| 45 | BRKCYCLE | Passed via loop interruption |
Functions and logical expressions help workflows and schedulers in WLOADCTL gain a significant amount of expressive power, if you are interested in those expressions, feel free to try a demo in our Official Website.
← Prev | Job Control By Condition





