-my ($StartMonth,$EndMonth) = &GetTimePeriod($Options{'m'},$Options{'p'});
-# if time period is more than one month: set output type to '-o pretty' or '-o dumpgroup'
-if ($Options{'o'} eq 'dump' and $Options{'p'}) {
+my ($StartMonth,$EndMonth);
+# if '-a' is set, set start/end month from database
+# FIXME - it doesn't make that much sense to get first/last month from database to query it
+# with a time period that equals no time period ...
+if ($Options{'a'}) {
+ undef($Options{'m'});
+ undef($Options{'p'});
+ my $DBQuery = $DBHandle->prepare(sprintf("SELECT MIN(month),MAX(month) FROM %s.%s",$Conf{'DBDatabase'},$Conf{'DBTableGrps'}));
+ $DBQuery->execute or die sprintf("$MySelf: E: Can't get MIN/MAX month from %s.%s: %s\n",$Conf{'DBDatabase'},$Conf{'DBTableGrps'},$DBI::errstr);
+ ($StartMonth,$EndMonth) = $DBQuery->fetchrow_array;
+} else {
+ ($StartMonth,$EndMonth) = &GetTimePeriod($Options{'m'},$Options{'p'});
+};
+# if -p or -a are set: drop -m
+undef $Options{'m'} if ($Options{'p'} or $Options{'a'});
+# if time period is more than one month: force output type to '-o pretty' or '-o dumpgroup'
+if ($Options{'o'} eq 'dump' and ($Options{'p'} or $Options{'a'})) {