Author: Dan Mares, dmares @ maresware . com
Portions Copyright © 1998-2016 by Dan Mares and Mares and Company, LLC
Phone: 678-427-3275

This is a command line program.
MUST be run within a command window as administrator.





This program ONLY works on a file of sorted records.

The sort is on a “sort key”. It takes these sorted records and totals up amounts in specified fields from records with similar sort keys.

It will total a number containing up to nine(9) digits plus associated punctuation such as ($ , .).

In other words if the field that you wish to total has commas as delimiters for thousands it will take those into account. If it has periods to delineate cents, all the records must have the period in the same (fixed location) place, and the output will be a number reflecting the total cents not dollars.

The total field is defaulted to 2 decimal places.

The program will normally be able to handle both left and right justified numbers.

The final output records contain 20 more characters than the input record. This 20 characters holds a signed/formatted total. Use the -m option to change the width of this field as necessary.

With the -c option, the totaling process is disabled, and ONLY a count of the number of occurrences for each key field is instituted.

If you use the -g # option, then the program automatically installs the -c. The -g will tell the program to do the -c (count) option and ONLY provide those records which contain counts (g)reater than the number supplied with the -g option. The final output record now contains a number reflecting the number of occurrences for each key.

When the -aA option is used, the program also includes in the ACCTING file an average of all the items totalled.

The program builds an output record which consists of the original record plus 20 digits containing the total of the items found for each unique sorted key. It takes succeeding keys, if the keys are the same it adds the total field. When it finds no more keys, it builds the output record. So you will have one output record for each unique key you have in the input file. The output record will have appended to it the totals of all the specified items in the field that was to be added.

The program with a -f (format) option can format the totalled field with dollar signs ($’s), start (*’s), justify (left or right), and pad with zeros. For information on how the -f option works contact Dan Mares.

The program also has the capability of using a parameter file. Contact Dan Mares for instructions.



C:>total input output -[options]

Item 1: total
Item 2: Input file name.
Item 3: Output file name.
Item 4: Options as necessary

C:> total  -i   input  -o   output  -r 100  -p 0  -L 5  -d 50  -n 7
C:> total  input   output  -r 100  -p 0  -L 5  -d 50  -n 7
notice in the 2nd instance, no -i or -o is required. This is a special positional specific command line.

This will give total occurrences of each unique key in position 0 which means the input record is 100 characters long, the sort key is the first character of the record, and is 5 characters long the field that we wish to total is in displacement 50 (51st character) and the number of characters in this field will be 7.

The output file will contain 120 character records.

Assuming the following file is sorted on the first character the command line would be:

C:>total  -i   input   -o   output  -r 12  -p 0  -L 1  -d 1  -n 10

Here are some sample formatting options used and the total field. The 1st example shows the output of the entire accounting file including the command line used, and a sample of the output records. The total field is in bold. The rest of the record is trash.

After the 1st example, only the -f (format option used is shown with 2 or three records.) Notice some inconsistancies with the placement of the negative sign when totals are negative. If this gives you real heart ache call for a patch.

Notice the -m adjusted the field size to max of 25 characters. In those where I remembered to do so, I placed an xx just prior to the output field.

The first one is a default of no formatiing at all.

There is a -f option which causes the output total field to be specially formatted. Examples are here, and see the -f option below.

Thu Aug 01 11:49:48 1996
TOTAL.EXE input dos.out -r 50 -p 14 -l 2 -d 37 -n 5 -m 25 -A

Infile=input|Filesize=7650|Recl=50|Records wrote=29

Records processed = 153
No of records written= 29
Final record length = 65
Highest number found = 99999
Elapsed time: 0 hrs. 0 mins. 0 secs

RECL=pos37000 X5 xx+ 1236988.00 203 0900203 + 203.00 ======================= -f 1 RECL xx+ $1236988.00 0203 xx+ $203.00 ======================= -f 2 RECL xx+$ 1236988.00 xx+$ 203.00 ======================= -f 4 RECL xx+00001236988.00 xx+00000000203.00 ======================= -f 5 REC xx+000$1236988.00 xx+0000000$203.00 ======================= -f 6 RECL xx+$0001236988.00 xx-$0000000010.00 ======================= -f 8 RECL xx+ 1,236,988.00 xx+ 203.00 xx- 10.00 ======================= -f 9 RECL xx+ $1,236,988.00 xx+ $203.00 xx- $10.00 ======================= -f 10 RECL xx+$ 1,236,988.00 xx-$ 10.00 ======================= -f 12 RECL xx+001,236,988.00 xx+00000000203.00 xx-00000000010.00 ======================= -f 13 RECL xx+0$1,236,988.00 xx+0000000$321.00 xx-00000000$10.00 ======================= -f 14 RECL xx+$01,236,988.00 xx+$0000000203.00 xx-$0000000010.00 ======================= -f 16 RECL xx+****1236988.00 xx+********203.00 xx-*********10.00 ======================= -f 17 RECL xx+***$1236988.00 xx+*******$203.00 xx-********$10.00 ======================= -f 18 RECL xx+$***1236988.00 xx+$*******203.00 xx-$********10.00 ======================= -f 24 RECL xx+**1,236,988.00 xx+********203.00 xx-*********10.00 ======================= -f 25 RECL xx+*$1,236,988.00 xx+*******$203.00 xx-********$10.00 ======================= -f 26 RECL xx+$*1,236,988.00 xx+$*******203.00 xx-$********10.00 ======================= -f 32 RECL xx +1236988.00 xx +203.00 xx -10.00 ======================= -f 33 RECL xx +$1236988.00 xx +$203.00 xx -$10.00 ======================= -f 34 RECL xx$ +1236988.00 xx$ +203.00 xx$ -10.00 ======================= -f 36 RECL xx000001236988.00 xx000000000203.00 xx000000000010.00 NOTE: notice the sign is lost in this format ======================= -f 40 RECL xx +1,236,988.00 xx +203.00 xx -10.00 ======================= -f 41 RECL xx +$1,236,988.00 xx +$203.00 xx -$10.00 ======================= -f 64 RECL xx+ 1236988.00 xx+ 203.00 xx- 10.00 ====================== -f 65 RECL xx+ $1236988.00 xx+ $203.00 xx- $10.00 ====================== -f 66 RECL xx+$ 1236988.00 xx+$ 203.00 xx-$ 10.00 ====================== -f 72 RECL xx+ 1,236,988.00 xx+ 203.00 xx- 10.00 ====================== -f 128 RECL xx 1236988.00+ xx 203.00+ xx 10.00- ====================== -f 1024 RECL xx 1236988 xx 203.25 xx 10.10



-i inputfilename:  Required: Name of the input file.

-o outputfilename:  Required: Name of the output file.
>I>If the input and output files are the 1st and 2nd item on the command line, then the -i and -o may be omitted.

-a:  disregard sort field and total entire file

-A:  create/append to ACCT-ING file includes average of items if -a option used. If environment variable ACCT=ON is set, this option is automatically installed.

/A:  turns off (-A) set by automatic environment variable ACCT=ON.

-r + #:  # is record length of input record.

-[Pp] + #:  # is position (displacement) to the sorted. field. 1st character in record is position 0. MUST BE MATCHED with -l option.

-[Ll] + #:# (ell). is length of sorted key. MUST BE MATCHED with -p option

If upper case -P, or -L option is used, then the sort sequence of the -PL field is processed as case sensitive. Meaning ("This", is not the same as "this") The default for processing the sort sequence of the -pl option is case insensitive, meaning ("This" is the same as "this")
A -T option will also cause case sensitivity to be turned on

-d + #:  # is displacement to the field containing integers to total. MUST BE MATCHED with -n option

-n + #:  # is number of characters (width) in the field to total. MUST BE MATCHED with -n option.

-c:  Will substitute a COUNT of the number of times the sort key (-pl options) is found in subsequent records for the total found in the specified field. This option disables the field totaling option.

-m + #:  # is maximum size of the total field to be added to the output record. The default is that the total field of 20 characters will be added to the output record. This is to allow for most all possible formatting options. If you are only totalling a small value, then this can be decreased to 10 or 15. But be careful, if the total calculated is greater than the field width allowed, errors will occur.

-g + #:  # is number indicating that you only want records with -c (counts) greater than the #. If the -g is used, the -c is automatically installed.

-u  this option acts just like unique. It eliminates all subsequent occurances of the records with each primary key. It does exactly the same operation as the -c option except it doesn’t add the 25 digit counter at the end of the record.

-f + #: the value entered here is a bit value for the following formatting options of the total field.

-f + # where # is a format option( s ) added together
     1 =  dollar sign ( $ ) justified to figures                   [+  $12345.00]
     2 =  dollar sign ( $ ) left justified to left of field        [+$  12345.00]
     4 =  left pad with ZEROS, will not work with a 1 or 2         [+00012345.00]
     8 =  insert COMMAS as thousands seperators                    [+  12,345.00]
    16 =  left pad with STARS ( * ). *'s go between sign and value [+***12345.00]
    32 =  place sign at left side of field                         [-   12345.00]
    64 =  place sign on left justified to figures                  [   -12345.00]
   128 =  place sign AFTER figures. ( trailing sign )              [   12345.00-]
   256 =  DO NOT use any sign                                      [    12345.00]
  1024 =  If the total value has .00 decimal, don't print the .00 (cents). and 
          Make it an integer only if there are no "cents".         [       12345]

   add all the applicable format codes and enter it after the -f
   i.e. to get left justified $ and * use 18