Page 1 of 1

Exiting loop without aborting job

Posted: Fri Apr 03, 2009 7:42 am
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

Posted: Fri Apr 03, 2009 7:59 am
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.

Posted: Fri Apr 03, 2009 9:21 am
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:

Posted: Fri Apr 03, 2009 9:43 am
by girija
Did your command stage create file name list with the delimeter after the last file name?

Posted: Fri Apr 03, 2009 1:36 pm
by ray.wurlod
Take a look at the Webinar on job sequence techniques with file processing. (www.dsxchange.net)

Posted: Mon Apr 06, 2009 3:22 am
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 ... :-)

Posted: Mon Apr 06, 2009 3:59 am
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

Posted: Mon Apr 06, 2009 5:13 am
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

Posted: Mon Apr 06, 2009 5:35 am
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

Posted: Mon Apr 06, 2009 7:26 am
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:

Posted: Mon Apr 06, 2009 7:54 am
by BIuser
YOU WERE RIGHT !!!! (As usual ...) :lol:

Thanks so much !!!

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

Kind regards
Barbara

Posted: Mon Apr 06, 2009 5:29 pm
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