Hi,
I have 9 target files in my network drive/folder. out of which 2 are having data. other 7 files dont have data except headers.
can any one help me how to delete those empty files which are having only headers from the network folder.
How to acheive this using BODS?
Any help appreciated.
Regards
Krishna Mohan
Steps for deleting the files with no data in outbound folder:
Steps 1: Declare variables $G_TOTAL_ROWS (data type as int), $G_VALUE (data type as int)
Step2: create a script after the dataflow where you are creating the multiple files.
Step3: Write the below script under script_file_deletion
$G_TOTAL_ROWS = total_rows('DATASTORENAME.DBO.FIRSTTABLENAME);
print('Total records for FIRST_TABLE is :');
print($G_TOTAL_ROWS);
IF ($G_TOTAL_ROWS < 1)
$G_VALUE=exec('sh', '-c "rm /Data/FILE_NAME1.txt"', 8);
#Print('Data does not exist for FILE_NAME1 so file is deleted');
else
print('Data Exists for FILE_NAME1);
the above code works for LINUX not for windows.
Step4: Repeat code for other files.
Step5: Check whether file is deleted or not in the folder
Note: above script works for Linux platform.
Regards
Krishna Mohan
Hi Krishna,
Hope the following reference will help you fulfill your requirement.
How to avoid empty file generation in BODS | SCN
Hope this helps.
And if you need any specifics regarding implementing for your scenario..please do let me know
Thanks,
AJ
write a windows bat file to check if excel file with header is empty. Call the bat file in exec() in BODS.
Hello Krishna,
If SAP Data Services is hosted on Linux/AIX you can write shell script
if [ `wc -l filename` -gt 0]
rm filename
If SAP Data Services is hosted on Windows, you can write bat file
FINDSTR /R /N "^.*$" filename.txt | FIND /C ":"
You have to store file names in a file and then use while loop to read the file name one by one.
Krishna
It will get complicated if you write the logic to delete the empty excel files. Data Services can process multiple excel files and you should not worry about the empty ones.
You can include DI_FILENAME for each excel file. The excel containing the data will be loaded and the DI_FILENAME will be populated.
Hope this simplifies your work 😊
Regards
Arun Sasi
Add a comment