Welcome Guest! Log in
×

Notice

The forum is in read only mode.
Stambia versions 2.x, 3.x, S17, S18, S19 and S20 are reaching End of Support January, 15th, 2024. Please consider upgrading to the supported Semarchy xDI versions. See Global Policy Support and the Semarchy Documentation.

The Stambia User Community is moving to Semarchy! All the applicable resources have already been moved or are currently being moved to their new location. Read more…

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
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.