cancel
Showing results for 
Search instead for 
Did you mean: 

Flat File Event Trigger base Job Scheduling in BODS

Former Member
0 Kudos

I have to schedule a job at 9am and it could run based on file event.That means, My bods job has to check wether file has arrived or not within 10 minutes like this it has to check 6 times every 10minutes if doesn't arrive then it has send an email,if its arrive it should run.

Iam completely novice to bods and it would be great if any one share complete logic detailly. However, I have found script on other post

which test file is arrived or not for ten minuts, but as per my requirement it has to verify 6 times for every ten minutes. please show your insight on it.

Wait for a file
$FileName= 'C:\\DIR\\FlatFile_' || to_char( sysdate( ), 'YYYYMMDD' ) ||  '.csv';
print ( $FileName );

While ( file_exists ( $FileName ) = 0 )
Begin
print( 'Waiting for File' );
Sleep(600);
End
print ( 'File Received Successfully' );
print ( 'File Processing Started' );

Accepted Solutions (1)

Accepted Solutions (1)

former_member187605
Active Contributor
0 Kudos

if (wait_for_file ( file_name_pattern, 3000000, 600000) <> 1) then

  begin

  smtp_to(.... ); # send mail

  raise_exception('No valid file found');

  end

Former Member
0 Kudos

My special thanks to Dirk Venken, Its worked fine.

Dirk Could you help me bit more,

1) How could I put some message?, "The file is arrived and job started" if statement became false. i.e file arrives within time.

2) How could I call other data flow to continue if the file is arrived.?

former_member187605
Active Contributor
0 Kudos

1/. Simply add a line at the end of the script:

     print('The file has arrived and job started');

2/. You don't have to "call" the data flow. Just include it after the script (connect the dots!) in the embedding job or work flow. When the file doesn't arrive, the job terminates as a result of the raise_exception function call; when it does, the script terminates with the print statement and the data flow will be started.

Answers (2)

Answers (2)

chethan_lingaraju
Active Participant
0 Kudos

Hello Srinath,

Best practice is to Isolate such file wait activity from BODS jobs.

For an exact problem, we implemented VB-Script which take four parameters -

  1. Path where files arrive
  2. A text file path & its name which has a list of file names to wait for
  3. Query interval (In your case 10 min)
  4. Attempts (in your case 6)

We dint implement "email upon no files" but instead, script returns error number which can be captured as a response in BODS exec function and take necessary actions.

When file arrival is complete, script will execute the batch file corresponding to BODS job.

Add "batch file name to execute upon file arrival" as 5th parameter to your script. It will be a perfect reusable artifact.

Cheers

Former Member
0 Kudos

Hello Chetan, Thanks for response and suggestion. However, as per my client everything has to be inside the BODS, if we go vb script or unix shell script its out of bods that which client doesn't wants to implement it. In fact, I too have shell script which checks every 10 minutes 6 times calls bods job(.sh)  but client doesn't wants to go out of bods control.

chethan_lingaraju
Active Participant
0 Kudos

Hi Srinath,

The script you quoted will wait indefinitely for file until it arrives.

Not sure if we can break loop using a incremental counter inside loop.

Or else, you will have to modify a bit. Instead of while loop, use "if else if block"

I dint check for syntax, script will be somewhat similar to the below:

$FileName= 'C:\\DIR\\FlatFile_' || to_char( sysdate( ), 'YYYYMMDD' ) ||  '.csv';

print ( $FileName );

IF ( file_exists ( $FileName ) = 0 )

Begin

    print( 'Waiting for File - attempt 1' );

    Sleep(600);

Else IF ( file_exists ( $FileName ) = 0 )

Begin

    print( 'Waiting for File - attempt 2' );

    Sleep(600);

Else IF ( file_exists ( $FileName ) = 0 )

Begin

    print( 'Waiting for File - attempt 3' );

    Sleep(600);

Else IF ( file_exists ( $FileName ) = 0 )

Begin

    print( 'Waiting for File  - attempt 4' );

    Sleep(600);

Else IF ( file_exists ( $FileName ) = 0 )

Begin

    print( 'Waiting for File - attempt 5' );

    Sleep(600);

Else IF ( file_exists ( $FileName ) = 0 )

Begin

    print( 'Waiting for File - attempt 6' );

    Sleep(600);

Else

    print( 'File wait failed' );   

    #<raise exception to kill the job if required>

End

print ( 'File Received Successfully' );

print ( 'File Processing Started' );

Try and let me know.

chethan_lingaraju
Active Participant
0 Kudos

I think I did the stupid way,

Try this logic- correct the syntax

$FileName= 'C:\\DIR\\FlatFile_' || to_char( sysdate( ), 'YYYYMMDD' ) ||  '.csv';

print ( $FileName );

$attempt = 0

While ( file_exists ( $FileName ) = 0 AND $attempt < 6)

Begin

    print( 'Waiting for File' );

    Sleep(600);

    $attempt = $attempt + 1;

End

If $attempt < 6

    print ( 'File Received Successfully' );

Else

    print ( 'no files' );

     #<do other actions>

End

former_member198401
Active Contributor
0 Kudos

Selective Reading and Postprocessing - Enterprise Information Management - SCN Wiki

Refer to DS reference guide for the function wait_for_file()

wait_for_file ( file_name_pattern, timeout, poll_interval,max_match, file_name_list, list_size, list_separator)

You can specify the timeout and poll_interval to achieve the requirement

Regards

Arun Sasi

Former Member
0 Kudos

Hi Arun,

I couldn't find much explanation in pdf, if possible could you please incorporate my requirement in the above function. As I am novice bods not able to utilize the above function.

former_member198401
Active Contributor
0 Kudos

Refer to below SAP Note. Its almost similar to your requirement.

1825911:How to use wait_for_file function in a data services job to access bunch of files in a folder and process it one file at a time

Regards

Arun Sasi