You are on page 1of 3

ACL Technical Support

Standard Script Document

COMMENT
** DISCLAIMER NOTICE:
** ACL SERVICES LTD. ("ACL") AND ITS DISTRIBUTORS PROVIDE THE SCRIPT "AS IS" AND
** FREE OF CHARGE. ACL AND ITS DISTRIBUTORS: (A) DO NOT PROVIDE SUPPORT FOR THESE
** SCRIPTS; (B) MAKE NO WARRANTIES OR REPRESENTATIONS, EXPRESSED OR IMPLIED, WITH
** RESPECT TO THE SCRIPT, INCLUDING ITS FITNESS FOR A PARTICULAR PURPOSE,
** MERCHANTABILITY, DURABILITY, QUALITY OR ITS NON-INFRINGEMENT; (C) DO NOT
WARRANT ** THAT THE SCRIPT IS FREE FROM ERRORS; AND (D) WILL NOT BE LIABLE FOR ANY
DAMAGES ** (INCLUDING, BUT NOT LIMITED TO INDIRECT DAMAGES SUCH AS LOST PROFITS
AND LOST
** DATA) ARISING OUT OF THE USE OF, OR THE INABILITY TO USE THE SCRIPT. YOU AGREE
TO ** ASSUME ALL RISK OF LOSS OR DAMAGE ARISING FROM THE USE OF THE SCRIPT.
END

COMMENT
*******************************************************************************
** Script Name: Cancel_matching_amounts (positive and negative amounts)
** Description: This script will create a new table without any duplicate
** amounts and one table with the amounts that were cancelled
** out.
**
** Requirements: A table with an amount field and a key field.
**
** Output: Two tables (cancelled and leftover amounts).
**
** Written By: Heiko Wieler, ACL Services On: October 9, 2003
** Last Edit By: Heiko Wieler, ACL Services On: February 11,2004
** Don Mak, ACL Services On: August 30, 2004
*******************************************************************************

SET SAFETY OFF

COMMENT
***** Clean up all variables.

DELETE ALL OK
CLOSE

COMMENT
***** Asks for the input and output table names.

DIALOG (DIALOG TITLE "ACL - Cancel Matching Amounts" WIDTH 587 HEIGHT 192 )
(BUTTONSET TITLE "&OK;&Cancel" AT 384 144 DEFAULT 1 HORZ ) (ITEM TITLE "f" TO
"v_input_table" AT 432 24 ) (TEXT TITLE "Please select the table to check for
canceling amounts:" AT 24 28 ) (TEXT TITLE "Please enter the output table name for
the leftover amounts:" AT 24 64 ) (EDIT TO "v_output_table" AT 432 60 ) (TEXT TITLE
"Please enter the output table name for the cancelled amounts:" AT 24 100 ) (EDIT TO
"v_output_table2" AT 432 96 )

COMMENT
***** Opens the input table.

OPEN %v_input_table%

COMMENT
***** Asks for the amount and key field.

Page 1 of 3
ACL Technical Support
Standard Script Document

DIALOG (DIALOG TITLE "ACL - Cancel Matching Amounts" WIDTH 410 HEIGHT 164 )
(BUTTONSET TITLE "&OK;&Cancel" AT 216 108 DEFAULT 1 HORZ ) (ITEM TITLE "N" TO
"v_amount_field" AT 252 24 ) (TEXT TITLE "Please select your amount field to check:"
AT 24 28 WIDTH 216 ) (TEXT TITLE "Please select your key field:" AT 24 64 ) (ITEM
TITLE "C" TO "v_key" AT 252 60 )

COMMENT
***** Deletes any fields created if the script has been run on this table
***** already.

DELETE absolute_amount OK
DELETE sign OK

COMMENT
***** Creates a computed field containing the negative/positive identifier.

DEFINE FIELD sign COMPUTED

"N" IF %v_amount_field% < 0


"P"

COMMENT
***** Creates a computed field containing the absolute value of the amount
***** field.

DEFINE FIELD absolute_amount COMPUTED ABS(%v_amount_field%)

COMMENT
***** Sorts on the sign in descending and then in ascending order to new tables.

SORT ON %v_key% absolute_amount D sign D TO "Sorted_Table_1"


SORT ON %v_key% absolute_amount D sign TO "Sorted_Table_2"

COMMENT
***** Opens Sorted_Table_1 and creates a record number field to join on.

OPEN Sorted_Table_1
DELETE record_number OK
DEFINE FIELD record_number COMPUTED STRING(RECNO(), 8)

COMMENT
***** Opens Sorted_Table_2 and creates a record number field to join on.

OPEN Sorted_Table_2
DELETE record_number OK
DEFINE FIELD record_number COMPUTED STRING(RECNO(), 8)

COMMENT
***** Open the primary and secondary tables.

OPEN Sorted_Table_1
OPEN SECONDARY Sorted_Table_2

COMMENT
***** Join Sorted_Table_1 and Sorted_Table_2 on record_number.

Page 2 of 3
ACL Technical Support
Standard Script Document

JOIN PKEY record_number FIELDS ALL SKEY record_number WITH ALL TO "Results" OPEN
PRESORT SECSORT

COMMENT
***** Obtains leftover amounts.

EXTRACT FIELDS ALL IF absolute_amount = absolute_amount2 AND sign2 = sign TO


"%v_output_table%"

COMMENT
***** Obtains cancelled amounts.

EXTRACT FIELDS ALL IF absolute_amount = absolute_amount2 AND sign2 <> sign TO


"%v_output_table2%" OPEN

COMMENT
***** Clean up temporary tables.

CLOSE SEC
DELETE FORMAT Sorted_Table_1 OK
DELETE Sorted_Table_1.FIL OK
DELETE FORMAT Sorted_Table_2 OK
DELETE Sorted_Table_2.FIL OK
DELETE FORMAT Results OK
DELETE Results.FIL OK
SET SAFETY ON

Page 3 of 3

You might also like