Hi Friends,
In X++, how do you get a record count in table, I don't want to use while loop.
Thanks,
River
*This post is locked for comments
Thank you very much, Sergei & Anton.
Its all clear now, and I wish I had it clarified from the online documentation as you did!
If you can suggest a better and detailed X++/API documentation or literature (books), preferably with detailed examples as above, please do.
In addition to Sergeis answer, the actual count of the number of records will be returned in the field of the table buffer specified in the "count()". You could use another field but usually everyone just uses the RecId field because every table has a RecId field of course. The count works on Int64, real, string fields and possibly others but I have not tested them all.
CustTable custTable; select count(RecId) from custTable; info(strFmt('custTable.RecId: %1', custTable.RecId)); select count(BankCustPaymIdTable) from custTable; info(strFmt('custTable.BankCustPaymIdTable: %1', custTable.BankCustPaymIdTable)); select count(CreditMax) from custTable; info(strFmt('custTable.CreditMax: %1', custTable.CreditMax)); select count(AccountNum) from custTable; info(strFmt('custTable.AccountNum: %1', custTable.AccountNum));
Hi,
1. RecId is the actual field name, kernel field which can be found in any table. It's the unique record id.
2. It doesn't matter where to use this statement, "from tableName" part should be in any case.
Hi,
2 question regarding the solution provided: select count(RecId) from AssetTable;
Thanks in advance,
Thanks a lot, Guys.
Ganriver, can you please mark these answers as verified? So that future forum readers can see that this is the correct answer to the question. Thanks!
Use Count() on RecId field on the table as suggested by Rick.
You can also check it from your development workspace under Tools > Number of records form. It will show you total number of records not only in tables but in views, tableMaps etc. This is nice and easy way to get total count of records without writting any custom code.
Select a count on the recId. For example:
AssetTable assetTable;
select count(RecId) from AssetTable;
info(strFmt("AssetTable has %1 records.", AssetTable.RecId));
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156