Posts Tagged ‘DictTable’
A few things you should know about temporary tables
- You can set the property ‘temporary’ in the AOT to yes –> this table is always temporary

- You can declare a buffer of a table and call the method setTemp() or setTempData(), from that moment on the buffer contains temporary data.
CustTable custTable; ; custTable.setTmp(); if (custTable.isTmp()) { // Do something with your temporary table }
- When you declare a buffer of a record of temporary table type, the table does not contain any values.
- Memmory and filespace aren’t allocated for a temporary table till the first record is inserted. This means that you have to watch out for client/server problems.
When the first record is inserted in a buffer on the client tier, the memory is allocated there. All actions (insert / update / delete) to this buffer will run trough that tier, so try to reduce round-trips and improve your performance. - When you declare 2 different buffers of the same temporary table, they will both have a life of their own. To share the date between the tables use the setTmpData method.
for example: tmpCommonBuffer1.setTmpData(tmpCommonBuffer2); - You can’t (normally) set up logging on temporary tables.
- Use the method isTmp() to know if a record is temporary or not (true –> temporary, false –> phisical)
My opinion: Temporary tables are very useful and can help you to easily manipulate data you don’t need store permanently, but watch out where and how you use them.
List of mandatory fields on a table
When you want a list of all the mandatory field on table X, yould check all the properties on the table fields, or you could be lazy and write a small job that does the trick for you. Just replace TableId with your tablenum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | static void CheckMandatoryFieldsOnTable(Args _args) { DictTable dictTable; DictField dictField; int i; TableId tableId = tablenum(custtable); ; dictTable = new DictTable(tableId); for (i=1 ; i<=dictTable.fieldCnt() ; i++) { dictField = new DictField(tableId, dictTable.fieldCnt2Id(i)); if (dictField.mandatory()) { info(dictField.name()); } } } |
Moving DB-objects to other layers … without losing data
Most of us have already been confronted with the problem of tables being inserted in the wrong layer, and when they already contain data it is very difficult to transfer these objects to the correct layer without losing data.
I found the following article on Axaptapedia that helps you with this issue: http://www.axaptapedia.com/Move_DB_objects_to_another_layer
Select a record from a table when you only have the tableId
The following code can provide you a generic way to update a table when you only have the tableId.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public Common findRecord(TableId _tableId, RecId _recId, Boolean _forUpdate = false) { Common common; DictTable dictTable; ; dictTable = new DictTable(_tableId); common = dictTable.makeRecord(); common.selectForUpdate(_forUpdate); select common where common.RecId == _recId; return common; } |
If you want, you can even update fields in this common record. You can Access/edit these fields by using their Name or FieldNum. The method below will update a specific field in a table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public void updateValue(TableId _tableId, RecId _recId, str _field, AnyType _value) { Common common; Int fieldId; ; ttsbegin; common = findRecord(_tableId, _recId, true); fieldId = fieldname2id(_tableId,_field); if (fieldId && _value) { common.(fieldId) = _value; common.update(); } ttscommit; } |

