Describing a Sort Object: SORTOBJ

You can define sort phrases and attributes in a Master File and reference them by name in a request against the Master File. The entire text of the sort object is substituted at the point in the TABLE where the sort object is referenced. The sort phrases in the sort object are not verified prior to this substitution. The only verification is that there is a sort object name and an equal sign in the Master File SORTOBJ record.



Reference: Usage Notes for Sort Objects in a Master File

  • The sort object declaration can appear anywhere after the first SEGNAME/SEGMENT record. However, it must appear after all fields mentioned by it in the Master File, including virtual fields.
  • A sort object can use both Master File and local virtual fields.
  • Unlimited sort object declarations may appear in a Master File, but the number referenced by a TABLE request cannot result in more than the maximum number of sort phrases in the request.
  • The sort object declaration can be followed by optional attributes.
  • If a sort object has the same name as a field, the sort object will be used when referenced in a request.


Syntax: How to Declare a Sort Object in a Master File

FILE= ...
SEG= ...
FIELD= ...
SORTOBJ sortname = {BY|ACROSS} sortfield1 [attributes]
  [{BY|ACROSS} sortfield2 ... ]; 
  [,DESC[CRIPTION]='desc',] 
  [DESC_ln='descln', ... ,]$ 

where:

sortname

Is a name for the sort object.

sortfield1, sortfield2 ..

Are fields from the Master File or local DEFINE fields that will be used to sort the report output.

attributes

Are any valid sort attributes.

;

Is required syntax for delimiting the end of the sort object expression.

DESC[CRIPTION]='desc'

Is a description for the sort object in the default language.

DESC_ln='descln'

Is a description for the sort object in the language specified by the language code ln.



Syntax: How to Reference a Sort Object in a Request

TABLE FILE ...
   .
   .
   .
BY sortname   .
   .
   .
END

where:

sortname

Is the sort object to be inserted into the request.



Example: Declaring and Referencing a Sort Object

The following sort object for the GGSALES Master File is named CRSORT. It defines two sort phrases:

  • BY the REGION field, with a SKIP-LINE attribute.
  • ACROSS the CATEGORY field.
SORTOBJ CRSORT = ACROSS CATEGORY BY REGION SKIP-LINE ; ,$

The following request references the CRSORT sort object:

TABLE FILE GGSALES      
SUM DOLLARS             
BY CRSORT               
ON TABLE SET PAGE NOPAGE
END

The output is:

                      Category                                  
Region       Coffee        Food          Gifts
------------------------------------------------
Midwest      4178513       4404483       2931349
Northeast    4201057       4445197       2848289
Southeast    4435134       4308731       3037420
West         4493483       4204333       2977092

WebFOCUS