Passing User variable to Exception Handler

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
eli.nawas_AUS
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 15, 2014 9:14 am

Passing User variable to Exception Handler

Post by eli.nawas_AUS »

Hi

We have this standard Exception Handler process like this:

ExceptionHandler_Stage --> Email_Stage --> Terminator_Stage


In the Email_Stage we can references parameters in the subject field, like this:

"MyJob Contained the following exception on #$DS_ENV#: #Exception_Handler.$ErrMessage#"

where:
1) #$DS_ENV# is our parameter to the job
2) #Exception_Handler.$ErrMessage# is some system varaible from DS?


How do I pass in some user variable, like system.dateTime?


For Example I have this picture (similar to another post):

........................................ --> ExeCmd1 --+
................................................................|
uservariable -> sequencer1 --> ExeCmd2 --+--> sequencer2(all)
................................................................|
......................................... --> ExeCmd3 --+


where uservariable is: CurrDate with Expression like: Field(DSJobStartDate,"-", 1) + .... + Field(DSJobStartTime,":", 1)


How do I pass this CurrDate to the Exception Handler?

(I don't want to invoke DSJobStartDate functions inside the Exception handler (don't even know if that's possible). I want to use the value from variable CurrDate because it contains a global value that must be referenced.)

I tried various combinations for # and $ (similar to: #Exception_Handler.$ErrMessage# ) but no success at all.

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If something supports parameters, like an email subject line, it also has an instance of the External Parameter Helper associated with it. Rather than typing in things by hand, use it to 'pick' the appropriate downstream parameter value from the list it shows you. Added bonus: it knows whether it needs hashes around it or not.

Access it via the ellipsis that should be there.
-craig

"You can never have too many knives" -- Logan Nine Fingers
eli.nawas_AUS
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 15, 2014 9:14 am

Post by eli.nawas_AUS »

Hi Chulett

It's not parameters that I want to select. It's the user-variables, and it seems they not in the External Parameter Helper list.

This is what I want to do:

I created a User-Variable, say CURRTIME, and popuplated it with the current date/time. It is then passed onto other jobs/scripts to be used. They must reference this single value. Later on, I want to obtain this user-variable within the my script within ExeCmd within the Exception Handler, like this:

ExceptionHandler_Stage --> ExeCmd --> Email_Stage --> Terminator_Stage


But I can't figure out how to pass a user-variable to some script within the Exception Handler stage. It seems that it can only references parameters, not user variables.

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Everything you are passing around is considered a 'parameter' in this context. However, clarify for us what you mean by 'User Variables', are you referring to something you've actually done in a User Variables Activity stage? Note that you don't need to pass anything to the Exception Handler (nor can you) but rather leverage something inside the exception branch.

I have no way to test this for myself, are you saying that once you are in the Exception Handler's pipeline in the Sequence job, you no longer have access to anything other than job parameters? None of the other variables from the body of the job show up in the Helper's list there? If that's the case, then perhaps your CURRTIME should be setup / passed in as a job parameter rather than derived inside the sequence?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

User variables are only available if they are in the same "timeline" - that is, if there is a direct path in the sequence between the User Variables activity and the activity in which you want to use them. To use a user variable downstream of the Exception Handler you will need a User Variables activity downstream of the Exception Handler.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That's what I suspected but had no way to verify except through others - the hard break between the exception handling and the body of the sequence is what leaves any variables not in the exception "timeline" out of reach.

The 'problem' with adding another there just for the CURRTIME is it will be different from the CURRTIME of the main body if it is defined there as well. Perhaps not different enough to be an issue? If they need to be exactly the same then it still seems to me it would need to be a job parameter.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Agreed. However the system variables @DATE and @TIME are set when the job starts, so they could be used to assign values to user variables, as could the DataStage macros such as DSJobStartDate, DSJobStartTime and DSJobStartTimestamp. All of the SDK functions are also available too, via DSRoutines.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
eli.nawas_AUS
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 15, 2014 9:14 am

Post by eli.nawas_AUS »

Hi
Yes, that was what I meant: I had a UserVariablersActivity where i have a variable containing the current timestamp. This timestamp kind of acts as the PrimaryKey. Has to be exact.

I am able to pass this timestamp as parameter to any ExeCmds scripts, but DS will not accept this parameter inside the ExeCmd inside the Exception Handler.

I think your guys hit it on the head: the problem is that "TimeLine" thing.


The solution seems to be:
1) Create a new sequence job (acting as the "main" program);
2) Create UserVariable (timestamp) in this main program;
3) Add a new parameter to ALL existing sequence jobs;
4) Call those other sequence jobs, pass in this timestamp

Now it will be available in any ExcCmd, even inside Exception Handler.


This is exactly what I wanted to confirm: Exception Handler cannot access UserVariables directly. Must go thru Parameters.


Thanks for your help.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

To clarify, an Exception Handler itself cannot access user variables, since it has no use for them. It can only have an Unconditional trigger.

Activities downstream of the Exception Handler cannot access user variables defined outside that stream, since there is no direct connection.

If there is a User Variables activity downstream of the Exception Handler, activities downstream of that can access its user variables. These can be assigned from job parameters.

But that's probably a waste of effort, since the downstream activities themselves can access the job parameter values directly.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

As noted by Ray, rather than using a "current timestamp" that you either pass in or generate, why not use the system variables or macros that hold the Job Start Timestamp which would be available anywhere in the job and are a constant since they are set in stone when the job actually starts? Not sure why I didn't think of that, put it on the table earlier.

We leveraged that particular timestamp rather heavily back in the day and continue to do so in that other tool I'm using now. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
eli.nawas_AUS
Premium Member
Premium Member
Posts: 39
Joined: Tue Apr 15, 2014 9:14 am

Post by eli.nawas_AUS »

Hi

That's what I want to do, but the existing jobs that I inherited use UserVariablesActivity to hold that time constant. I want to reference this
variable in the ExeCmd script inside Exception Handler (or even in SendMail's subject line.)

If system variables/macros is a better solution, I can propose that change. But I don't know how to do that. (I only have basic training a couple of years back ;) )

I pass @DATE @TIME to the shell script in ExeCmd. Inside the script I print out all args. But @DATE @TIME does not contain the actual date. It just has the literal string @DATE @TIME instead

What is the proper syntax to get the @DATE @TIME?

Thanks
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

@DATE and @TIME are in a DataStage internal format. In the user variable expressions use Oconv() function to convert them to whatever format you require.
For example:

Code: Select all

Oconv(@DATE, "D-YMD[4,2,2]")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply