AMT Help Files
homeAMT AdminAdvanced FunctionsComScript ModuleSort Interface

Sort Interface

The Sort object (ISort) is returned by the CreateSort function of the ComScript connection. Through this object, the functionality of the AMT 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.
DupeOption String Read/Write Duplicate option.
Allowed values are:
"LASTDUP" - remove every duplicate entry except for the last duplicate item.
"FIRSTDUP" - keep the first item and remove every duplicate entry after.
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.
NoDups Boolean Read/Write Reserved for future use.
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.
AddIfthenFindRepItem Void Adds a FINDREP (find/replace) item to the current IFTHEN block (INREC or OUTREC).
InValue String Value to find (already resolved).
OutValue String Replacement value (already resolved).
StartPos Integer Start column (1-based, inclusive). 0 = whole record.
EndPos Integer End column (1-based, inclusive). 0 = whole record.
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.
AddInrecField Void Adds a field to the input record.
AbsolutePos Integer Absolute column position of the field in the input file.
InputPos Integer The start position of the field in the input file.
InputLength Integer Length of the field in the input file.
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"
AddInrecIfthenOverlayItem Void Adds an OVERLAY item to the current INREC IFTHEN block.
OutputPos Integer Output position (1-based). -1 for continuation.
InputPos Integer Input position (1-based). -1 for literal items.
InputLength Integer Number of characters to copy. 0 for literal items.
LiteralValue String Literal string to write. Empty string for field-copy items.
AddInrecIfthenWhenCloseParen Void --- Record a closing parenthesis in the current WHEN expression. The close count is attached to the most recently added WHEN condition of the current block.
AddInrecIfthenWhenCondition Void Adds a WHEN condition to the current INREC IFTHEN block.
StartPos Integer Start position (1-based).
Length Integer Field length.
Format String The format of the field. Can be CH (character), BI (binary), PD (packed decimal).
Operation String Comparison operator:. Can be EQ, NE, GT, LT, GE, LE.
CompareValue String Value to compare against (already resolved).
LogicalOp String Logical operator to next condition: AND, OR, or empty.
AddInrecIfthenWhenInit Void --- Marks the current INREC IFTHEN block as WHEN=INIT (always applies).
AddInrecIfthenWhenLogicalOp Void LogicalOp String Sets the trailing logical operator (AND/OR) that connects the most recently added WHEN condition of the current block to the next condition.
AddInrecIfthenWhenNone Void --- Marks the current IFTHEN block as WHEN=NONE. The block applies only to records that were not selected by a preceding WHEN=(logexp) block in the same INREC/OUTREC statement.
AddInrecIfthenWhenOpenParen Void --- Record an opening parenthesis in the current WHEN expression. The pending open count is attached to the next WHEN condition added via AddInrecIfthenWhenCondition.
AddJoinKey Void Adds a JOINKEYS key field for one of the two input files.
FileId Integer 1 for SORTJNF1/F1, 2 for SORTJNF2/F2.
StartPos Integer 1-based start position of the key field in the record.
Length Integer Length of the key field.
Order String Sort order: A (ascending) or D (descending).
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 from the input file to the output record.
AbsolutePos Integer Absolute column position of the field in the input file.
InputPos Integer The start position of the field in the input file.
InputLength Integer Length of the field in the input file.
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"
AddReformatField Void Adds one segment of the REFORMAT FIELDS spec that describes how to build the joined output record from slices of the F1 and F2 records.
FileId Integer Source file: 1=F1, 2=F2, 0=filler (spaces).
StartPos Integer 1-based start position in the source record (ignored for filler).
Length Integer Number of characters to copy (or spaces to emit for filler).
AddSortSelect Void Adds a 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.
BeginInrecIfthenBlock Void --- Begins a new INREC IFTHEN block.
BeginOutrecIfthenBlock Void --- Begins a new OUTREC IFTHEN block (post-sort processing).
EndInrecIfthenBlock Void --- Finalize the current INREC IFTHEN block and add it to the list.
EndOutrecIfthenBlock Void --- Finalize the current OUTREC IFTHEN block and add it to the OUTREC list.
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.
SetIfthenBuild Void --- Marks the current IFTHEN block as a BUILD (reformat) block. BUILD rebuilds the record from an empty buffer using the item list, while OVERLAY modifies the record in place.
SetJoinType Void JoinType String Set the join type for a JOINKEYS application. Supported types:
PAIRED = inner join (default); UNPAIRED,F1 = left outer;
UNPAIRED,F2 = right outer; UNPAIRED,ONLY = unmatched only
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 Developer (see the AMT Developing manual).

Attention: The NUMERIC-CODING setting in ComScript Sort should always be changed according to the setting in AMT Developer Studio, and not the other way around. The setting in AMT 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. info 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
SortingOrder 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()

Contents

 Go to top