Page 1 of 1

Accessing Datastage Env variable value in Basic Rouitne

Posted: Tue Jul 15, 2008 2:35 pm
by dstest
Hi,

Can any one please tell me how to access datastage Env variable value in basic routine.

Thanks

Posted: Tue Jul 15, 2008 3:10 pm
by rameshrr3
You can use a code snippet similar if you have a job handle attached.

Code: Select all

CurrentJobHandle = DSJ.ME 
/* CurrentJobHandle= DSAttachJob(JobName,DSJ.ERRFATAL)*/
TargetEnv =  '$TARGET_ENV'
TargetEnvValue = DSGetParamInfo(CurrentJobHandle, TargetEnv, DSJ.PARAMVALUE)
Ans = TargetEnvValue
In the example above $TARGET_ENV is a parameter defined as a DS Environment variable.

Posted: Tue Jul 15, 2008 6:00 pm
by umamahes
I know this way.I am asking is there any other way with out adding env in the job parameter can we access env value in basic routine

Posted: Tue Jul 15, 2008 7:10 pm
by ray.wurlod

Code: Select all

FUNCTION GetEnvironmentVariable(EnvVarName)
      If UnAssigned(EnvVarName) Or IsNull(EnvVarName)
      Then
         Ans = @NULL
      End
      Else
         Call DSExecute("UV", "ENV", Output, ExitStatus)
         FindStr EnvVarName In Output Setting FMC,VMC,SMC
         Then
            Ans = Field(Output<FMC,VMC,SMC>, "=", 2, 99)
         End
         Else
            Ans = ""
         End
      End
RETURN(Ans)

Posted: Wed Jul 16, 2008 12:23 pm
by vivekgadwal
I have a question with this routine Ray.

> Is there a reason why "UnAssigned()" is present twice?

Code: Select all

If UnAssigned(EnvVarName) Or UnAssigned(EnvVarName) 
      Then 
         Ans = @NULL

Posted: Wed Jul 16, 2008 12:37 pm
by kcbland

Code: Select all

UNIXcmd="echo $yourenvironmentvariable"
CALL DSExecute("UNIX", UNIXcmd, ScreenOutput,ReturnCode)
yourenvironmentvariable = ScreenOutput<1>

Posted: Wed Jul 16, 2008 3:58 pm
by ray.wurlod
The test condition should have been

Code: Select all

UnAssigned(EnvVarName) Or IsNull(EnvVarName)
:oops:

I have edited the original post to show this.