How to abort a job in a routine if the source file is empty?

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
Shaina Austin
Participant
Posts: 17
Joined: Wed Jul 07, 2004 7:59 am

How to abort a job in a routine if the source file is empty?

Post by Shaina Austin »

Hi All:

My source file has 1 header, n detail and 1 trailer records.

First I perform a check on the header, if the header is not found, I abort the job after 1 record in the constraint.

I need to do the same with the trailer. I reject the trailer in a separate sequencial file, here if the trailer is not found then abort the job. I am unable to do this in the constraint, as there is no record found in the sequencial file, if the trailer does not appear in the source file.

Hence I am trying to write a routine using the DSLogfatal, but cannot get started with it. Can anyone please guide me thru the steps I need to follow or what should be included in the routine. Also where and how do I implement this routine?

Any help is greatly appreciated.
lebos
Participant
Posts: 74
Joined: Mon Jan 20, 2003 10:02 am
Location: USA

Post by lebos »

One way to do this is to write a "Dummy" trailer record to your trailer reject file at the beginning of your job. This way the file is never empty and you can check it later in a constraint to see if it contains a real trailer or the dummy one.

This involves a little overhead, but not much.

Larry
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Why not write a before/after routine that uses Unix commands? In the routine, you can use the DSExecute API (search the forum for LOADS of examples) to execute a shell command. You can do heads and tails and lots of stuff that will return the screen output in a variable, then look at the variable and take appropriate action. To call DSLogFatal, again search the forum for loads of examples.
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
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

Post by DSkkk »

i need to abort the job if there are no records in it. i get a header which gives the rowcount but i do not know where and how to compare this. if this is 0 then the job should stop abort.
can you please help me.
g.kiran
lebos
Participant
Posts: 74
Joined: Mon Jan 20, 2003 10:02 am
Location: USA

Post by lebos »

In the tranform into which the input file is going, code something like the following in a derivation field:

If Input.HeaderCount = 0 then UtilityAbortToLog("No Records to process") Else Input.HeaderCount

Modify this to fit your needs. Use field names to match your transform, put your own expression after the else.

You might want to verify the syntax, but it is close.

Larry
arunverma
Participant
Posts: 90
Joined: Tue Apr 20, 2004 8:20 am
Location: MUMBAI
Contact:

Post by arunverma »

Hi ,

We had also same problem , but we resolve this problem with Unix shell scripting, we had got confirmation that source file having standard head and trailer , then we create unix script which check header and trailer and call this script in datastage job - before job subrotuine .



With Regards

Arun
Arun Verma
dsxdev
Participant
Posts: 92
Joined: Mon Sep 20, 2004 8:37 am

Post by dsxdev »

You can achieve this functionality in a routine by using DSExecute and all the logic embedded inthe Code. Even Job cintrol Code would be another option.
Happy DataStaging
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

Post by DSkkk »

i solved the problem using a shell script.
thank you though for trying to help me
g.kiran
Shaina Austin
Participant
Posts: 17
Joined: Wed Jul 07, 2004 7:59 am

Post by Shaina Austin »

Hi,

Kiran, I am still not able to abort my job, if the file is empty. Can u explain, how u acheived this using a shell script?

Probably, it might help me in doing the same.

Thx.
Post Reply