Exiting loop without aborting job

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
BIuser
Premium Member
Premium Member
Posts: 238
Joined: Thu Feb 02, 2006 4:03 am
Location: South Africa

Exiting loop without aborting job

Post by BIuser »

Hi there

I have implemented the following sequence job.

Command stage ---- User Variable Stage ---- StartLoop ---- Job ---- EndLoop

This sequence reads files out of a directory and then passes the value to the same job using the User Variable Stage. The job works perfectly with one small problem. When the Command Stage gets to the last file and it loops back to find the next, there is no file for it to find - however, the job still runs and then ABORTS because it cannot find a file in the directory.

Problem is - we do not want to reset jobs all the time before we can run them again - we'd prefer if the loop exited gracefully !!!! Any way we can get around the ABORT situation ...

Your help is always appreciated.

Barbara
-------------------------
https://www.ssa.co.za
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

There's no "loop" in the Command Stage, it should just be generating a snapshot, a static list of the files available at the time it ran. Sounds like you have an "extra" delimiter at the end of your list, something causing it to loop one more time than it should. Verify that and then trim it off before the StartLoop stage consumes it.
-craig

"You can never have too many knives" -- Logan Nine Fingers
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

what Craig has written is the most likely problem in such cases.

I am assuming that you are using list loop not a numeric loop. :wink:
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
girija
Participant
Posts: 89
Joined: Fri Mar 24, 2006 1:51 pm
Location: Hartford

Post by girija »

Did your command stage create file name list with the delimeter after the last file name?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Take a look at the Webinar on job sequence techniques with file processing. (www.dsxchange.net)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
BIuser
Premium Member
Premium Member
Posts: 238
Joined: Thu Feb 02, 2006 4:03 am
Location: South Africa

Post by BIuser »

Hi there

This is the output from my command stage:
CO 19 TRANS DEC08.csv
CO 18 TRANS REPORT.csv
File Not Found

My user variable stage has the following syntax:

Trim(Left(Convert(@FM, ",", Cmd_TransFile_To_Load.$CommandOutput), Len(Cmd_TransFile_To_Load.$CommandOutput) - 1))

Where do I trim the last space if I'm not doing it already in my user variable stage ?

Thanks !
Barbara

PS: Will check out suggestion that Ray made in the mean time ... :-)
-------------------------
https://www.ssa.co.za
BIuser
Premium Member
Premium Member
Posts: 238
Joined: Thu Feb 02, 2006 4:03 am
Location: South Africa

Post by BIuser »

Hi there Ray,

Unfortunately, security with regards to the Internet is so strict here in this organization that the Webinar is not accessible.... :-(

I'll have to wait to hear if anyone on the forum has ideas for me with regards to trimming the last file in the list.

Thanks a mil.

Barbara
-------------------------
https://www.ssa.co.za
sbass1
Premium Member
Premium Member
Posts: 211
Joined: Wed Jan 28, 2009 9:00 pm
Location: Sydney, Australia

Post by sbass1 »

Hi Barbara,

Can you post the exact command you're using to generate the file list?

Also, you may want to type "help dir" and "help for" in a cmd window. In particular, I've sometimes used "for" instead of "dir" to generate a list of files.

For example:

Code: Select all

for %i in (c:\temp\*.csv) do @echo %~dpnxi#
Check out the file modifiers at the end of the for help text.

HTH,
Scott
BIuser
Premium Member
Premium Member
Posts: 238
Joined: Thu Feb 02, 2006 4:03 am
Location: South Africa

Post by BIuser »

Hi there

This is the exact syntax for my command:
DIR /B/O-D "\\mcbcptfs01\groups\MHD\Data to load\Payroll files\TRANS files\*.csv" ls -m

**Please remember that this is on a Windows platform** (Don't know if it makes any difference).

Please let me know how I should change this ?

Barbara
-------------------------
https://www.ssa.co.za
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yes, it makes a HUGE difference and was something we discussed. Your "file not found" error comes from the "ls -m" you've mysteriously decided to leave at the end of your command. As noted much earlier, get rid of it. Problem solved. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
BIuser
Premium Member
Premium Member
Posts: 238
Joined: Thu Feb 02, 2006 4:03 am
Location: South Africa

Post by BIuser »

YOU WERE RIGHT !!!! (As usual ...) :lol:

Thanks so much !!!

I will happily mark topic as resolved ... AGAIN !

Kind regards
Barbara
-------------------------
https://www.ssa.co.za
sbass1
Premium Member
Premium Member
Posts: 211
Joined: Wed Jan 28, 2009 9:00 pm
Location: Sydney, Australia

Post by sbass1 »

BIuser wrote:**Please remember that this is on a Windows platform** (Don't know if it makes any difference).
Hi Barbara,

Yes as Craig noted, the O/S makes a difference as to what commands you execute (I'm sure you know that :) )

I'll just point out that my "for" example in my earlier post is Windows syntax. Knowing that syntax is useful to have in your Windows kitbag, and has helped me in the past. I still recommend a read of "help dir" and "help for" under Windows.

Regards,
Scott
Post Reply