Collection Classes

Today I will demonstrate you that how to use various collection classes in AX 2012.

All below codes needs to write in Job
Array


Static void Array_example(Args _args)

{
Int I;
Array arr=new Array(Types::String);
arr.value(1,”ABC”);
arr.value(2,”ABCD”);
arr.value(3,”ABCDE”);
for(i=1;i<=arr.lastindex();i++)
{
Info(strfmt(“Value is: %1”,arr.value(i)));
}
}



List
Static void List_example(Args _args)
{
List l=new List (Types::Integer);
ListEnumerator lenum;
l.addEnd (20);
l.addEnd (24);
l.addStart (30);
l.addStart (25);
lenum= l.getEnumerator();
lenum.reset();
While (lenum.movenext())
{
Info (strfmt(“Value is: %1”,lenum.current()));
}


Map
Static void Map_example(Args _args)
{
Map m=new Map (Types::String,Types::Integer);
MapEnumerator menum;
m.insert(“Vlaue1”, 20);
m.insert(“Vlaue2”, 30);
m.insert(“Vlaue3”, 60);
menum= m.getEnumerator();
While (menum.movenext())
{
Info (strfmt(“Value is: %1 || Key is: %2 ”,menum.currentValue(),menum.currentKey()));
}
}

Set
Static void Set_example(Args _args)
{
Set s=new Map (Types::Integer);
SetEnumerator senum;
s.add( 20);
s.add( 25);
s.add( 60);
senum= s.getEnumerator();
While (senum.movenext())
{
Info (strfmt(“Value is: %1 “,senum.current()));
}
}

Struct
Static void Struct_example(Args _args)
{
Int i;
Struct s=new Struct ();
s.add(“Name”,”ABC”);
s.add( “Age”, 34);
s.add( “Salary”,23000.00);
for(i=1;i<=s.fields();i++)
{
Info (strfmt(“Field Type: %1 || Field Name: %2 || Value is: %3“,s.fieldType(i),s.fieldName(i),s.value(s.fieldName(i))));
}
}

RecordInsertList 

Static void RecordInsertList_example(Args _args) 
{
RecordInsertList recordins;
CustTable cust;
recordins=new RecordInsertList(tablenum(CustTable));
cust.AccountNum=”11234”;
cust.CustGroup=”80”;
recordins.add(cust);
recordins.insertDatabase();
}

Below code needs to write in class and needs to set class “RunOn” Property to “Server”  because RecordSortedList only execute server side.


Class recordsortedlist_example
{
}
Private static void insertrecord_ex() 
{
RecordSortedList recordsort;
CustTable cust;
recordsort=new RecordSortedList(tablenum(CustTable));
cust.AccountNum=”11234”;
cust.CustGroup=”80”;
recordsort.ins (cust);

custe.clear();
custe.AccountNum = "456";
custe.CustGroup = "DOM";
cust.Currency = "USD";
recordSortedList.ins(cust);

cust.clear(); 
cust.AccountNum ="789";
cust.CustGroup ="INT";
cust.Currency ="USD";
recordSortedList.ins(cust);
recordsort.insertDatabase();
}
Public static void main (Args _args)
{
recordsortedlist_example::insertrecord_ex ();
}

Comments