Deletion of output file

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

Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

DSguru2B,

I need some information on COMMON variables for the same issue. Let me know whether following works or not:

Data for the target sequential file stages is passed through the Transformer stage. In the constraints section of the file stage, I called the following routine. If the routine returned value is 1, then that record will be inserted in the file else, rejected.

Routine name: mstat

IF Len(EndDate)=0 THEN
Ans = 0
END ELSE
IF (Iconv(Field(CurrentDate," ",1),"D-DMY[2,2,4]") - Iconv(Field(EndDate," ",1),"D-YMD[4,2,2]")) < 0 THEN
Ans = 0
END ELSE
Ans = 1
End
END

So, I know when the record is going to be inserted in the file. So can I use a counter in this routine, whenever the returned value is 1 (Ans=1), counter will be incremented by 1.

For deleting the empty file, I can have a after-job routine. In this, if I can get access to this counter (final) value, I can check whether this = 0 or not. If it's zero, I can delete the file by creating the following routine (with COMMON Variables):

COMMON ..................
If Counter = 0 Then
Command = 'Erase "':MoutDir:'\':WarnFileName:'.':dttm:'.war.csv"'
Call DSExecute("NT", Command, Output, SystemReturnCode)
End
End

Please advise me on this.
Also let me know status function, which Ray had created earlier.
dsx
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Latha1919 wrote:I need to have the column names in the file.
In that case, skip the whole 'check the file size' way and check link counts instead.

An after job routine can be used to query the job using DSGetLinkInfo to determine the count of rows that went down any given link. Check for a zero count there and then delete the file associated with that link. Lather, rinse, repeat.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

I am getting the following error when I use the DSGetLinkInfo while creating Before/After routine.

Array 'DSGetLinkInfo' never dimensioned.
dsx
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Never seen that kind of message before? :wink:

It means you need to include the header file with the function declaration for DSGetLinkInfo... JOBCONTROL.H off the top of my head. Search the forum for the proper syntax, something like:

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H
This needs to be at the top of your routine.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

I included the below mentioned files in the routine and so I am not getting any error while compiling the routine.

$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

CountRows = DSGetLinkInfo(DSJ.ME,"WarningOut","ToWarningOut", DSJ.LINKROWCOUNT)

However, as I said earlier, File will have the first row as column names. Do I need to condier the CountRows as 1, if I have to delete the empty file (having only the column names).

Is the row of column names is also considered in the rowcount or not?

Please advise.
dsx
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

No, column names is not considered a row when getting row counts through DSGetLinkInfo(). You need to check for row count zero.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Latha1919 wrote:Is the row of column names is also considered in the rowcount or not?
No. I wouldn't suggest something like that specifically to counter the issue of column headings if it wouldn't work as suggested. Trust me. :P

As noted, you are checking the link that is sending data to the Sequential file, counting the records being sent to the stage - not counting the total number of records in the file. Almost the same thing but not quite in this case.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

I created a before/after job routine as below for deleting the empty file (after the job run), but its not working out, please advise me whats wrong with code: (This job will be recursively called for processing the data in different directories.)

$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

ErrorCode = 0 ;* set this to non-zero to stop the stage/job

MoutDir= Field(InputArg,"~",1)
WarnFileName= Field(InputArg,"~",2)
dttm = Field(InputArg,"~",3)

WarnRows = DSGetLinkInfo(DSJ.ME,"WarningOutbox","ToWarningOutbox", DSJ.LINKROWCOUNT)

If WarnRows = 0 Then
Command = 'Erase "':MoutDir:'\':WarnFileName:'.':dttm:'.war.csv"'
End

Call DSExecute("NT", Command, Output, SystemReturnCode)
dsx
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Please expand on "its not working out".

As I read your code, the Input Values field should provide a string of the form directorypath~filename~datetime and issues an ERASE command for the file

Code: Select all

directorypath\filename.datetime.war.csv 
if the link row count is zero.

Add some diagnostic capability. For example:

Code: Select all

$DEFINE DEBUGGING
$IFDEF DEBUGGING
Message = "Parse results: "
Message<-1> = "MoutDir = " : Quote(MoutDir)
Message<-1> = "WarnFileName = " : Quote(WarnFileName)
Message<-1> = "dttm = " : Quote(dttm)
Call DSLogInfo(Message, "Debugging")
$ENDIF
Replace $DEFINE with $UNDEFINE when debugging is no longer required. You only need one $DEFINE declaration in the subroutine.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

Ray,

I can see only this much of you reply, but not complete one:

Please expand on "its not working out". As I read your code, the Input Values field should provide a string of the form directorypath~filename~datetime and issues an ERASE command for the file ...

Please advise. Also, let me know the code I have written in "Command = " is correct or not.

Thanks
dsx
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

For less than $1 per week you CAN read all of the premium posts. This money goes only part way towards funding this site. Without funding, it will cease to exist. Do you want that?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You could read the part where he asked you to expand on your "It's not working out" comment, how about taking a stab at that? There's nothing obviously wrong with what you've posted that I can see, but without specific examples of your problem - what error you are getting, what it is doing wrong or not doing, something - we can't really be of much help.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

When the job processes the .csv input file, it wil create 2 to 3 files based on the number of written to output file or rejected rows. I am observing that after job is routine is deleting all the files from the output folder, where the out files are written. Also deleting the other input files that are to be processed.

Please advise.
dsx
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That is not possible from the code you posted. Are you certain that there is no wildcard character in the pathname you generate for the ERASE command?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Latha1919
Premium Member
Premium Member
Posts: 178
Joined: Mon May 22, 2006 2:32 pm

Post by Latha1919 »

Following is the code, I have used in the before/after job routine. I am not finding any wild card characters here.

WarnRows = DSGetLinkInfo(DSJ.ME,"WarningOutbox","ToWarningOutbox", DSJ.LINKROWCOUNT)

If WarnRows = 0 Then
Command = 'Erase "':MoutDir:'\':WarnFileName:'.':dttm:'.war.csv"'
End

Call DSExecute("NT", Command, Output, SystemReturnCode)
dsx
Post Reply