See Also: Get_Attribute, Set_Attribute
The sort direction of the index segment.
Index segment
All Drivers
Enumeration list, permanent
Read / Write
DF_ASCENDING, DF_DESCENDING
If DF_INDEX_SEGMENT_DIRECTION is set to DF_DESCENDING, the index segment will rank from high to low rather than the default low to high. Individual segments (columns) of an index can be designated as descending or ascending. Index segments designated descending can be very useful, but can impose certain requirements on programming. For example, when a find gt (greater than) function is executed on an index containing descending segments, the gt operates as an lt (less than).
For permanent indexes (DF_INDEX_SQL_TYPE = DF_INDEX_SERVER, DF_INDEX_CLIENT, DF_INDEX_SERVER_ONLY), this attribute can only be set inside a Structure_Start ... Structure_End operation.
For temporary indexes (DF_INDEX_SQL_TYPE = DF_INDEX_TEMPORARY) this attribute can only be set outside a Structure_Start ... Structure_End operation.
The value of this attribute may be stored in the intermediate file under the keyword Index_Segment_Direction.
Procedure ShowIndices Handle hTable
Integer iLastIndex iIndex iNumSegments iSegment iColumn iCase iDirection
String sColumn sIndex
Get_Attribute DF_FILE_LAST_INDEX_NUMBER Of hTable To iLastIndex
For iIndex From 1 To iLastIndex
Get_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To iNumSegments
If (iNumSegments > 0) Begin
Move "" To sIndex
For iSegment From 1 To iNumSegments
Get_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex iSegment To iColumn
Get_Attribute DF_FIELD_NAME Of hTable iColumn To sColumn
Get_Attribute DF_INDEX_SEGMENT_CASE Of hTable iIndex iSegment To iCase
If (iCase = DF_CASE_IGNORED) ;
Move (sColumn * "uppercased") To sColumn
Get_Attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex iSegment To iDirection
If (iDirection = DF_DESCENDING) ;
Move (sColumn * "descending") To sColumn
If (iSegment > 1) ;
Move (sIndex + ",") To sIndex
Move (sIndex * sColumn) To sIndex
Loop
Showln " Index number: " iIndex " (" sIndex ")"
End
Loop
If (iLastIndex = 0) ;
Showln " NO index defined."
End_Procedure
The sample procedure above shows all segments of all indices of a table. If a segment is “uppercased” and/or descending, this is added to the segment description.
Procedure FillIndexForFindFirst Handle hTable Integer iIndex Integer iFindDirection
Integer iNumSegments iSegment iColumn iExtreme iSegmentDirection
If (iFindDirection = EQ) ;
Procedure_Return
Get_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To iNumSegments
If (iNumSegments > 0) Begin
For iSegment From 1 To iNumSegments
Get_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex iSegment To iColumn
Get_Attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex iSegment To iSegmentDirection
If (iSegmentDirection = DF_ASCENDING) Begin
If (iFindDirection = GT Or iFindDirection = GE) ;
Move DF_LOW To iExtreme
Else ;
Move DF_HIGH To iExtreme
End
Else Begin
If (iFindDirection = GT Or iFindDirection = GE) ;
Move DF_HIGH To iExtreme
Else ;
Move DF_LOW To iExtreme
End
Fill_Field hTable iColumn With iExtreme
Loop
End
End_Procedure
The sample procedure above fills the segments of a given index for an upcoming find operation. It looks at the segment direction and the intended find operation to determine if it should place the maximum or minimum value in the segment column.
Procedure CreateTable
Handle hTable hoWorkspace
Integer iColumn iIndex
String sPath sOrigFolder
//*** Make sure table comes in first folder of datapath by making that folder current
Get phoWorkspace Of ghoApplication To hoWorkspace
Get psDataPath Of hoWorkspace To sPath
Get PathAtIndex Of hoWorkspace sPath 1 To sPath
Get_Current_Directory To sOrigFolder
Set_Directory sPath
//*** Create physical table contacts
Move 0 To hTable
Structure_Start hTable "DATAFLEX"
Set_Attribute DF_FILE_PHYSICAL_NAME Of hTable To "Contact"
Set_Attribute DF_FILE_MAX_RECORDS Of hTable To 150000
Create_Field hTable At iColumn
Set_Attribute DF_FIELD_NAME Of hTable iColumn To "Customer_Number"
Set_Attribute DF_FIELD_TYPE Of hTable iColumn To DF_BCD
Set_Attribute DF_FIELD_LENGTH Of hTable iColumn To 6
Move 0 To iColumn
Create_Field hTable At iColumn
Set_Attribute DF_FIELD_NAME Of hTable iColumn To "ContactDate"
Set_Attribute DF_FIELD_TYPE Of hTable iColumn To DF_DATE
Move 0 To iColumn
Create_Field hTable At iColumn
Set_Attribute DF_FIELD_NAME Of hTable iColumn To "Comment"
Set_Attribute DF_FIELD_TYPE Of hTable iColumn To DF_TEXT
Set_Attribute DF_FIELD_LENGTH Of hTable iColumn To (8 * 1024)
Move 0 To iIndex
Create_Index hTable At iIndex
Set_Attribute DF_INDEX_NUMBER_SEGMENTS Of hTable iIndex To 2
Set_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex 1 To 1
Set_Attribute DF_INDEX_SEGMENT_FIELD Of hTable iIndex 2 To 2
Set_Attribute DF_INDEX_SEGMENT_DIRECTION Of hTable iIndex 2 To DF_DESCENDING
Structure_End hTable
Set_Directory sOrigFolder
//*** Add to filelist and generate fd
Move 0 To hTable
Get_Attribute DF_FILE_NEXT_EMPTY Of hTable To hTable
If (hTable > 0) Begin
Set_Attribute DF_FILE_ROOT_NAME Of hTable To "Contact"
Set_Attribute DF_FILE_DISPLAY_NAME Of hTable To "Contact sample table"
Set_Attribute DF_FILE_LOGICAL_NAME Of hTable To "Contact"
Open hTable
Get psDDSRCPath Of hoWorkspace To sPath
Get PathAtIndex Of hoWorkspace sPath 1 To sPath
If (Right(sPath, 1) <> Sysconf(Sysconf_Dir_Separator)) ;
Move (sPath - Sysconf(Sysconf_Dir_Separator)) To sPath
Move (sPath - "Contact.fd") To sPath
Output_Aux_File DF_AUX_FILE_FD For hTable To sPath
Close hTable
End
End_Procedure
In this sample a new table called Contact is created. It has the columns: Customer_Number of type Numeric(6), ContactDate of type Date and Comment of type Text(8192) with an index on Customer_Number and ContactDate (descending). The table will be created in the first folder of the data path of the current workspace; an fd file will be created in the first folder of the DDSrc path of the current workspace.