All,
A routine is reading a line from a text file and writing it in another file. I placed the routine in the before-job subroutine in job properties. the routine read the first line of the source file and inserted the line in the destination file, later it aborts. It is not reading the next lines of the source.
the code of the routine is below
ErrorCode = 0 ;* set this to non-zero to stop the stage/job
lPathname="d:ds-exercisemergefilecusttrainee.txt"
llPathname="d:ds-exercisemergefilecusttrainee2.txt"
OpenSeq lPathname To mailfile else
Call DSLogWarn(" Cannot Open " :lPathname,Myroutine)
GoTo ErrorExit
End
LOOP
ReadSeq mailline from mailfile
On Error
Call DSLogWarn(" Error from " :lPathname: " Status = " :Status(), "My Routine")
GoTo ErrorExit
End
Then
* split the line, create a structured file.
OpenSeq llPathname To FileVar Then
Loop
ReadSeq llPathname From FileVar Else Exit
Repeat
WriteSeq mailline To FileVar Else
* Call DSLogFatal("Cannot write to ":llPathname, "MyRoutine")
* GoTo ErrorExit
Exit
End
End Else
Call DSLogFatal("Cannot open file ":llPathname, "MyRoutine")
GoTo ErrorExit
End
CloseSeq llPathname
* write the line
End Else
Exit
End
Repeat
CloseSeq mailfile
ErrorCode = 0
ErrorExit:
CloseSeq mailfile
Abort
It is giving the following error
Attempting to Cleanup after ABORT raised in stage flatfile..BeforeJob
Kindly get back to me.
thanks,
T Sankar
Reading a file and writing it into another file
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Is any message logged prior to the abort?
You are re-opening your output file for every line read from the input file. This means that you are overwriting it each time. (And performance will be horrible.)
What is the line "ReadSeq llPathname From FileVar Else Exit" meant to achieve?
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
You are re-opening your output file for every line read from the input file. This means that you are overwriting it each time. (And performance will be horrible.)
What is the line "ReadSeq llPathname From FileVar Else Exit" meant to achieve?
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
Hi Ray,
No message is logged prior to the abort.
The line ReadSeq llPathname to FileVar Else Exit - is to move the cursor to the position where it will append the new record.
It is not overwriting the record, It is reading the next line ad not writing in to the output file. at time it showing the error message.
with regards,
T Sankar
No message is logged prior to the abort.
The line ReadSeq llPathname to FileVar Else Exit - is to move the cursor to the position where it will append the new record.
It is not overwriting the record, It is reading the next line ad not writing in to the output file. at time it showing the error message.
with regards,
T Sankar
Hi,
Routine was running with out any error.
ErrorCode = 0 ;* set this to non-zero to stop the stage/job
lPathname="d:ds-exercisemergefilecusttrainee.txt"
llPathname="d:ds-exercisemergefilecusttrainee2.txt"
OpenSeq lPathname To mailfile else
Call DSLogWarn(" Cannot Open " :lPathname,Myroutine)
GoTo ErrorExit
End
LOOP
ReadSeq mailline from mailfile
On Error
Call DSLogWarn(" Error from " :lPathname: " Status = " :Status(), "My Routine")
GoTo ErrorExit
End
Then
* split the line, create a structured file.
OpenSeq llPathname To FileVar Then
Loop
ReadSeq llPathname From FileVar Else Exit
Repeat
WriteSeq mailline To FileVar Else
* Call DSLogFatal("Cannot write to ":llPathname, "MyRoutine")
* GoTo ErrorExit
Exit
End
End Else
Call DSLogFatal("Cannot open file ":llPathname, "MyRoutine")
GoTo ErrorExit
End
CloseSeq llPathname
* write the line
End Else
Exit
End
Repeat
CloseSeq mailfile
ErrorCode = 0
Return ------------------ it does the routine run with out error.
ErrorExit:
CloseSeq mailfile
Abort
with regards,
T Sankar
Routine was running with out any error.
ErrorCode = 0 ;* set this to non-zero to stop the stage/job
lPathname="d:ds-exercisemergefilecusttrainee.txt"
llPathname="d:ds-exercisemergefilecusttrainee2.txt"
OpenSeq lPathname To mailfile else
Call DSLogWarn(" Cannot Open " :lPathname,Myroutine)
GoTo ErrorExit
End
LOOP
ReadSeq mailline from mailfile
On Error
Call DSLogWarn(" Error from " :lPathname: " Status = " :Status(), "My Routine")
GoTo ErrorExit
End
Then
* split the line, create a structured file.
OpenSeq llPathname To FileVar Then
Loop
ReadSeq llPathname From FileVar Else Exit
Repeat
WriteSeq mailline To FileVar Else
* Call DSLogFatal("Cannot write to ":llPathname, "MyRoutine")
* GoTo ErrorExit
Exit
End
End Else
Call DSLogFatal("Cannot open file ":llPathname, "MyRoutine")
GoTo ErrorExit
End
CloseSeq llPathname
* write the line
End Else
Exit
End
Repeat
CloseSeq mailfile
ErrorCode = 0
Return ------------------ it does the routine run with out error.
ErrorExit:
CloseSeq mailfile
Abort
with regards,
T Sankar
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You seem to have found the missing RETURN statement without which the code was dropping through to the ABORT statement.
As a general rule you should avoid use of the ABORT statement in DataStage BASIC, since it causes an immediate abort not only of the routine in which it occurs but also in the entire tree of callers. In a before/after subroutine, prefer to set the ErrorCode argument to a non-zero value, which is detected when the routine returns; this gives DataStage a chance to clean up (which the ABORT statement does not).
Tip: A useful statement to position to end of file (to append) is
SEEK filevariable,0,2 THEN statements ELSE statements
For example:
Seek FileVar,0,2
Else
Call DSLogWarn("Error seeking to EOF","MyRoutine")
End
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
As a general rule you should avoid use of the ABORT statement in DataStage BASIC, since it causes an immediate abort not only of the routine in which it occurs but also in the entire tree of callers. In a before/after subroutine, prefer to set the ErrorCode argument to a non-zero value, which is detected when the routine returns; this gives DataStage a chance to clean up (which the ABORT statement does not).
Tip: A useful statement to position to end of file (to append) is
SEEK filevariable,0,2 THEN statements ELSE statements
For example:
Seek FileVar,0,2
Else
Call DSLogWarn("Error seeking to EOF","MyRoutine")
End
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518