To check the output file rowcount

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
pmadhavi
Charter Member
Charter Member
Posts: 92
Joined: Fri Jan 27, 2006 2:54 pm

To check the output file rowcount

Post by pmadhavi »

Hi my target is a flat file.
I have to check whether any rows have been populated to the atrget file or not.
if there are no rows they I have to display an error message.

So after loading the data into a temporary file before loading into the target, i used a transformer to check the no. of rows going to the target.
in the constraint section I gave @INROWNUM=0 to display the error and if the INROWNUM <>0 then they data will be populated to the target.

But it is not working. Do we have any specific functions to check the row count.
Please throw a light on the same. We are using DS 7.1r1
Thanks,
Madhavi
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

You'll never have a row go into an output link which requires a constraint check if there's no input rows. Your method doesn't work. Use an after-stage routine call and write a routine that checks the link values using the API libraries.
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
pmadhavi
Charter Member
Charter Member
Posts: 92
Joined: Fri Jan 27, 2006 2:54 pm

Post by pmadhavi »

kcbland wrote:You'll never have a row go into an output link which requires a constraint check if there's no input rows. Your method doesn't work. Use an after-stage routine call and write a routine that checks the link values using the API libraries.
Can u please tell me how to do that. I dont have idea on API libraries.
Thanks,
Madhavi
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

This forum has thousands of posts regarding doing what you ask, just use the Search. Your DS BASIC manual is available under your Start button.
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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Search for DSGetLinkInfo as a starting point.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pmadhavi
Charter Member
Charter Member
Posts: 92
Joined: Fri Jan 27, 2006 2:54 pm

Post by pmadhavi »

chulett wrote:Search for DSGetLinkInfo as a starting point. ...

The flow of job is as follows:

Source->Transformer1-->Transformer2-->Target

Now i need to check if the target is empty or it has rows.
if there's no data coming to the target flat file then it has to display the error message.

I created the routine called Countrows for DSGetLinkInfo as suggested.
I extended the job with one more transformer connected to the target file. I used this routine inside the transformer to find out the number of rows coming out of the target file.

If the target is empty, I dont know whether it will go to the next stage ie transformer to run the routine and get the number of rows.

I tried running the routine for an empty target file and tried diplaying the eror message if the routine returns no rows.
but it is not working. I was not successful in waht I have done. I dont know how it check the emptyness of a file or size of a file.

Pls help me out.
Thanks,
Madhavi
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Post your routine code. Plus I'd suggest you think about doing this 'post job' as in a Sequence job or possibly after job. It depends on exactly what you mean by 'display an error' if the processed row count is zero.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The number of bytes in a file is returned by the STATUS statement applied to the file variable associated with an opened file. In your case, since it's an operating system file in which you are interested, you would have opened it with OPENSEQ, and will close it with CLOSESEQ.

This has been described very recently on the forum. You would apply this test in an after job or after stage subroutine (using DSLogWarn to log a warning message), or in a Routine activity after the job had been completed (using a downstream Routine activity to invoke UtilityWarningToLog).

Plan exactly what you want to do in the circumstance that the file is empty, and you can implement precisely that plan.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pmadhavi
Charter Member
Charter Member
Posts: 92
Joined: Fri Jan 27, 2006 2:54 pm

Post by pmadhavi »

chulett wrote:Post your routine code. Plus I'd suggest you think about doing this 'post job' as in a Sequence job or possibly after job. It depends on exactly what you mean by 'display an error' if the processed row count is zero.
The code in the routine is as follows:
DSGetLinkInfo(DSJ.ME,StageName','linkname', DSJ.LINKROWCOUNT)

when I check the routine in DS manager it is returning -1.

I did not use any code to open the file like OPENSEQ.
My requirement is if there are rows they have to be populated and if tehre are no rows, the error message has to be written to the same target file, as the user doesn't want it to be in two seperate files.
Flow from temp target:

temp file--> transformer--> Actual target


in the transformer if i call the routine, i feel it not working properly because if there are no rows in the temp file, the flow is not proceeding to the next stage.
Thanks,
Madhavi
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

pmadhavi wrote:
The code in the routine is as follows:
DSGetLinkInfo(DSJ.ME,StageName','linkname', DSJ.LINKROWCOUNT)

when I check the routine in DS manager it is returning -1.
1.It's giving error in the Manager because you need to give JobHandle in place of DSJ.ME. You would need to attach the Job first using DSAttachJob to get the JobHandle and then use the JobHandle in your code.

2. If would like to use DSGetLinkInfo in a transformer stage you might want to design a job something like this

Code: Select all

Source->Transformer1--Tempfile>Transformer2-->Target 
instead of

Code: Select all

Source->Transformer1-->Transformer2-->Target 
as you mentioned in your earlier post.

Now in the second Transformer, you can define a stage variable which can read the number of rows passed into Temp file and based upon that you can write messages to log using DSTransform or to the output file.

IHTH
Kris

Where's the "Any" key?-Homer Simpson
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

pmadhavi wrote:I did not use any code to open the file like OPENSEQ.
Ray suggested OPENSEQ if you want to use the STATUS command. This command will tell you if your file is of zero bytes or not. But you want to get the row count on a particular link using DS functions. So basically you dont need OPENSEQ command.
My advice, do it in seperate jobs. Dont do all this in the same job. Build your Temp file. Then in your second job you can get the row count of that particular link and do what you have to do with it.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply