Adding a role through Code.

I have table name Role which has three field roles,enabled and label. it contains roles in it. if a role exist in the table and has its enabled field checked, and that role doesnot exist in AOT,I need to add it in AOT\Roles. How to loop through the table so that I can add the role in AOT?

Do you mean security roles (AOT > Security > Roles) in AX 2012?

yes.

You can do it by inserting a record to SecurityRole table. For example:

SecurityRole securityRole;
securityRole.initValue();
securityRole.AotName = "MyRole";
securityRole.Name = "My Role";
securityRole.insert();

AX already has a method to make it even simpler: SysUserManagement::createRole().