Welcome Guest! Log in

Topic-icon Question check flat file contain any records or not

More
16 Nov 2016 15:22 #1 by Prashant.Sangle
check flat file contain any records or not was created by Prashant.Sangle
Hi,

I want to check that file contain records or not, before move action perform.
If 0 records then send alert mail else proceed to next action.

Regards,
Prashant

Please Log in or Create an account to join the conversation.

More
16 Nov 2016 17:14 - 16 Nov 2016 17:18 #2 by Cyril Dussud
Replied by Cyril Dussud on topic check flat file contain any records or not
Hi,

I see different solutions to perform this:

1. If your file is supported by Stambia (Delimited/Positional, ...) you could simply perform a select on the file with a SQL Operation and check the number of results through a bind link.
For instance:


-> The caveat of this is that all the rows of the files are read

2. You could also make a little script that test the length of the file
For instance:


In this example, we are testing that the file exists, and then its length.
The script is:
File file = new File("${../filePath}$");

if (file.exists()) {
	if (file.length() == 0){
		__ctx__.publishVariable("~/fileStatus","EMPTY");
	}
	else{
		__ctx__.publishVariable("~/fileStatus","NOT_EMPTY");
	}
}else{
	__ctx__.publishVariable("~/fileStatus","NOT_EXISTS");
}

We are using then the variable we have published to split our Process, with conditions like
"${~/fileStatus}$" == "EMPTY"

I hope this answers to your question.:)
Attachments:
Last edit: 16 Nov 2016 17:18 by Cyril Dussud.

Please Log in or Create an account to join the conversation.