Axaptapedia is now maintained by AgileCadence For more information please click here.

Accessing record fields

From Axaptapedia
Jump to: navigation, search

The usual way[edit]

Obviously to access a field of a record, you usually just use its name:


Example: <xpp> CustTable ct;

select firstonly ct; info(ct.CustAccount); </xpp>

The different way[edit]

But, what do you do, if you want to access the fields of a record, where you do not know the field names?

In this case you can access field values via their field ID:



<xpp> CustTable ct;

select firstonly ct; info(ct.(fieldnum(CustTable, CustAccount))); </xpp>

For example the following function outputs any record to the infolog. This is achieved by iterating over the DictTable object of the passed record. The DictTable will give us the field Id's, which in turn are used to access the field value.

<xpp> static void Info(common _common, boolean _includeSys = false) {

   SysDictTable   dictTable;
   SysDictField   dictField;
   int            fieldIdx;
   fieldid        commonFieldId;
   dictTable = new SysDictTable(_common.TableId);
   for(fieldIdx=1; fieldIdx <= dictTable.fieldCnt(); fieldIdx++)
     commonFieldId =  dictTable.fieldCnt2Id(fieldIdx);
     dictField = dictTable.fieldObject(commonFieldId);
     if(!dictField.isSystem() || _includeSys)
       if(dictField.baseType() == Types::Container)
         info(strfmt("%1 = <%2>", dictField.label(), dictField.baseType() ));
         info(strfmt("%1 = %2", dictField.label(), _common.(commonFieldId)));

} </xpp>

Example of accessing dimension fields. <xpp> int idx; FieldId fieldId; FieldId fieldIdExt;

CustTrans custTrans;

idx = SysDimension::Center+1;

select firstOnly custTrans

   where custTrans.Dimension[idx];

fieldId = fieldNum(CustTrans, Dimension);

fieldIdExt = fieldId2Ext(fieldId, idx);

info(custTrans.(fieldIdExt)); </xpp>