Passing Runtime parameter using $UserStatus

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

Passing Runtime parameter using $UserStatus

Post by sohasaid »

Dears,

I'm trying to pass a runtime parameter to a job which holds a value from a previous one. i.e. selecting max(date) from job1 then passing the result in where clause of job2.
After searching, I've followed the following scenario:
viewtopic.php?t=132137&highlight=overwr ... eter+value
chulett wrote:Not directlyTypically, that '1st ODBC' work would be in one job and the results would be landed somewhere, say in USERSTATUS. Then a Sequence job would read the value from user status and assign it to a Job Parameter in a second job where the '2nd ODBC' would use it in its where clause.
Job design is:

Code: Select all

Job1_Activity --> UserVariableActivity --> Job2_Activity
Steps:
1- Create a server routine called 'DSSetUserStatus' to set the value of $UserStaus variable:

Code: Select all

Call DSSetUserStatus(Arg1) 
Ans =Arg1
2-At job1, select max(date) in max_date column, then use transformer to create a stage variable which has a drivation and sending the output to a dummy file:

Code: Select all

DSSetUserStatus(max_date)
3-At job2, in where clause set date = #Param.MaxDate#
4-Now the $UserStatus variable should hold the max_date value.

My questions:
1- At job1_Activity, what is the required expression for 'UserStatus' expression?
2- At UserVariableActivity, after adding a new row what's the expected expression also?

Sorry for long post.

Regards.
[/code]
Last edited by sohasaid on Wed Jun 23, 2010 6:32 am, edited 1 time in total.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

1. Job1_Activity.$UserStatus - pick it from the list of operands in an expression.

2. Job1_Activity.$UserStatus - pick it from the list of operands in the expression editor.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

Post by sohasaid »

Ray, I've tried to use 'Job1_Activity.$UserStatus' at Job1_Activity and UserVariableActivity but no output is generated from job2 which means that it didn't receive the parameter at run time. Also, I've examined the log of job2 and the select statement is receiving the default value of parameter?

Also, I'm confused about where & how to map extactly the value @UserStatus to a specific parameter in a parameter set, #MaxDate# for example?

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

Post by ray.wurlod »

@UserStatus is not available in other processes.

Look at the job log for job 2 to see what it actually received. Did you pick the activity variable from the expression editor when filling in the parameter value expression in the Job activity Job2_Activity?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sohasaid
Premium Member
Premium Member
Posts: 115
Joined: Tue May 20, 2008 3:02 am
Location: Cairo, Egypt

Post by sohasaid »

ray.wurlod wrote: Did you pick the activity variable from the expression editor when filling in the parameter value expression in the Job activity Job2_Activity?
It worked out, Ray. Your question was the key. At job2, I was defining a parameter set not a single parameter on job2 level, so the Value Expression for it at Job2_Activity was always 'As pre-defined' .

Steps:
1- I've created a new single parameter on the job2 level #MaxDateVar#
2- use #MaxDateVar# in job2's where condition to retreive data based on it
3- At Job2_Activity stage, assign 'Job1_Activity.$UserStatus' to #MaxDateVar#

So, I've found no need to use UserVariableActivity stage, I removed it and it worked fine.

Code: Select all

Job Design: Job1_Activity -->Job2_Activity
Thanks a lot, Ray for your support & time. :)

Regards.
yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Post by yaminids »

Ray,

Would it be possible to pass two variables using UserStatus?

I followed the design, explained above, and prepared 2 jobs and 1 Sequence. Also, I created a customer routine to get the user status
Call DSSetUserStatus(Arg1)
Ans =Arg1
Job-1 --> passes an argument to the routine
Job-2 --> selects data from db based on the variable retrieved by $USERSTATUS

I'm working on a new project which requires me to pass more than 1 variable from Job-1 to Job-2. Would I be able to do that?

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

Post by chulett »

You can put any number of values in $UserStatus - in a delimited string. Then your call to get any value back would just need to include the field number from the delimited string which you then parse out and return.
-craig

"You can never have too many knives" -- Logan Nine Fingers
yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Post by yaminids »

Craig,

Thanks for your response.

To make myself clear, should I change the function to the following
Call DSSetUserStatus("Arg1,Arg2")
Ans =(Arg1, Arg2)
I'm using Stage variables in Job-1 to call the function. How can I pass values to the 2 variables in this job?

Thanks
Yamini
yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Post by yaminids »

Craig,

On further analysis I found that we can't pass more than 1 argument to the routine DSSetUserStatus.

Can you please explain how I can put more than 1 value in $USERSTATUS (in a delimited string)

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

Post by chulett »

You concatenate them together with the delimiter of your choice, in other words you create the delimited string to pass to the function. No change is needed in the function itself, all it ever does is take the passed in value, store it in UserStatus and then pass it back out.

So rather than calling it like this:

CallDSSetUserStatus(Arg1,Arg2)

You would call it like this:

CallDSSetUserStatus(Arg1:"|":Arg2)
-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 »

And then, when you need to unpack the delimited string, use the Field() function. The first element is returned by

Code: Select all

Field(JobActivity.$UserStatus, "|", 1, 1)

and the second element is returned by

Code: Select all

Field(JobActivity.$UserStatus, "|", 2, 1)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Post by yaminids »

Ray/Craig,

Thanks a lot for your help

-Yamini
Post Reply