Feature - Project & Calculate Distance Between Two Zip Codes

Feature - Project & Calculate Distance Between Two Zip Codes

Release Date: 8/7/25
Version: 8.5 and Above

The utility program SYDSTCAL.CBL is used to calculate the distance between two zip codes. To calculate the distance between two ZIP codes using latitude and longitude (from their geographic centers), the simplest trigonometric method is the Haversine formula. It gives you the great-circle distance between two points on the Earth's surface, accounting for the Earth's curvature. This calculation uses intrinsic functions to determine the distance. This requires the following compiler directive located in the first line of the program. 

      $SET ADDRSV "FUNCTION"

Note: Removal of this line or changes to this line will cause a compilation error.

The program uses the following linkage:

       01 SYDSTCAL-VALUES.
          03 SYDSTCAL-MODE                PIC X(1).
          03 SYDSTCAL-MILES-OR-KILOMETERS PIC X(1).
          03 SYDSTCAL-PRIM-LOC-ZIP-CODE   PIC X(5).
          03 SYDSTCAL-LOCATIONS-TABLE.
             05 SYDSTCAL-LOCATIONS OCCURS 100 TIMES.
                07 SYDSTCAL-TABLE-NAME    PIC X(8).
                07 SYDSTCAL-REF-VALUE     PIC X(30).
                07 SYDSTCAL-ZIP-CODE      PIC X(5).
                07 SYDSTCAL-DISTANCE      PIC S9(5)V9999.
          03 SYDSTCAL-OPEN-STATUS         PIC X(1).

SYDSTCAL-MODE - 1=Open File, 2=Close Files, 3=Calculate
SYDSTCAL-MILES-OR-KILOMETERS - K=Kilometers, M=Miles (default is miles)
SYDSTCAL-PRIM-LOC-ZIP-CODE - Primary location for the distance comparison.
SYDSTCAL-LOCATIONS (supports up to 100 entries)
SYDSTCAL-TABLE-NAME - Table name where the comparison zip code originated such as IMLOCFIL
SYDSTCAL-REF-VALUE - Reference value of the primary location such as the LOCATION-CODE from IMLOCFIL
SYDSTCAL-ZIP-CODE - Zip code used to compute the distance
SYDSTCAL-DISTANCE - Calculated distance returned by the program
SYDSTCAL-OPEN-STATUS - Indicates if the opening procedure in SYDSTCAL was successful

Normal Use of this Program
  1. Call SYDSTCAL in the opening procedure of the program with the mode set to "1." This will perform the opening procedure in SYDSTCAL and set local working storage variable in the program indicating if the opening procedure was successful. The variable SYDSTCAL-OPEN-STATUS is also set and returned back to the calling program. If this flag is set to "N," the OPENING-PROCEDURE-STATUS should be set to UNSUCCESSFUL.
  2. Call SYDSTCAL with the mode set to "3" during normal processing to calculate and return the distance for all of the provided zip codes.
  3. Call SYDSTCAL in the closing procedure of the program with the mode set to "2." This will perform the closing procedure in SYDSTCAL and set the local working storage variable in the program indicating that the closing procedure was performed. After the program returns, it should be cancelled in the closing procedure.
SYZIPCDS Table
This program uses the latitude and longitude provided in the table SYZIPCDS to calculate the distance between two zip codes.  The maintenance of this table can be found in Elliott -> System Utilities -> Zip Code File.  The latest SYZIPCDS.BTR table is installed in the <ElliottRoot> directory, while the versions in the DATA* folders may not be up to date. Therefore, we provide a Synchronize utility to synchronize the SYZIPCDS.BTR table in <ElliottRoot> with the corresponding tables in the <ElliottRoot>\DATA* folders. If the multi-company feature is used, you will need to perform this synchronization on a company-by-company basis. Since the SYZIPCDS.BTR file in the <ElliottRoot>\DATA* folders may be modified by you, it is better to use the Synchronize utility rather than performing a direct copy from the <ElliottRoot> folder.

What If A Provided Zip Code Does Not Exist in our Zip Code Table?

Our distance calculation is based on the 5-digit zip code. Various Elliott tables support a 10-digit zip cope but this program only uses the first 5 digits.  It is possible a new 5-digit zip code does not exist in our database.  In that case, the program will use first 4 digits of the zip code to start and find the closest zip code.  For example, if zip code 91788 does not exist in the zip code table, then the application will read all of the zip codes starting with 9178 to find zip codes between 91780 and 91789.  The closest lower zip codes will be used. That is to say, if 91780, 91782, 91784, 91785, 91789 exist, the application will use 91789 for the distance calculation because it is the closest (off by 1, vs. 91785 which is off by 3).  On the other hand, if both 91787 and 91789 are found, then we will use 91787 because it is off by 1, and it is the lower zip code instead of 91789 which is the higher zip code.  If no zip codes are found within the 4-digits zip code, then the application will try with the first 3 digits of the provided zip code (e.g., 917 in this example). If there are no zip codes found for 917* in the zip codes database, then it is an error condition.  This applies to either the primary (SYDSTCAL-PRIM-LOC-ZIP-CODE) or the list of potential location zip codes (SYDSTCAL-ZIP-CODE). In that case, the application will return a distance of 99999.9999 back, which is the maximum value.  Also, if the zip code is less than 5 digits it is an error condition, and the application will return the value 99999.9999 as well.  This makes sure this entry will not be used. 

Programs Added: SYDSTCAL.CBL, SYDSTCAL.WS
CLS

    • Related Articles

    • Feature - Sales Order Import Warehouse Location Based on Distance from Ship-To Location

      Release Date: 8/7/25 Version: 8.5 and Above This feature is applicable for users with multiple warehouse locations who are using EDI sales order import. The trading partner chooses not to specify the warehouse location for the fulfillment of the ...
    • Btrieve Error Codes 001 - 199

      MicroKernel (Btrieve) Database Engine Status Codes This section describes status codes that the MicroKernel returns. All status codes are provided in 3-digit formats since the search on this website cannot search 1 or 2-digit words correctly. That is ...
    • Btrieve Error Codes 3100 - 3199

      Network Services Layer Status Codes The following status codes originate from the Pervasive Network Services Layer (PNSL). 3103: Server name not found by Pervasive Network Services Layer The search for a target server name was unable to resolve an ...
    • Avalara - Item Tax Codes

      Release Date: 4/28/23 Version: 8.6 and Above Tax codes (_GOODSERVICES attribute) are used to determine what tax category an item belongs to for taxing purposes. Tax codes can be assigned at the product category, user-defined code, and item levels. ...
    • Avalara Source Code Integration - AV API Call

      Release Date: 11/16/21 Revised: 05/23/22 Version: 8.6 and Above This article is intended for Elliott Business Software developers. This API call will allow the programmer to pass a value to indicate which Avalara function is to be performed. The ...