AMT Help Files

Sort Interface

The Sort object (ISort) is returned by the CreateSort function of the ComScript connection. Through this object, the functionality of the AMT-COBOL Sort utility can be used in programs that are written in any COM supporting development environment.

The following functionality is provided:

Properties



Name Type  Access Description
CopyOption Boolean Read/Write Sets the SORT copy option (copy only, no sort).
DeleteDuplicateRecords Boolean Read/Write Delete duplicate records in the sorted file. 
ErrorCode Integer Readonly  The error code of the Sort object. Zero means there is no error. 
ErrorDescription String Readonly The error description of the Sort object. When no error occurred Ok will be returned.
FileRecordEnding AmtFileRecordEnding Read/Write The file ending used by the file. For the allowed options see the AmtFileRecordEnding table below.
SortLinkSize Integer Read/Write Sets the SORT link size. 
SortNumRec Integer Read/Write Specifies the number of records to process, should be set between 1 and 34,359,738,367.
WorkFolder String Read/Write Set the temporary work folder name. 
YYDateKey Boolean Read/Write Set to true if the key is a date without century. 

Functions


Function Name Return type  Parameters Description 
Name Type 
AddAcceptKey Void
  Adds an ACCEPT parameter to the sort command.
StartPos Integer The starting position.
Length Integer  The number of characters to be tested.
Type String  The Kind of data the field contains. Can be ASC, CAS or DEC.
Operation String  Test operation. Can be =, >, >=, <, <= or <>.
Value String  Contains the test data to be compared. 
LogicalOp String  Logical operation. Can be AND or OR. 
AddFileIn Void  FileName String  The path and name of the file to sort. More than one file may be added. They will be concatenated before sorting.
AddIncludeClosingBracket Void ---
Adds a closing bracket to the list of include keys for nested conditions.
AddIncludeKey Void     Adds an INCLUDE key to the sort command. When the condition matches, the record will be added to output.
StartPos Integer The start position of the key.
Length Integer The number of characters to be tested.
Type String The kind of data that the field contains. Can be CH (character), BI (binary), PD (packed decimal), AQ (character with alternate collating sequence).
Operation String Test operation. Can be =, >, >=, <, <= or <>.
Value String Contains the test data to be compared.
LogicalOp String Logical operation. Can be AND or OR.
AddIncludeLogicalOperator Void LogicalOp String Adds logical operator AND or OR to nested keys, the operator between closing and opening bracket.
AddIncludeOpeningBracket Void ---
Adds an opening bracket to the list of include keys for nested conditions.
AddKey Void  StartPos Integer Add a key to sort on. Multiple keys may be added, they will be evaluated in the order they are added.
 
The description of the parameters together with the allowed values can be found in the table below.
NumberOfChars Integer
Type String
SubType String
SortingOrder String
AddOmitClosingBracket Void ---   Adds a closing bracket to the list of omit keys for nested conditions.
AddOmitKey Void

Adds an OMIT key to the sort command. When the condition matches, the record will be added to output.
StartPos  Integer  The start position of the key.
Length Integer The number of characters to be tested. 
Type String The kind of data that the field contains. Can be CH (character), BI (binary), PD (packed decimal), AQ (character with alternate collating sequence).
Operation String Test operation. Can be =, >, >=, <, <= or <>.
Value String Contains the test data to be compared.
LogicalOp String Logical operation. Can be AND or OR.
AddOmitLogicalOperator Void LogicalOp String Adds logical operator AND or OR to nested keys, the operator between closing and opening bracket.
AddOmitOpeningBracket Void ---
Adds an opening bracket to the list of omit keys for nested conditions.
AddOutrecField Void

Adds a field to be added from the input record in the output record.
StartPos Integer Start position of the field in the input record.
Length Integer Length of the field.
SeparationField String Separation characters to be put behind the field to separate it from the next field. Can be <n>X or <n>Z. <n>X adds n spaces to the output record, <n>Z adds n binary zeroes to the output record.
Example: "2X"
   
AddSortSelect Void

Adds an SELECT parameter to the sort command. 
StartPos  Integer  The start position 
Length Integer The number of characters to be selected. 
OutputPos Integer The output position of the selection. 
   
AddSumField Void     Add a field that gets its values summed for all duplicate records into 1 record. Only 1 record (in AMT the first record) will be written with the summed values. Other duplicate records are not written to the output file.
StartPos Integer Start position of the key.
Length Integer The number of characters to be tested.
Type String The kind of data that the field contains. The allowed values can be found in the Type parameter in table below.
  
Init Void  ---
Initialize the Sort object (clear all settings of a previous sort)
SetFileOut Void  FileName String The path and name of the file to write the sorted output to.
SetLinkSize Void Size Integer Sets link size, which affects how much of any variable length record is significant to the sort operation being performed.
SetNumericCoding Void  Coding String

Defines how Signed values are stored when using overpunch. There are four options:

  • LION (default)
  • ANSI
  • EBCDIC
  • UNIX

If you are not sure which coding must be used, then this can be checked by the setting of the application option "Numeric Sign Encoding" in AMT-COBOL Developer (see the AMT-COBOL Developing manual).

Attention: The NUMERIC-CODING setting in ComScript Sort should always be changed according to the setting in AMT-COBOL Developer Studio, and not the other way around. The setting in AMT-COBOL Developer Studio should never be changed since this would lead to unpredictable behavior.

SetRecSize Void Size Integer The size of the records to use for the output file. Longer records will be truncated and shorter records will be extended to this size.
SetSortSequence  Void  SortSequence  String  With this function the sort order of characters in a text file can be changed. Normal (default) is digits before capitals before lowercase letters. 

By using the SortSequence string "a-z,0-9,A-Z" the sort order will be lowercase before digits before capitals. Individual characters can be given the same place in the order by using the equal sign.

For example "a=A,b-z,B-Z,0-9" will put lowercase and capital A at front followed by the lowercase letters the capitals and the digits.

Note: the sort sequence is reversed when in the AddKey function the sort order is set to descending.
SetUnicode Void Unicode Boolean Sets Unicode or ASCII. Set to true for Unicode. 
SortFile Void  ---
Execute the sort.
SortFileFromScript Void ---
Execute the Sort from a script. This implements accept and select functions.

AddKey Parameters


Parameter Allowed Values Description
AscDsc ASC
DSC
Sort ascending or descending.
NumOfChar any integer The length of the field to use as key.
StartPos any integer  The starting position of the field to use as key in the record.
SubType L
T
l
t
Subtype for signed numerics. L is leading separate, T trailing separate, l leading overpunch and t trailing overpunch.
Type
A  1
N  2
S  7
O  0
E  9
=

The type of the field. Some types are restricted by the application origin.

A is Alpha, N is Numeric, S is Signed, O is Numeric computational, E is Financial computational,

1 is Numeric bit9 (OS2200 only), 2 is  Financial bit9 (OS2200 only), 7 is Numeric binary (IBM & Microfocus),

0 is Financial binary (IBM & Microfocus), 9 is Numeric comp 9 (OS2200 only), = is Financial comp 9 (OS2200 only)

 

AmtFileRecordEnding

Value File record Ending
0 Default
1 CR/LF
2 CR
3 LF
4 None

 

Example


PowerShell


#See ComScript Connection Interface
... 
$ComScr.Connect()

#Create an Object of the Sort Interface

$Sort = $ComScr.CreateSort()


$Sort
.AddFileIn('D:\Data\filetosort.txt')

$Sort.AddKey(1,3,'N',' ','ASC')

$Sort.SetFileOut('D:\Data\fileSorted.txt')

$Sort.SetRecSize(20)

$Sort.Sortfile()


#Check if an error occurred and log if so.

if ($Sort.ErrorCode -ne 0) {

    [void]$Msg.AddMsgInformation("ErrorCode is: $($Sort.ErrorCode)")

    [void]$Msg.AddMsgInformation("ErrorDescription is: $($Sort.ErrorDescription)")

} else {

    [void]$Msg.AddMsgInformation("Sorting succeeded.")

}


# Finally release the variables and clean up the session.
$ComScr.Dispose()