environmental variable in a rountine

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
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

environmental variable in a rountine

Post by parvathi »

Hi all,
I have set one parameter dirloc in the administrator.
The same parameter in the job is assigned a $projdef.
that is the parameer gets a environmental variable.

Can i assign an environmental variable to varible in routine.
If so can anbody tell me the function and the syntax to be used
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You can echo the value of that environtment variable using DSExecute() and assign it to your routine variable. This was discussed here a few weeks back. Search for more details.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If, as you say, the environment variable is a job parameter, you can use the DSGetParamInfo() function to retrieve its value.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

use the DSGetParamInfo() function to retrieve its value.
This worked out well. thanks
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

I was asked not to use the job parameter. instead get it from the enviromental varibale.i saw the few discussions from those


For this part i have this the syntax like this

Code: Select all

Call DSExecute("UNIX","echo $DSLOG_DIR",UnixOutput,SystemReturnCode)

var = UnixOutput
but still i get an error
I was setting it in a sample test routine.to see what output it gets. but i don't get any value

can any body correct me on the code if i have used it wrong
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The "UnixOutput" will also contain @FM characters. If it is empty, try echo-ing a value that you know is set, such as $DSHOME.
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

Even if i give that it is not working
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Please explain exactly what is 'not working' about it. Simply saying 'it is not working' or 'i get an error' without mentioning the error involved makes it pretty hard to help you. :?

You might want to post the entire routine. That snippet looks fine, the only 'error' I could see would be the value coming back empty if the variable is not set. Then again, that depends on your Operating System - some echo back an empty value when the variable isn't set while others actually return an error and specifically tell you it isn't set. You should always check the value of the 'SystemReturnCode' variable when using DSExecute in case Something Goes Wrong so you can handle it properly.
-craig

"You can never have too many knives" -- Logan Nine Fingers
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

I have gone through this the variable is echoed only when value is set in my .profile.h file
else it is not echoing the value.
I can't echo the value from the DSParams file.
EVEN in the DSParams file the value is not set
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:? You can echo that value of any environment variable that is currently set.

Your code, minimal as it is, works fine. Your conclusions must be based on testing the routine in the Manager, which is fine as long as you understand what you are seeing. In the Manager, the only environment variables available to you at that moment are those set in your .profile file. Environment variables that only exist in the Administrator (what you refer to as 'from the DSParams file') are only instantiated when a job runs. Outside of a running job, they do not exist.

Build yourself a test Sequence job. Use a single Routine Activity stage to call your routine. Run the job. Check the job's log for the 'Summary of sequence run' entry. Post the results.
-craig

"You can never have too many knives" -- Logan Nine Fingers
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post by parvathi »

I have tested the same. I am able to get the values but there is an attached extraspace to the value when i see the director aftter the value DSLogs

ChRtn..AfterJob (sample): Failed to open directory /data/sample/DSLogs


how can i remove the empty string
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

TRIM() can be used to removed trailing spaces. But I think you have a @FM in there as well - see my previous post.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Trim() function.
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