Saturday, March 12, 2011

Calling an informatica workflow in a loop - Part 1

Issue Description: We had an informatica workflow which had a flat file as source.  We could have more than one file available at one time to be loaded.  The files had to be processed individually by the workflow. 

Issue Resolution: Two batch scripts were created.  The first (See Script One below) one had to ensure that only one file was picked up by the workflow at one time.  The script is such that the number of files allowed to be processed simultaneously was passed as parameter to the script. 
Also, it ensured that zero bytes file were not processed by the informatica workflow if we so desired.  The second batch script (See Script Two in Part 2 of this post) called the workflow in a loop.  This script has other features such as: error checks and detection of status of workflow from previous run. 

Script One:

 ::


:: Project : Self-Development
:: Purpose : Checks number of files and file size before they are processed by interface

:: Author : allispossibleteam

:: Date Started : 31 August 2010

:: Date Completed: 31 August 2010

:: Usage : checkFileSize.bat INTERFACE_CODE MAX_NUM_OF_FILES

::



@ ECHO on

SetLocal EnableDelayedExpansion



::

:: Interface code received as parameter one

::

SET INTERFACE_CODE=%1



::

:: MAX number of files allowed to be interfaced comes as parameter 2

::

SET MAX_NUM_FILES_ALLOWED=%2



::

:: Flag to indicate if we want to check number of files being interfaced

::

SET CHECK_NUM_OF_FILES=Y





::

:: Path containing source files

::

SET TGTDIR=xxx\%INTERFACE_CODE%



::

:: Flag to indicate if we want to fail interface if zero byte file is found

::

SET FAIL_ON_ZERO_BYTE_FILE=Y



SET FILE_COUNTER=0

SET FILE_SIZE=0

SET ZERO_FILE_SIZE_FOUND=N



for %%a in (%TGTDIR%\*%INTERFACE_CODE%*.*) do (

for %%b in ("%%a") do (

SET FILE_SIZE=%%~zb

SET /a FILE_COUNTER=!FILE_COUNTER!+1

)

IF !FILE_SIZE!==0 (

SET ZERO_FILE_SIZE_FOUND=Y

)

)

::

:: NO NEED TO CHECK, NO FILES IN FOLDER

::

IF %FILE_COUNTER%==0 (

GOTO END_OF_SCRIPT

)



IF %FAIL_ON_ZERO_BYTE_FILE%==Y (

IF %ZERO_FILE_SIZE_FOUND%==Y (

@ECHO FAILED DUE TO ZERO BYTE FILE SIZE

GOTO CAUSE_ERROR

)

)



IF %CHECK_NUM_OF_FILES%==Y (

IF %FILE_COUNTER% GTR %MAX_NUM_FILES_ALLOWED% (

@ECHO FAILED DUE TO NUM OF FILES EXCEEDING MAX

GOTO CAUSE_ERROR

)

)

:END_OF_SCRIPT

EXIT /B 0


:CAUSE_ERROR

EXIT /B 1

No comments:

Post a Comment