Datastage Basic WriteSeq
Moderators: chulett, rschirm, roy
Datastage Basic WriteSeq
Hi All
In Basic , How do i write a new record as first record in a file
After going through help, i figured out
openseq file to file.var then
writeseq "my new record" to file.var then
readseq line2 from file then
*do my logic on line2 of the file
---
End
End
CloseSeq
But I am not getting my desired output
output should be
my new record in line1
1234,2345 this record is first record prior to inserting line1
can any one suggest me what i should do..
Thanks.
In Basic , How do i write a new record as first record in a file
After going through help, i figured out
openseq file to file.var then
writeseq "my new record" to file.var then
readseq line2 from file then
*do my logic on line2 of the file
---
End
End
CloseSeq
But I am not getting my desired output
output should be
my new record in line1
1234,2345 this record is first record prior to inserting line1
can any one suggest me what i should do..
Thanks.
What are you trying to do? Using readseq and writeseq to manipulate data in a file is very tricky. Use readseq to scan a file from beginning to end. Use writeseq to sequentially write to a file from beginning to end.
You cannot move backwards and forwards in a file, manipulating one row, reading another, overwriting a row, etc using these commands.
You cannot move backwards and forwards in a file, manipulating one row, reading another, overwriting a row, etc using these commands.
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Thanks KC
I am trying to read a file (contains only one record)as an after job routine and check for value in column1 and column2 , if column1 is not equal to column 2 then i am sending an email with this file in the message body,
I am able to do the above ....
But, i want to insert a heading to the file with the column names .How can i insert a heading to a file that i am trying to read .
Hope i am clear
Thanks.
Nag.
I am trying to read a file (contains only one record)as an after job routine and check for value in column1 and column2 , if column1 is not equal to column 2 then i am sending an email with this file in the message body,
I am able to do the above ....
But, i want to insert a heading to the file with the column names .How can i insert a heading to a file that i am trying to read .
Hope i am clear
Thanks.
Nag.
The easiest way to "read" a file into an array is to simply "cat" or "type" the file.
Example:
The screen output is put into a variable called ScreenOutput. Now it's just an array. Each line in the screen output is a row in the array. So the first line is ScreenOutput<1>. The second line is ScreenOutput<2>, and so forth.
So, to write out a file, simple overwrite it completely. To do this, you'll want to write a routine that you can call whenever you want to output a file. Notice the WEOFSEQ, which truncates an existing file after you've written over it partially. Here's mine I call OutputFile, it's a subroutine you can CALL using InputArg as the filename and @USER0 (global variable) as the array of file contents:
Example:
Code: Select all
UNIXcmd = "cat yourfilename"
Call DSExecute("UNIX", UNIXcmd, ScreenOutput, ReturnCode)
So, to write out a file, simple overwrite it completely. To do this, you'll want to write a routine that you can call whenever you want to output a file. Notice the WEOFSEQ, which truncates an existing file after you've written over it partially. Here's mine I call OutputFile, it's a subroutine you can CALL using InputArg as the filename and @USER0 (global variable) as the array of file contents:
Code: Select all
ValidOpen = @FALSE
filename = InputArg
If filename Then
OPENSEQ filename TO FILE Then
ValidOpen = @TRUE
End Else
CREATE FILE Then ValidOpen = @TRUE
End
End
If NOT(ValidOpen) Then
Call DSLogFatal("Could not create the file: ":filename, "OutputFile")
End
txt = @USER0
AM.CNT = DCOUNT(txt, @AM)
For i=1 to AM.CNT
WRITESEQ txt<i> TO FILE else
Call DSLogFatal("Could not update the file: ":filename, "OutputFile")
End
Next i
WEOFSEQ FILE
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
You can use it last as well, it just lops off the remainder of the file.chulett wrote:If you want to 'truncate' the sequential file before you start writing to it, use (from memory) WEOFSeq first.
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You don't need WeofSeq at the end. CloseSeq will write an end of file mark if you have written to the file and you're at the end of the file.
Your problem can be solved fairly easily given that there is only one line in the file.I leave it as an exercise to the reader to code the Else and other clauses.
Your problem can be solved fairly easily given that there is only one line in the file.
Code: Select all
OpenSeq .... To hFile
Then
ReadSeq Line From hFile
Then
* Position to beginning of file
Seek hFile, 0, 0
Then
WeofSeq hFile ; * truncate file
WriteSeq "Header stuff" To hFile
Then
WriteSeq Line To hFile
Then
Call DSLogInfo("File written. Yay!", "Output File")
End
End
End
End
End
CloseSeq hFile
Last edited by ray.wurlod on Tue Nov 09, 2004 3:32 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod wrote:You don't need WeofSeq at the end. CloseSeq will write an end of file mark if you have written to the file.
Okay, I haven't tested to back this up, but I believe Ray is mistaken. I have always used WEOFSEQ to insure that a file is truncated. If you open an existing file and then write to it fewer rows than what currently exist in the file, you have to use the WEOFSEQ to remove the remaining bytes from the original file. I'm pretty sure, but....Any other old Universe hacks want to chip in?
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
It's always possible. No-one's perfect. I'm remembering from Prime INFORMATION, but believe that CLOSESEQ behaves as I described in UniVerse and therefore in DataStage. Maybe will do the test in my copious free time! ![Laughing :lol:](./images/smilies/icon_lol.gif)
![Laughing :lol:](./images/smilies/icon_lol.gif)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ken,
You are correct regarding WEOFSEQ and CLOSESEQ. CLOSESEQ does not truncate the file and WRITESEQ certainly does truncate the file. The following is straight from the UV BASIC Reference guide -
Regards,
You are correct regarding WEOFSEQ and CLOSESEQ. CLOSESEQ does not truncate the file and WRITESEQ certainly does truncate the file. The following is straight from the UV BASIC Reference guide -
So issuing the WEOFSEQ is vital if you want to ensure that the file is truncated.Some systems do not support the truncation of disk files. WEOFSEQ is
ignored on these systems, except that WEOFSEQ always works at the
beginning of a file.
Regards,
Mike Hester
mhester@petra-ps.com
mhester@petra-ps.com
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Here's the test program;
0001: OPENSEQ "FREDFILE" TO HFILE
0002: THEN WEOFSEQ HFILE
0003: WRITESEQ "LINE 1" TO HFILE ELSE NULL
0004: WRITESEQ "LINE 2" TO HFILE ELSE NULL
0005: !!! WEOFSEQ HFILE
0006: CLOSESEQ HFILE
0007: STOP
0008: END
I inspected the result with filepeek and with vi. It made no difference whether line 5 was enabled or not. File FREDFILE did not exist prior to execution of the test, so the THEN clause was not executed.
I never claimed that CLOSESEQ would truncate a file, only that it would write an end of file mark at the end of the file.
0001: OPENSEQ "FREDFILE" TO HFILE
0002: THEN WEOFSEQ HFILE
0003: WRITESEQ "LINE 1" TO HFILE ELSE NULL
0004: WRITESEQ "LINE 2" TO HFILE ELSE NULL
0005: !!! WEOFSEQ HFILE
0006: CLOSESEQ HFILE
0007: STOP
0008: END
I inspected the result with filepeek and with vi. It made no difference whether line 5 was enabled or not. File FREDFILE did not exist prior to execution of the test, so the THEN clause was not executed.
I never claimed that CLOSESEQ would truncate a file, only that it would write an end of file mark at the end of the file.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.