Zero Byte file Input problem

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
muruganr117
Participant
Posts: 40
Joined: Sun Jan 21, 2007 1:52 pm
Location: Chennai
Contact:

Zero Byte file Input problem

Post by muruganr117 »

Hi ,

I wanna know, how is it able to write one record to output file, if the input file is a zero byte file, means there is no data in input file. I need one record to be written to output file. Both are sequential flat files. Please assist me in this regard

Thank you in advance

regards
Murugan
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You're right, an empty source file will process zero records in the job and then nothing will be written to the target file. What is special about this 'one record' that needs to be written when you have no input? Describe it, please.
-craig

"You can never have too many knives" -- Logan Nine Fingers
muruganr117
Participant
Posts: 40
Joined: Sun Jan 21, 2007 1:52 pm
Location: Chennai
Contact:

Post by muruganr117 »

chulett wrote:You're right, an empty source file will process zero records in the job and then nothing will be written to the target file. What is special about this 'one record' that needs to be written when you have no input? Describe it, please.
Hi,

Thank you for your reply, The output file provides information related to count and time stamp related stuff. Hence if the input file is a zero byte file, the output should have zero in the count and then time stamp, This will be the record written in to the output file.

regards
Murugan R
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So do you always write only one record to the output file? Or do you process all of the incoming data, write some/all to the output and then always append one more record to the file? More of a curiosity than anything.

I'd suggest you write an 'after job' routine. Pass it in the Stage Name of the Transformer in the job, the Output Link from the transformer that writes to the output file and the full path to the output file. You can use that information in a call to DSGetLinkInfo with LINKROWCOUNT to get your count of how many records were written out, including zero. And the DSJobStartTimestamp macro can get you a good timestamp for the activity unless you already have one. Then simply build the record and echo/cat/type it onto the end of your file with '>>' style redirection. That or get fancy with the OPENSEQ, SEEK, WRITESEQ (etc) BASIC functions. Or build a second DataStage job run after the first (via a Sequence job) to add this 'trailer' record to the file.

Food for thought.
-craig

"You can never have too many knives" -- Logan Nine Fingers
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

A small routine - Check for file size and if zero byte write '0, current timestamp' into the file.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And if file has a header record for the column names? :wink:

A generic link row count check for zero always works.
-craig

"You can never have too many knives" -- Logan Nine Fingers
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Re: Zero Byte file Input problem

Post by JoshGeorge »

ONE record is the requirement :)
Last edited by JoshGeorge on Mon May 07, 2007 2:20 am, edited 1 time in total.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You missed my point. Completely.
-craig

"You can never have too many knives" -- Logan Nine Fingers
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

If the incoming file is zero byte it implies it won't have a header.
So if we check and find it is zero byte then we just have to write '0, current timestamp' to the output file (Append).
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

An 'empty' file can also have a single header record, in which case it will not be zero bytes in size but still process zero rows. My advise was more for the masses, general advice for determining emptiness and not specific to this issue where the OP 'knows' empty does in fact = zero bytes.
-craig

"You can never have too many knives" -- Logan Nine Fingers
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Was just making my point. Yep for 'masses' :) Didn't say that it is not a good idea.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
muruganr117
Participant
Posts: 40
Joined: Sun Jan 21, 2007 1:52 pm
Location: Chennai
Contact:

Post by muruganr117 »

chulett wrote:So do you always write only one record to the output file? Or do you process all of the incoming data, write some/all to the output and then always append one more record to the file? More of a curiosity than anything.

I'd suggest you write an 'after job' routine. Pass it in the Stage Name of the Transformer in the job, the Output Link from the transformer that writes to the output file and the full path to the output file. You can use that information in a call to DSGetLinkInfo with LINKROWCOUNT to get your count of how many records were written out, including zero. And the DSJobStartTimestamp macro can get you a good timestamp for the activity unless you already have one. Then simply build the record and echo/cat/type it onto the end of your file with '>>' style redirection. That or get fancy with the OPENSEQ, SEEK, WRITESEQ (etc) BASIC functions. Or build a second DataStage job run after the first (via a Sequence job) to add this 'trailer' record to the file.

Food for thought.
Hi Craig..

Thank you for your suggestions. I need to get a understanding of a point stated. Do you mean to say that code a routine to write a record into a file as in UNIX style?
Post Reply