That message can indicate that you've used the variable name ANS rather than the name Ans. Variable names are case sensitive.
It can also mean that there is a path through your code in which the Ans variable is not set at all - maybe you failed to open the "table" (directory) or to read the "record" (file).
To avoid the latter you need to initialize the Ans variable.
And, Craig did spot an omission, I intended to use ReadU not Read - this sets an update lock on the "record" so you don't lose updates made from multiple DataStage processes to this file.
Code: Select all
FileDir = "E:\ETL"
FileName = "weightA0.txt"
Ans = @NULL ; * initialize return variable
OpenPath FileDir To FileVar
Then
* Because the ReadU statement lacks a LOCKED clause, it will wait
* indefinitely for any lock to be released. You could, alternately,
* build in a sleep/retry mechanism if the lock is detected.
ReadU File From FileVar, FileName
Then
LineNumber = 0
Loop
Remove FileLine From File Setting MoreLines
* logic to extract pieces most efficient in field order
BRANCH=FIELD(FileLine,",",1)
AO=FIELD(FileLine,",",2)
MAX=FIELD(FileLine,",",3)
CNT=FIELD(FileLine,",",4)
LineNumber += 1
If BRANCH=BRANCH_NBR AND MAX>CNT
Then
FileLine = Fieldstore(FileLine,",",4,1,CNT+1)
Exec = FileLine
File<LineNumber> = FileLine
Exit
End
Else
Exec="999"
End ; * end of IF statement
While MoreLines
Repeat
Write File To FileVar, FileName
Else
Call DSLogWarn('Unable to write to file', 'Routine')
End
End
Else
* File does not exist, so release the update lock
Release FileVar, FileName
End ; * end of READ statement
End ; * end of OPEN statement
* Return the fileline which is found to be rewritten
Ans=Exec