AX Query에서 사용하는 like operator

Posted by Alvin You
2013. 11. 13. 14:58 Dynamics AX

AX Engine에서 사용되는 Query 작성시 사용할 수 있는 Like 연산자 사용방법에 대한 예제입니다.

 

static void likeOperator(Args _args)
{
    DirPartyTable dirPartyTable;
    ;
 
    select dirPartyTable where dirPartyTable.Name like("*Pusan*");// match with Pusan
    info(dirPartyTable.Name);   
    select dirPartyTable where dirPartyTable.Name like("*Pusan");// end with with Pusan
    info(dirPartyTable.Name);   
    select dirPartyTable where dirPartyTable.Name like("Pusan*");// start with Pusan
    info(dirPartyTable.Name);
}

Import data from Excel file to AX using X++ in AX 2012

Posted by Alvin You
2013. 10. 23. 00:19 Dynamics AX

Excel 파일을 Import 받아 AX에 구성되어 있는 Standard or Developed Table에 값을 집어 넣는 로직입니다. Delphi나 VB, Powerbuilder 개발을 해 보셨던 분들에겐 익숙한 코딩일 듯 싶습니다.

 

static void ReqAmount(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    Name name;
    FileName filename;
    ReqAmount reqAmount;
    int row;
    str _reqOrderNo;
    int _reqAmount;
    ;
 
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    filename = "D:\\ReqAmount.xlsx";
   
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
 
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1); //첫번째 Sheet
    cells = worksheet.cells();
    do
    {
        row++;
        _reqOrderNo = any2str(cells.item(row, 1).value().toString());
        _reqAmount = cells.item(row, 2).value().int();

        reqAmount.ReqOrderNo = _reqOrderNo;
        reqAmount.ReqAmount = _reqAmount;
        reqAmount.insert();

        type = cells.item(row+1, 1).value().variantType();
    } while (type != COMVariantType::VT_EMPTY);
   
    application.quit();
}

'Dynamics AX' 카테고리의 다른 글

Dynamics AX Useful Links  (0) 2013.10.25
Minimizing risk, maximizing returns  (0) 2013.10.25
RecId란?  (0) 2013.10.20
훌륭한 Dynamics AX Project Manager에 필요한 자질  (0) 2013.10.16
SAP vs Oracle vs AX  (0) 2013.10.13

RecId란?

Posted by Alvin You
2013. 10. 20. 22:44 Dynamics AX
AX 개발자에겐 선배 개발자들이 말하는 RecId라는 말을 그냥 개발자에겐 꼭 알아야 하는 고유명사처럼 많이들 들어봤을겁니다. 하지만 정작 우리가 RecId에 대해 명확히 알고 사용을 하는지 한 번 되새겨 볼 필요가 있어서 RecID 원문 글을 올립니다. 
What is RecId?
The RecId is a unique field in every table, used as an identifier. Every row in the system can be guaranteed (in theory) to have a unique RecId. RecIds can be negative, and their value can change due import/export operations. Due to this, it is not a good idea to use RecIds as foreign key references to other tables.

What is the difference between a RecId and an Id?

The kernel generates the RecId while the Id is generated by the application.

'Dynamics AX' 카테고리의 다른 글

Minimizing risk, maximizing returns  (0) 2013.10.25
Import data from Excel file to AX using X++ in AX 2012  (0) 2013.10.23
훌륭한 Dynamics AX Project Manager에 필요한 자질  (0) 2013.10.16
SAP vs Oracle vs AX  (0) 2013.10.13
AX VS SAP?  (0) 2013.10.12

Adding a calculated field to a grid

Posted by Alvin You
2013. 10. 8. 00:16 Dynamics AX

Enterprise Portal 개발을 진행하면서, AX Grid에 어떻게 하면 Calculated Field를 표시해 줄 수 있을까를 고민하면서 찾은 방법입니다.

첫번째 사용한 방법은 AX 2012에서 새롭게 소개된 View 의 Computed Field를 추가해서 사용하는 방법을 이용했지만, 다른 문제가 있음을 발견 후 다시 고민고민을 하다가 결국 오늘 두번째 방법을 찾았답니다.

두번째 방법은 이미 X++ 개발을 하셨던 분들에게는 쉬운 방법일 수 있겠지만, 저처럼 C#을 접하고 X++을 개발하는 개발자에게는 조금은 생소한 방법이기 때문에 다른 분들과의 공유를 위해서 이곳에 기록을 남겨 봅니다.

이미 만들어져 있는 VendInvoiceTrans 테이블의 display method인 lineAmountInclTax를 Grid상에 표시하는 방법입니다.

1) VendInvoiceTrans 테이블의 lineAmountInclTax display method

image

2) Grid –> New Control –> RealEdit Type의 칼럼 추가

image

3) DataSource, DataMethod 를 각각 아래와 같이 변경

image

4) Enterprise Portal 상에서 추가된 칼럼 정보 확인

A) Grid에서의 칼럼 순서 표기

image

B)앞의 Amount는 새롭게 추가된 lineAmountInclTax 칼럼이며, 뒤의 Amount는 기존의 LineAmount칼럼임

image

Comparision between X++ and C#

Posted by Alvin You
2013. 10. 5. 01:38 Dynamics AX

AX의 개발 언어인 X++과 MS의 대표적인 개발언어인 C#의 비교자료입니다.

같은 Object-Oriented Programming 언어이지만, OOP의 개념을 어떻게 풀어 넣었느냐에 따라 개발 방법이나 사용 방법은 틀려질꺼라 생각됩니다.

Axapta가 AX 2012 버젼이 되면서 MS의 Backoffice 서버 제품군(Sharepoint Server, Project Server)과의 통합에 많은 주력을 한 듯 보입니다.

Enterprise Portal과 Project Module의 추가를 보면 많은 신경을 쓴 듯 보입니다. 아직 국내에는 활발하게 해당 모듈을 이용한 프로젝트가 많지는 않지만, 향후에는 많은 프로젝트들이 생기길 기대해 봅니다.

Abaper들과 어깨를 견주길 바라며, Xppler 여러분 화이팅입니다.

X++
C#
abstract
class
The modifiers public and private are ignored on class declarations.
There is no concept of a namespace grouping of classes. There are no dots (.) in any class names.
The modifiers public and private can be used to modify class declarations. C# also has the keyword internal, which relates to how classes are grouped together in assembly files.
extends
A class declaration can inherit from another class by using the extends keyword.
A colon (:) is used where the key words extends and implements are used in X++.
final
A final method cannot be overridden in a derived class. A final class cannot be extended.
The keyword sealed on a class means the same thing that final means on an X++ class.
implements
A class declaration can implement an interface by using the implements keyword.
(See extends.)
interface
An interface can specify methods that the class must implement.
An interface can specify methods that the class must implement.
new
The new keyword is used to allocate a new instance of a class. Then the constructor is automatically called.
Each class has exactly one constructor, and the constructor is named new. You can decide what parameters the constructor should input.
The new keyword is used to create a new instance of a class. Then the constructor is automatically called.
Constructor methods themselves are not named new; they have the same name as the class.
null
private and protected
The private and protected keywords can be used to modify the declaration of a class member.
The private and protected keywords can be used to modify the declaration of a class member.
public
A method that is not modified with public, protected, or privatehas the default access level of public.
A method that is not modified with public, protected, or private has the default access level of private.
static
A method can be static, but a field cannot.
Both methods and fields can be static.
super
The super keyword is used in a derived class to access the same method on its base class.
void method2()
{
;
// Call method2 method
// on the base class.
super();
}
The base keyword is used in a derived class to access various methods in its base class.
void method2()
{
// Call methods on
// the base class.
base.method2();
base.method3();
}
this
For a call from one instance method to another on the same object, a qualifier for the called method is required. The keyword this is available as a qualifier for the current object.
For a call from one instance method to another on the same object, a qualifier for the called method is not required. However, the this keyword is available as a qualifier for the current object. In practice, the keyword this can be helpful by displaying IntelliSense information.
finalize
The Object class contains the finalize method. The finalize method is not final, and it can be overridden.
The finalize method appears to resemble the System.Object.Finalize method in C#, but in X++ the finalize method has no special meaning of any kind.
An object is automatically removed from memory when the last reference to the object stops referencing the object. For example, this can happen when the last reference goes out of scope or is assigned another object to reference.
The methods Finalize and Dispose are common on some types of classes.
The garbage collector calls the Finalize and Dispose methods when it destroys and object.
main
Classes that are invoked from a menu have their main method called by the system.
Classes that are invoked from a command line console have their Main method called by the system.

Item의 Default Order Settings 일괄 생성

Posted by Alvin You
2013. 9. 24. 22:52 Dynamics AX

아래 Job을 통해서 Default Order Settings(Inventory, Purchase Order, Sales Order)를 생성 시킬 수 있습니다.

static void Set_DefaultOrderSettings(Args _args)
{
    InventTable inventTable;
    InventItemInventSetup invent;
    InventItemPurchSetup purch;
    InventItemSalesSetup sales;
    ;
    delete_from invent;
    delete_from purch;
    delete_from sales;
    while select inventTable
    {
        if(!InventItemPurchSetup::findDefault(inventTable.ItemId))
        {
            InventItemPurchSetup::insertDefault(inventTable.ItemId);
        }
        if(!InventItemInventSetup::findDefault(inventTable.ItemId))
        {
            InventItemInventSetup::insertDefault(inventTable.ItemId);
        }
        if(!InventItemSalesSetup::findDefault(inventTable.ItemId))
        {
            InventItemSalesSetup::insertDefault(inventTable.ItemId);
        }
    }
}

Create Dynamic Table in the X++

Posted by Alvin You
2013. 9. 24. 00:08 Dynamics AX/Development

AX상에서 테이블 생성을 Manual로 일일이 작업하는 동료를 보며, SQL처럼 스크립트 같은걸 만들어 놓고 동일 작업이 필요할 경우 작업할 수 있는 방법은 없을지 찾다가 발견한 솔루션입니다.

이 내용을 통해서, 많은 X++ Developer들의 개발 생산성이 향상되길 빌며…

static void newTableCreate(Args _args)
{
TreeNode treeNode;
AOTTableFieldList fieldList;
#AOT
;
treeNode = TreeNode::findNode(#TablesPath);

treeNode.AOTadd("KOR_SalesTable");
SqlDataDictionary::synchronize();

fieldList = treeNode.AOTfindChild('KOR_Table').AOTfindChild('fields');
fieldList.addString('KOR_Field1');
fieldList.addString('KOR_Field2);

SqlDataDictionary::synchronize();
print "Table Created";
pause;
}

Query Object의 내용을 문자열로 Export

Posted by Alvin You
2013. 9. 24. 00:07 Dynamics AX/Development

AX 개발시에 Query Object를 만든 후 해당 내용을 다시 문자열로 Export 받아 코드 레벨의 Query Object 생성시 재사용할 수 있는 방법은 없을까 방법을 찾다가 아래와 같은 방법이 있음을 알아냈다.

◈ Query Object

image

◈위 내용을 문자열로 Export 받은 내용

Query Proc_PurchSummary object 2320c548: SELECT * FROM VendPurchOrderJour(VendPurchOrderJour_1) JOIN * FROM PurchLineAllVersions(PurchLineAllVersions_1) ON VendPurchOrderJour.RecId = PurchLineAllVersions.PurchTableVersionRecId JOIN * FROM VendTable(VendTable_1) ON PurchLineAllVersions.VendAccount = VendTable.AccountNum JOIN * FROM DirPartyTable(DirPartyTable_1) ON VendTable.Party = DirPartyTable.RecId JOIN * FROM InventDim(InventDim_1) ON PurchLineAllVersions.InventDimId = InventDim.inventDimId JOIN * FROM InventLocation(InventLocation_1) ON InventDim.InventLocationId = InventLocation.InventLocationId JOIN * FROM PurchTable(PurchTable_1) ON VendPurchOrderJour.PurchId = PurchTable.PurchId AND ((DocumentState=40)) JOIN * FROM HcmWorker(HcmWorker_1) ON PurchTable.WorkerPurchPlacer = HcmWorker.RecId JOIN * FROM DirPerson(DirPerson_1) ON HcmWorker.Person = DirPerson.RecId

◈Export 받는 방법

static void Job1(Args _args) // X++ job.
{
Query q = new Query(queryStr(Proc_PurchSummary));
QueryRun qr = new QueryRun(q);
info(q.toString());

}