How tos

How To calculate database usage?

Author
Luc Van Dyck
Date
03/03/2003
Size
4,28 KB
Downloads
2403
Rating
321501
Popularity
Downloaded 4 times in the last two weeks
Sometimes you want to give a warning when database usage is getting close to the database size.
eg. For large batch operations, it becomes almost impossible to execute properly, when the database has reached 99% of the database size.

Therefore you need to calculate the database usage and database size, using C/AL code.

These routines does just that, but they can't be 100% accurate. This is caused by BLOB-fields in objects, as they are stored in a compressed form (by using a pkzip algorithm and removing 0's and trailing blanks). Hence there is a difference in the used (KB) figures according to the Database - Information form.

fctGetDbUsage() : Decimal
lrecTableInfo.FIND('-');
REPEAT
  ldecDbUsed := ldecDbUsed + lrecTableInfo."Size (KB)";
UNTIL lrecTableInfo.NEXT = 0;

lrecObject.FIND('-');
REPEAT
  ldecDbUsed := ldecDbUsed + (lrecObject."BLOB Size" / 1024);
UNTIL lrecObject.NEXT = 0;

EXIT(ldecDbUsed);

fctGetDbSize() : Decimal
lrecDbFile.FIND('-');
REPEAT
  ldecDbSize := ldecDbSize + lrecDbFile."Size (KB)";
UNTIL lrecDbFile.NEXT = 0;
EXIT(ldecDbSize);

fctGetDbName() : Text[250]
lrecDbFile.FIND('-');
EXIT(lrecDbFile."File Name");
Download code

Screenshots