Log In    |    Knowledge Base    |    4D Home
Tech Tip: A simple sorting routine for 4D Open for Java
PRODUCT: 4D Open for JAVA | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: May 18, 2001

The following is a simple 4D Open for Java routine to sort in an alphanumeric field and display it on the screen.

opSelection selection = process.AllRecords(table);
selection.mTableNumber = 1;
opFieldArray fieldArray = new opFieldArray(1);
fieldArray.mTargetTable = 1;

fieldArray.mFieldArray[0] = new opField(1,1);
fieldArray.mFieldArray[0].mOrdering=GREATER_THAN; // (*)Ascending order


int found = selection.mRecordsInSelection;

opDataArray dataArray[] = new opDataArray[1];
dataArray[0] = new opDataArray(found);

for(short i=0;i{

(*) For those who are still new to 4D may be confused by the meaning of the constant GREATER_THAN. In 4D, the sorting direction is determined by the greater-than (>) and the less-than (<) symbol. The same rule is applied to 4D Open for Java. If the sorting will be done in an ascending order mOrdering will be equal to GREATER_THAN or 3. If the sorting will be done in a descending order, mOrdering will be equal to "LESS_THAN" or 5.