Here is a set of functions written by Stephen Wong of ISSP (
Stephen@issp-inc.com) that has been passed around for years that will set all parameters in a job to correspondingly named values in a file. You will need to auto-format these functions when pasting into DS Manager. The next posting will show how to use these two functions
This function, GetParameterArray, will be passed an parameter file in the format:
parameter_name1=value1
parameter_name2=value2
parameter_name3=value3
This function reads the file into an internal array, throwing away lines with leading comment characters.
DEFFUN FileFound(A) Calling 'DSU.FileFound'
FunctionName = "GetParameterArray"
Call DSLogInfo("Loading parameters from file: ":Arg1, FunctionName)
cBlank = ''
cName = 1
cValue = 2
vParamFile = Arg1
aParam = cBlank
vParamCnt = 0
vCurRoutineName = 'GetParameterArray'
vFailed = @FALSE
Done = @FALSE
IF vParamFile AND FileFound(vParamFile) Then
OPENSEQ vParamFile TO hParamFile Then
Loop
READSEQ vLineRaw FROM hParamFile
ON ERROR
Call DSLogWarn('Error from ':vParamFile:'; Status = ':STATUS(),vCurRoutineName)
CLOSE hParamFile
vFailed = @TRUE
Done = @TRUE
End Then
vLine = TRIM(vLineRaw)
vFirstChar = LEFT(vLine,1)
vRemark = LEFT(vLine,4)
IF NOT(vFirstChar = cBlank OR vFirstChar = '#' OR vFirstChar = '*' OR vFirstChar = '"' OR vFirstChar = "'" OR vFirstChar = ';' OR vFirstChar = ':' OR vFirstChar = '[' OR vRemark = 'REM ') THEN
vParamCnt += 1 ; * Add to any parameter array passed as an argument
aParam = TRIM(FIELD(vLine,'=',cName))
aParam = FIELD(vLine,'=',cValue)
END
END ELSE
Done = @TRUE
END
Until Done Do Repeat
CLOSE hParamFile
End Else
Call DSLogWarn('Error from ':vParamFile:'; Status = ':STATUS(),vCurRoutineName)
vFailed = @TRUE
End
End Else
vFailed = @TRUE
End
Call DSLogInfo("Values loaded: ":aParam, FunctionName)
If vFailed Then
Ans = "ERROR"
End Else
Ans = aParam
End
Create a second function, SetJobParameters, with three arguments:
Arg1 = Parameter List ( = parameter names, = parameter values)
Arg2 = Job Handle that parameters will be set for. (Must be attached to the Job/Batch)
Arg3 = Parameter names to be skipped. (Comma separated)
This function is used when actually starting a job up. It takes a job handle and queries the job for its list of parameters. It then matches that list to the internal array of parameter file values and sets the job to them:
$INCLUDE DSINCLUDE JOBCONTROL.H
*------------------*
* Define Functions *
*------------------*
DEFFUN Exists(A) Calling 'DSU.Exists'
*----------------------*
* Initialize Variables *
*----------------------*
Ans = 0 ; * 0=Successful(default), 1=Error occured
ParamList = Arg1
Job = Arg2
ProgName = "Function: SetJobParameters"
SkipParams = Arg3
CONVERT "|" TO @AM IN SkipParams
*------*
* Main *
*------*
IF Exists(ParamList) THEN
IF NOT(Job) THEN
Call DSLogFatal('Could not attach to job (':JobName:')',ProgName)
END
JobParamList = DSGetJobInfo(Job,DSJ.PARAMLIST)
IF Exists(JobParamList) THEN
CONVERT ',' TO @AM IN JobParamList
ParamCnt = DCOUNT(JobParamList,@AM)
FOR P = 1 TO ParamCnt
ParamName = JobParamList
If Exists(SkipParams) Then
LOCATE ParamName IN SkipParams SETTING SkipPos THEN CONTINUE
End
LOCATE ParamName IN ParamList SETTING Pos THEN
ParamValue = ParamList
* Call DSLogInfo('Parameter: ':ParamName:' = ':ParamValue,ProgName)
ErrCode = DSSetParam(Job,ParamName,ParamValue)
IF ErrCode THEN
Ans = 1
BEGIN CASE
CASE ErrCode = DSJE.BADHANDLE
ErrMsg = 'Invalid Job Handle for ':JobName
CASE ErrCode = DSJE.BADSTATE
ErrMsg = 'Job (':JobName:') is not in the right state (compiled, not running)'
CASE ErrCode = DSJE.BADPARAM
ErrMsg = 'ParamName (':ParamName:') is not a known parameter of the job'
CASE ErrCode = DSJE.BADVALUE
ErrMsg = 'ParamValue (':ParamValue:') is not appropriate for ParamName (':ParamName:')'
CASE 1
ErrMsg = 'Problem setting ParamName (':ParamName:'); Value = ':ParamValue
END CASE
Call DSLogWarn('Error [':ErrCode:'], ':ErrMsg,ProgName)
END
* END ELSE
* Ans = 1
* Call DSLogWarn('Parameter(':ParamName:') not passed in parameter list.',ProgName)
END
NEXT P
END
END ELSE
Call DSLogWarn('Missing parameter list ',ProgName)
Ans = 1 ; * Set error flag
END
Kenneth Bland