TOTAL

PURPOSE   OPERATION   OPTIONS   COMMAND LINES   RELATED PROGRAMS


Author: Dan Mares, dmares @ maresware . com
Portions Copyright © 1998-2023 by Dan Mares
Phone: 678-427-3275 leave message
Last update: 05-07-2023

One liner: Totals number fields, or "counts" number of records for "sorted" key fields.

Sample Maresware Batches  an executable with data that demonstrates various Maresware software. Download and run the appropriate _12_xx batch for total demo.

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


top

PURPOSE


top

OPERATION

This program ONLY works on a file of fixed length sorted records.

The sort is on a “sort key” field. 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 approximately 20-25 more characters than the input record. This field holds a signed/formatted total. The number of characters added depends on the option(s) used. If you use the -c option for total count then the added record length is about 20. If you use options which actually add values in the -d -n fields, then a 25 character limit is added to account for "trillion" values for when the government uses the program to add up its dept.

With the -c option, the totaling process is disabled, and ONLY a count of the number of occurrences for each key field is instituted. The -c option does NOT need the -d -n values. It relies on the -p -l options.

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 the necessary 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), stars (*’s), justify the $$ sign either left or right, and pad with zeros or stars ****. Check the help screen for the options. Knowing that some option combination will conflict or are mutually exclusive. Test test test, practice practice practice.


top

COMMAND LINE

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
or
C:> total  input   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 -f xxx
C:> total  input   output  -r 100  -p 0  -L 5  -c
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 approximately 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. Because the masking is so complicated, it is suggested you make some test runs before actually implementing the options as some may conflict with each other, for instance you can't have padded 0's and stars *'s in the same -f xx option.

===================================================
Thu Aug 01 11:49:48 1996 TOTAL.EXE input dos.out -r 50 -p 14 -l 2 -d 37 -n 5 -fnnn -A Infile=input|Filesize=7650|Recl=50|Records wrote=29 Records processed = 153 No of records written= 29 Final record length = 75 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 this option may not be implemented in your version RECL xx 1236988.00+ xx 203.00+ xx 10.00-

top

OPTIONS

Please note that many of the fine tuned options may have been removed in later versions. So it is suggested if you are planning on useing some of the more fine tuned items (like -g -m -u and others), please run test runs to see what the output looks like.

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

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

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

-[Ll] + #:  # (ell). (Required) 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

-a:  disregard sort field and total entire file on the sort key field. -p   -l options.

-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.

-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.

-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 binary value entered here is a bit value for the following formatting options of the total field.
For those values which are mutually exclusive, IE: 1, & 2 $$ signs. if you place a -f 3 on the command line, the 2 is ignored, and the option is treated as -f 1.

-f + # where # is a format option( s ) added together 
1 = dollar sign ( $ ) justified to figures [+ $12345.00]              (1 and 2 mutually exclusive. 1 is primary) 
2 = dollar sign ( $ ) left justified to left of field [+$ 12345.00]   (1 and 2 mutually exclusive) 
 
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]          (32 and 64 mutually exclusive)
64 = place sign on left justified to figures [ -12345.00]   (32 and 64 mutually exclusive, 64 is primary)

128 = place sign AFTER figures. ( trailing sign )(may not be implemented in your copy) [ 12345.00-] 



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


RELATED PROGRAMS

FILBREAK

UNIQUE

top