# Sometimes the Simple Things… Dictionary Ideas

Sometimes its the simple things in life. I have a favorite Dictionary record I’d like to share with all of you. It is the constant “1”. What can you do with a Dictionary Record of “1”? First, create a dictionary record with the constant “1” and call it “ITEMS” (see below).

Then if you want to know how many employees you have in each department (Assuming you have an EMPLOYEE file with a DEPT attribute)

LIST EMPLOYEE BREAK-ON DEPT BY DEPT TOTAL ITEMS DET-SUPP ID-SUPP (Your flavor of mutlivalue may vary on this)

You will get a list of departments with the number of employees in each department.

So anything you need to know how many of a certain type of item is in your file, you can modify the above query to provide that information.

Pick Flavor Dict Item (Thanks to Clif Oliver)

ITEMS

0001 S
0002 0
0003 ITEMS
0004
0005
0006
0007
0008 F;C1
0009 R
0010 8

Information Flavor Dict Item

ITEMS

0001 I
0002 1
0003
0004 ITEMS
0005 8R
0006 S

# BASIC Code to calculate a programs elapsed wallclock time

Calculating the elapsed wall clock time of a program is helpful to determine how much time it actually takes for a program to complete. The easy method is to take the time the program ends and then subtract the time the program starts. In all multivalue BASIC languages you can use the TIME() function to return the number of seconds from midnight. The problem with this solution is if you have to calculate the elapsed time through midnight.

If you start at 11:59pm and complete at 12:01am the internal times would be 86340 for 11:59pm and 60 for 12:01am. So using the above calculation of end time minus start time which would be 60 – 86340 = -86280. This elapsed time does not make any sense at all.

To correct for the midnight crossing we need to use the date the program started and the date the program ended. One thing we need to know is that there are 86400 seconds in a day. With that in mind the new calculation would be ((Date End – Date Start) * 86400) + (Time End – Time Start). This formula will provide a more accurate method of calculating elapsed time if there is a midnight crossing.

The internal dates are calculated using the DATE() function that calculates the number of days from the Epoch. Multivalue databases use the Epoch 12-31-1967. The Epoch is where the internal date is zero.

Using the above example, lets add that the program started on 01-01-2017 and it was completed on 01-02-2017.The internal date for 01-01-2017 is 17899 and the internal date for 01-02-2017 is 17900, the calculation now looks like the following.

((17900 – 17899) * 86400) + (60 – 86340) which gives (86400 – 86280) that equals 120 seconds or 2 minutes which is the correct elapsed time. Some, but not all multivalue database system provide for a date and time @-variable that define the program start date and time. You may see that there is a tiny glitch in the logic above in that if I get the time that program start and the date changes before the value of the date is read the calculation will be off. The converse of this glitch would also be true if I get the date and the time crosses midnight. The @-variables help prevent this glitch.

So, in my programs when I wish to calculate the elapsed wall clock time of my program in a midnight or date crossing condition, I create an equate that provides the elapsed time.

EQUATE ELAPSED LITERALLY “((DATE()-@DATE)*86400)+(TIME()-@TIME)”

At the end of my program I use the following.

PRINT “Elapsed: “:OCONV(ELAPSED,”MTS”)

This only provides the elapsed wall clock time of the BASIC program. You may want to also determine the amount of CPU time spend on executing the program. The wall clock time of a program can be influenced by the load on the system.