############################################################################
# Copyright (C) 1982-2005 ESL Syndetic Limited #
# All Rights Reserved. #
# #
# NOTICE #
# PROPRIETARY AND CONFIDENTIAL #
# #
# This computer program is and contains trade secret and confidential and #
# proprietary information of ESL Syndetic Limited. All use, disclosure, #
# and/or reproduction not specifically authorized in writing by #
# ESL Syndetic Limited is prohibited. This program may also be protected #
# under the copyright and trade secrets laws of countries other than the #
# U.S.A. #
# #
# #
############################################################################
###################################################################################
#
# The ADD2Table, is a generic routine for added rows to table. For the
# routine to work, the Table Name must be unique. The Data to be input
# in the table, is passed in the Row_SV parmeter and must be formatted so
# each field is separated using the column delimiter of the target table.
# The Column_IV is use to define which column is used for sorting and
# whether Ascending (use a position number) or Descending (use a negative number).
# If Column_IV is set to zero or is outside the range of columns in the table
# the rows will not be sorted. The column to be sorted on must be defined as
# integer, float or string, otherwise it will not be sorted.
# The Match_SV defined the behaviour if a duplicate is found, it has 3 values:
# "BEFORE" the duplicate row is inserted before the existing matched row
# "AFETR" the duplicate row is inserted after the existing matched row
# "REPLACE" the duplicate row replace the row already in the table.
# If Match_SV has any other value, the duplicate row is discarded.
###################################################################################
subroutine ADD2Table(string: TableName_SV,
string: Row_SV,
integer:Column_IV,
string: Match_SV) is
string SortSpec_LSV
Delimiter_LSV
TableKey_LSV
SortKey_LSV
Row_LSV
Null_LSV
integer Row_LIV
Index_LIV
Bottom_LIV
SortKey_LIV
TableKey_LIV
DataState_LIV
ErrorLevel_LIV
Column_LIV
float SortKey_LFV
TableKey_LFV
boolean SortDescending_LBV
Duplicate_LBV
copy (bottom of TableName_SV) to Bottom_LIV
# No sorting required if first row to be added
if (Bottom_LIV = 0) then
add to TableName_SV insert row at end
copy (Bottom_LIV + 1) to Row_LIV
copy Row_SV to row Row_LIV of TableName_SV
else
# is there a sort order?
if (Column_IV = 0) then
# no sort - just add at the bottom
add to TableName_SV insert row at end
copy (Bottom_LIV + 1) to Row_LIV
copy Row_SV to row Row_LIV of TableName_SV
else
# Negative number means sort descending
if (Column_IV < 0) then
copy true to SortDescending_LBV
copy (0 - Column_IV) to Column_LIV # remove - sign
else
copy Column_IV to Column_LIV # just copy column number
end if
if (Column_LIV <= (right of TableName_SV)) then # (safety)
# get the sort key from the new record (for column n it's
# the value which comes before the n'th tab)...
copy (column delimiter of TableName_SV) to Delimiter_LSV
copy Row_SV Delimiter_LSV to Row_LSV
# (ensure a delimiter after the last value)
for Index_LIV = 1 to Column_LIV loop
extract from Row_LSV
take to Delimiter_LSV SortKey_LSV
skip by Delimiter_LSV
take to last Row_LSV
end loop
# find where to insert it...(Dependant on Type)
switch (type of column Column_LIV of TableName_SV) is
case char "integer" is
copy SortKey_LSV to SortKey_LIV
for Row_LIV = 1 to Bottom_LIV loop
copy (integer cell Column_LIV, Row_LIV of TableName_SV) to TableKey_LIV
if (SortKey_LIV = TableKey_LIV) then
copy true to Duplicate_LBV
leave loop
end if
if (SortDescending_LBV) then
if (TableKey_LIV < SortKey_LIV) then
leave loop
end if
else
if (TableKey_LIV > SortKey_LIV) then
leave loop
end if
end if
end loop
case char "float" is
copy SortKey_LSV to SortKey_LFV
for Row_LIV = 1 to Bottom_LIV loop
copy (float cell Column_LIV, Row_LIV of TableName_SV) to TableKey_LFV
if (SortKey_LFV = TableKey_LFV) then
copy true to Duplicate_LBV
leave loop
end if
if (SortDescending_LBV) then
if (TableKey_LFV < SortKey_LFV) then
leave loop
end if
else
if (TableKey_LFV > SortKey_LFV) then
leave loop
end if
end if
end loop
case char "string" is
for Row_LIV = 1 to Bottom_LIV loop
copy (string cell Column_LIV, Row_LIV of TableName_SV) to TableKey_LSV
if (SortKey_LSV = TableKey_LSV) then
copy true to Duplicate_LBV
leave loop
end if
if (SortDescending_LBV) then
if (TableKey_LSV < SortKey_LSV) then
leave loop
end if
else
if (TableKey_LSV > SortKey_LSV) then
leave loop
end if
end if
end loop
default is
# No other column types that can be sorted
# sort just insert at end!
copy (Bottom_LIV + 1) to Row_LIV
end switch
else # the column number is not valid - add at the end
copy (Bottom_LIV + 1) to Row_LIV
end if
if (not Duplicate_LBV) then
if (Row_LIV > Bottom_LIV) then
add to TableName_SV insert row at end
else
add to TableName_SV insert row before row Row_LIV
end if
copy Row_SV to row Row_LIV of TableName_SV
else
switch Match_SV is
case char "BEFORE" is
add to TableName_SV insert row before row Row_LIV
copy Row_SV to row Row_LIV of TableName_SV
case char "AFTER" is
add to TableName_SV insert row after row Row_LIV
copy Row_SV to row (Row_LIV + 1) of TableName_SV
case char "REPLACE" is
copy Row_SV to row Row_LIV of TableName_SV
default is
end switch
end if
end if
end if
###################################################################################