Creating Sort Specifications Programmatically

To code a SortSpecification object, create the following objects,  which are found in the  oracle.dss.selection package, as needed:

Note: All ConditionSortStep objects are evaluated before  MemberSortStep objects.  

Example: Alphabetic sorting

Sort ascending by product name. The following code creates the required ConditionSortStep.


//strProductDim is the unique identifier of the Product dimension //strStandardHier is the unique identifier of the Standard hierarchy // SortSpec sortSpec = new SortSpec(); ConditionSortStep  condSortStep1 = new ConditionSortStep (  strProductDim, strStandardHier, ConditionSortStep.ALPHABETICAL,  ConditionSortStep.ASCENDING); sortSpec.addConditionSortStep (condSortStep1);

Example: Measure-based sorting

Sort by sales, descending, for January, 2002, for regions of the world, and for the total channel. You can use a QDR in measure-based sorting to reference the desired data.

The following code creates the QDR.


//strSalesMeasure is the unique identifier for the Sales measure //strSalesMeasureDim is the unique identifier for the Sales measure dimension //strTimeDim is the unique identifier for the Time dimension //strGeogDim is the unique identifier for the Geography dimension //strChannelDim is the unique identifier for the Channel dimension // m_qdr1 = new OlapQDR (strSalesMeasureDim, strTimeDim + ":JAN2002; "   + strGeogDim + ":WORLD;" +  strChannelDim  + ":TOTALCHANNEL"); m_qdr1.addDimMemberPair (strSalesMeasureDim, strSalesMeasure);

The following code uses m_qdr1 to create a measure-based ConditionSortStep.


ConditionSortStep condSortStep2 = new ConditionSortStep (  strProductDim, strStandardHier, ConditionSortStep.MEASURE,  ConditionSortStep.DESCENDING, strSalesMeas, m_qdr1); sortSpec.addConditionSortStep (condSortStep2);

Example: Specifying a position for individual members

Move the Accounting Division members first.


Vector vAcc = new Vector (); vAcc.addElement ("ACCDIV"); MemberSortStep memberSortStep1 = new MemberSortStep (  strProductDim, new MemberStep (strProductDim, vAcc),  MemberSortStep.FIRST, null); sortSpec.addMemberSortStep (memberSortStep1);

Example: Adding a SortSpec to a selection

The following code adds a SortSpec object to an existing selection sel.

sel.setSortSpec (sortSpec);